Skip to content

Commit

Permalink
Merged in r2-2680-uat-forbidden-error-flagging-family (pull request #…
Browse files Browse the repository at this point in the history
…6583)

R2-2680 W - UAT - Forbidden error when flagging family
  • Loading branch information
aespinoza-quoin authored and pnabutovsky committed Nov 7, 2023
2 parents 3b3249b + 7a43e41 commit 6174aa0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def initialize_permission(permission)
# rubocop:enable Metrics/CyclomaticComplexity

def configure_flags
[Child, TracingRequest, Incident, RegistryRecord].each do |model|
[Child, TracingRequest, Incident, RegistryRecord, Family].each do |model|
configure_flag(model)
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) 2014 - 2023 UNICEF. All rights reserved.

require 'rails_helper'
require 'cancan/matchers'

describe Ability do
CRUD = %i[index create view edit update destroy].freeze
Expand Down Expand Up @@ -168,6 +169,25 @@
expect(ability).to authorize(:read, case1)
expect(ability).to authorize(:write, case1)
end

describe '#configure_flags' do
let(:flag_permissions) do
Permission.records.map do |resource|
Permission.new(resource:, actions: [Permission::READ, Permission::FLAG])
end
end

let(:flag_role) { create :role, permissions: flag_permissions }
let(:flag_user) { create :user, role: flag_role }
subject(:ability) { Ability.new(flag_user) }

it 'allows to flag records an user' do
[Child, TracingRequest, Incident, RegistryRecord, Family].each do |model|
instance = model.new_with_user(flag_user, {})
expect(ability).to be_able_to(:flag_record, instance)
end
end
end
end

describe 'Roles' do
Expand Down

0 comments on commit 6174aa0

Please sign in to comment.