Files
grecia/app/models/abilities/valuator.rb
Bertocq 26cf91c61a Create valuation comments creation ability
Why:

Only admins or valuators (for those investments they've assigned) can
create internal valuation comments on them.

How:

* Creating a new `comment_valuation` ability for admins and valuators in
the same manner the `valuate` ability works.

* Adding a validation at Comment model for those with `valuation` flag
active that checks if the author can make a valuation comment on the
commentable, as well as the respective active record error messages.
This will prevent comments from being created at a controller level as
well.

* Improving comment factory trait `valuation` to have an associated
investment, author that is a valuator and setting the valuator on the
valuators list of the investment
2018-01-31 02:03:03 +01:00

13 lines
402 B
Ruby

module Abilities
class Valuator
include CanCan::Ability
def initialize(user)
valuator = user.valuator
can [:read, :update, :valuate], SpendingProposal
can [:read, :update, :valuate, :comment_valuation], Budget::Investment, id: valuator.investment_ids
cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: 'finished' }
end
end
end