Skip to content

Commit

Permalink
Make sure submitters entity is never redacted
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Feb 14, 2024
1 parent 10681a7 commit 80db3b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ def attributes_for_deduplication
end

def force_redactions
# We don't want to ever redact entities linked with users with the submitter role
return if submitter_user_entity?

InstanceRedactor.new.redact(self, REDACTABLE_FIELDS)
end

def submitter_user_entity?
self.users.joins(:roles).where(roles: { name: 'submitter' }).any?
end

def publication_delay
self.users.first&.publication_delay || 0
end
Expand Down
1 change: 1 addition & 0 deletions lib/redactors/google_sender_redactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def redact(instance)
private

def redact_entity(entity)
return if entity.submitter_user_entity?
return if entity.nil?

if entity.name != Lumen::REDACTION_MASK
Expand Down
32 changes: 32 additions & 0 deletions spec/models/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@
expect(entity).to receive(:force_redactions)
entity.save
end

context 'redaction of submitter entities' do
it "doesn't redact entities linked to users with submitter role" do
params = { name: 'Test if we redact' }
entity = Entity.new(params)
entity.save

create(:user, :submitter, entity: entity)

entity.name = 'Test if we redact [email protected]'
entity.save

expect(entity.name).to include '[email protected]'
end

it "doesn't redact entities linked to users with submitter role using GoogleSenderRedactor" do
params = { name: 'Test if we redact' }
entity = Entity.new(params)
entity.save

create(:user, :submitter, entity: entity)

notice = create(:defamation, :with_facet_data)
notice.entity_notice_roles = notice.entity_notice_roles.select { |entity_role| entity_role.name.to_sym != :sender }
notice.entity_notice_roles << create(:entity_notice_role, entity: entity, name: 'sender')
notice.recipient.name = 'Google'
notice.auto_redact
notice.recipient.save

expect(notice.sender.name).not_to eq Lumen::REDACTION_MASK
end
end
end

context 'validating scoped name attribute' do
Expand Down

0 comments on commit 80db3b8

Please sign in to comment.