Class: Flag
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Flag
- Includes:
- CommunityRelated, Routing, Timestamped
- Defined in:
- /var/apps/qpixel/app/models/flag.rb
Overview
Represents a flag. Flags are attached to both a user and a post, and have a single status.
Class Method Summary collapse
-
.accessible_to(user, post) ⇒ ActiveRecord::Relation<Flag>
Gets flags appropriately scoped for a given user & post.
Instance Method Summary collapse
-
#confidential? ⇒ Boolean
Checks if the flag is confidential as per its type.
- #maximum_reason_length ⇒ Object
-
#resolve(status:, message:, handled_by:, handled_at: nil) ⇒ Boolean
Resolve a flag and run associated ability and notification actions.
Methods included from Routing
Methods inherited from ApplicationRecord
#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules
Class Method Details
.accessible_to(user, post) ⇒ ActiveRecord::Relation<Flag>
Gets flags appropriately scoped for a given user & post
31 32 33 34 35 36 37 38 39 |
# File '/var/apps/qpixel/app/models/flag.rb', line 31 def self.accessible_to(user, post) if user&.at_least_moderator? post.flags elsif user&.can_handle_flags? post.flags.not_confidential else post.flags.none end end |
Instance Method Details
#confidential? ⇒ Boolean
Checks if the flag is confidential as per its type
43 44 45 |
# File '/var/apps/qpixel/app/models/flag.rb', line 43 def confidential? post_flag_type&.confidential || false end |
#maximum_reason_length ⇒ Object
47 48 49 50 51 52 |
# File '/var/apps/qpixel/app/models/flag.rb', line 47 def maximum_reason_length max_len = SiteSetting['MaxFlagReasonLength'] || 1000 if reason.length > [max_len, 1000].min errors.add(:reason, "can't be more than #{max_len} characters") end end |
#resolve(status:, message:, handled_by:, handled_at: nil) ⇒ Boolean
Resolve a flag and run associated ability and notification actions.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File '/var/apps/qpixel/app/models/flag.rb', line 61 def resolve(status:, message:, handled_by:, handled_at: nil) resolve_status = false transaction do resolve_status = update(status: status, message: , handled_by: handled_by, handled_at: handled_at || DateTime.now) resolve_status &&= AbilityQueue.add(user, "Flag Handled ##{id}") unless resolve_status raise ActiveRecord::Rollback end unless .blank? # TODO: create_notification actually behaves like a bang method user.create_notification('A moderator has written a response to your flag. Check your flag history page.', flag_history_url(user, { host: community.host })) end end resolve_status end |