From 7a43e41e9838cea79ed6751257ceb2cae48a8b57 Mon Sep 17 00:00:00 2001 From: Alberto Espinoza Date: Tue, 7 Nov 2023 12:20:41 -0600 Subject: [PATCH] R2-2680 W - UAT - Forbidden error when flagging family Adding Family to configure_flags --- app/models/ability.rb | 2 +- spec/models/ability_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 3df0bb7a59..8a6779ac5a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index babb1dc182..b9d659a2f8 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -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 @@ -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