-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor update owner audit activity to store metadata, and remove ca…
…llbacks and dependency on User.current
- Loading branch information
Showing
44 changed files
with
536 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class ChangeCaseOwnerForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attribute :owner_id | ||
attribute :owner_rationale | ||
|
||
validates_presence_of :owner_id | ||
validate :new_owner_must_be_active_user_or_team, if: -> { owner_id.present? } | ||
|
||
def owner | ||
user || team | ||
end | ||
|
||
private | ||
|
||
def new_owner_must_be_active_user_or_team | ||
errors.add(:owner_id, :not_found) unless owner | ||
end | ||
|
||
def user | ||
@user ||= User.active.find_by(id: owner_id) | ||
end | ||
|
||
def team | ||
@team ||= Team.find_by(id: owner_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 15 additions & 16 deletions
31
psd-web/app/models/audit_activity/investigation/automatically_update_owner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
class AuditActivity::Investigation::AutomaticallyUpdateOwner < AuditActivity::Investigation::Base | ||
def self.from(investigation) | ||
title = investigation.owner.id.to_s | ||
super(investigation, title) | ||
def self.from(*) | ||
raise "Deprecated - use DeleteUser.call instead" | ||
end | ||
|
||
def owner_id | ||
# We store owner_id in title field, this is getting it back | ||
# Using alias for accessing parent method causes errors elsewhere :( | ||
AuditActivity::Investigation::Base.instance_method(:title).bind(self).call | ||
def self.build_metadata(owner) | ||
{ | ||
owner_id: owner.id | ||
} | ||
end | ||
|
||
# We store owner_id in title field, this is computing title based on that | ||
def title | ||
def title(user) | ||
type = investigation.case_type.capitalize | ||
new_owner = (User.find_by(id: owner_id) || Team.find_by(id: owner_id))&.decorate&.display_name | ||
new_owner = owner.decorate.display_name(viewer: user) | ||
"Case owner automatically changed on #{type} to #{new_owner}" | ||
end | ||
|
||
def subtitle | ||
def subtitle(_viewer) | ||
"Case owner automatically changed, #{pretty_date_stamp}" | ||
end | ||
|
||
def entities_to_notify | ||
[] | ||
end | ||
private | ||
|
||
def email_subject_text; end | ||
def owner | ||
User.find_by(id: metadata["owner_id"]) || Team.find_by(id: metadata["owner_id"]) | ||
end | ||
|
||
def email_update_text(viewer = nil); end | ||
# Do not send investigation_updated mail. This is handled by the DeleteUser service | ||
def notify_relevant_users; end | ||
end |
4 changes: 2 additions & 2 deletions
4
psd-web/app/models/audit_activity/investigation/team_added.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
psd-web/app/models/audit_activity/investigation/team_deleted.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.