Class: Flag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/flag.rb

Constant Summary collapse

DEFAULT_VALID_APPLIES_TO =
%w[Post Topic]
MAX_SYSTEM_FLAG_ID =
1000
MAX_NAME_LENGTH =
200
MAX_DESCRIPTION_LENGTH =
1000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_reset_flag_callbackObject

Returns the value of attribute skip_reset_flag_callback.



19
20
21
# File 'app/models/flag.rb', line 19

def skip_reset_flag_callback
  @skip_reset_flag_callback
end

Class Method Details

.reset_flag_settings!Object



34
35
36
37
38
# File 'app/models/flag.rb', line 34

def self.reset_flag_settings!
  # Flags are cached in Redis for better performance. After the update,
  # we need to reload them in all processes.
  PostActionType.reload_types
end

.used_flag_idsObject



40
41
42
43
# File 'app/models/flag.rb', line 40

def self.used_flag_ids
  PostAction.distinct(:post_action_type_id).pluck(:post_action_type_id) |
    ReviewableScore.distinct(:reviewable_score_type).pluck(:reviewable_score_type)
end

.valid_applies_to_typesObject



30
31
32
# File 'app/models/flag.rb', line 30

def self.valid_applies_to_types
  Set.new(DEFAULT_VALID_APPLIES_TO | DiscoursePluginRegistry.flag_applies_to_types)
end

Instance Method Details

#applies_to?(type) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/flag.rb', line 49

def applies_to?(type)
  self.applies_to.include?(type)
end

#system?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/flag.rb', line 45

def system?
  self.id.present? && self.id < MAX_SYSTEM_FLAG_ID
end

#used?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'app/models/flag.rb', line 25

def used?
  PostAction.exists?(post_action_type_id: self.id) ||
    ReviewableScore.exists?(reviewable_score_type: self.id)
end