Class: Complaint
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Complaint
- Includes:
- Timestamped
- Defined in:
- /var/apps/qpixel/app/models/complaint.rb
Instance Method Summary collapse
-
#can_add_more_comments?(user) ⇒ Boolean
Can a specified user currently add more comments to this complaint?.
-
#update_status(new_status, attribute_to = nil) ⇒ Object
Update the complaint’s status, create a comment to record the change, and send emails to the right people.
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
Instance Method Details
#can_add_more_comments?(user) ⇒ Boolean
Can a specified user currently add more comments to this complaint?
37 38 39 40 41 42 43 44 |
# File '/var/apps/qpixel/app/models/complaint.rb', line 37 def can_add_more_comments?(user) if user&.staff? || comments.external.empty? true else last_user_id = comments.external.most_recent&.user_id last_user_id != user&.id && status != 'closed' end end |
#update_status(new_status, attribute_to = nil) ⇒ Object
Update the complaint’s status, create a comment to record the change, and send emails to the right people.
25 26 27 28 29 30 31 |
# File '/var/apps/qpixel/app/models/complaint.rb', line 25 def update_status(new_status, attribute_to = nil) dt = DateTime.now update(status: new_status, status_updated_at: dt) attribution = attribute_to.nil? ? 'automatically' : "by #{attribute_to}" comments.create(content: "Status updated to #{new_status} at #{dt.iso8601} #{attribution}.", internal: true, user: ApplicationController.helpers.system_user) end |