From 7a017451881b4f76af303c38ad1fc20c8fe56746 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 9 Feb 2018 21:52:17 +0100 Subject: [PATCH] Add valuation permissions to groups --- app/models/abilities/valuator.rb | 4 ++-- app/models/valuator_group.rb | 2 ++ spec/models/abilities/valuator_spec.rb | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb index 3c12f2089..8ea8d71cf 100644 --- a/app/models/abilities/valuator.rb +++ b/app/models/abilities/valuator.rb @@ -5,8 +5,8 @@ module Abilities def initialize(user) valuator = user.valuator can [:read, :update, :valuate], SpendingProposal - can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.investment_ids - can [:valuate], Budget::Investment, { id: valuator.investment_ids, valuation_finished: false } + can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.investment_ids + valuator.valuator_group.investment_ids + can [:valuate], Budget::Investment, { id: valuator.investment_ids + valuator.valuator_group.investment_ids, valuation_finished: false } cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: 'finished' } end end diff --git a/app/models/valuator_group.rb b/app/models/valuator_group.rb index ba7fc5edc..c5bf8d29b 100644 --- a/app/models/valuator_group.rb +++ b/app/models/valuator_group.rb @@ -1,3 +1,5 @@ class ValuatorGroup < ActiveRecord::Base has_many :valuators + has_many :valuator_group_assignments, dependent: :destroy, class_name: 'Budget::ValuatorGroupAssignment' + has_many :investments, through: :valuator_group_assignments, class_name: 'Budget::Investment' end \ No newline at end of file diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index 41c885421..3b40457b8 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -6,12 +6,18 @@ describe Abilities::Valuator do let(:user) { valuator.user } let(:valuator) { create(:valuator) } + let(:group) { create(:valuator_group) } let(:non_assigned_investment) { create(:budget_investment) } let(:assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'valuating')) } + let(:group_assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'valuating')) } let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, phase: 'finished')) } before do assigned_investment.valuators << valuator + + group_assigned_investment.valuator_groups << group + valuator.update(valuator_group: group) + finished_assigned_investment.valuators << valuator end @@ -31,6 +37,9 @@ describe Abilities::Valuator do it { should be_able_to(:update, assigned_investment) } it { should be_able_to(:valuate, assigned_investment) } + it { should be_able_to(:update, group_assigned_investment) } + it { should be_able_to(:valuate, group_assigned_investment) } + it { should_not be_able_to(:update, finished_assigned_investment) } it { should_not be_able_to(:valuate, finished_assigned_investment) } end