Class: Complaint

Inherits:
ApplicationRecord show all
Includes:
Timestamped
Defined in:
/var/apps/qpixel/app/models/complaint.rb

Instance Method Summary collapse

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?

Parameters:

  • user (User, nil)

    The user to check.

Returns:

  • (Boolean)

    check result



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.

Parameters:

  • new_status (String)

    The new status to set, from safety_center.yml.

  • attribute_to (String) (defaults to: nil)

    Who should the status change be attributed to? Username only.



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