Add valuation permissions to groups

This commit is contained in:
rgarcia
2018-02-09 21:52:17 +01:00
parent 1152f95965
commit 7a01745188
3 changed files with 13 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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