class ContentHighlight

Public Class Methods

can_add_highlights?(highlightable, user) click to toggle source

Set Add Permissions here

# 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) click to toggle source

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

# 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={}) click to toggle source

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

# 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

Public Instance Methods

can_remove_highlight?(user) click to toggle source

Set remove permissions here

# 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