Class: ContentHighlight

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_add_highlights?(highlightable, user) ⇒ Boolean

Set Add Permissions here

Returns:

  • (Boolean)


18
19
20
# File 'lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb', line 18

def self.can_add_highlights?(highlightable, user)
  return true # e.g. highlightable.can_highlight?(user)
end

.enrich_highlights(user) ⇒ Object

This method is used to show details on the poptips with permissions to remove highlights



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb', line 29

def self.enrich_highlights(user)
  ContentHighlight.joins(:user)
      .select("content_highlights.id as identifier,
              CONCAT('Highlight by ', users.id) as description,
              ARRAY[CASE user_id WHEN #{user.id} THEN 'me' ELSE 'others' END] as life_time_class_ends,
              CASE user_id WHEN #{user.id} THEN true ELSE false END as can_cancel,
              content,
              selection_backward as backward,
              startnode_offset as start_offset,
              endnode_offset as end_offset,
              container_node_identifier as common_ancestor_identifier,
              container_node_type as common_ancestor_node_type")
end

.highlights_to_show(highlightable, user, options = {}) ⇒ Object

This method shall be used to choose the highlights the user can see



12
13
14
15
# File 'lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb', line 12

def self.highlights_to_show(highlightable, user, options={})
  # request = options[:request]
  highlightable.content_highlights
end

Instance Method Details

#can_remove_highlight?(user) ⇒ Boolean

Set remove permissions here

Returns:

  • (Boolean)


23
24
25
# File 'lib/generators/acts_as_content_highlightable/templates/active_record_content_highlight_model.rb', line 23

def can_remove_highlight?(user)
  return (self.user == user)
end