debian-mirror-gitlab/app/policies/todo_policy.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
840 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
class TodoPolicy < BasePolicy
desc 'User can only read own todos'
condition(:own_todo) do
@user && @subject.user_id == @user.id
end
2022-10-02 17:18:49 +05:30
desc "User can read the todo's target"
2021-08-04 16:29:09 +05:30
condition(:can_read_target) do
@user && @subject.target&.readable_by?(@user)
end
2019-12-21 20:55:43 +05:30
2022-10-02 17:18:49 +05:30
desc "Todo has confidential note"
condition(:has_confidential_note, scope: :subject) { @subject&.note&.confidential? }
desc "User can read the todo's confidential note"
condition(:can_read_todo_confidential_note) do
2022-11-25 23:54:43 +05:30
@user && @user.can?(:read_internal_note, @subject.target)
2022-10-02 17:18:49 +05:30
end
2021-08-04 16:29:09 +05:30
rule { own_todo & can_read_target }.enable :read_todo
2022-10-02 17:18:49 +05:30
rule { can?(:read_todo) }.enable :update_todo
rule { has_confidential_note & ~can_read_todo_confidential_note }.policy do
prevent :read_todo
prevent :update_todo
end
2019-12-21 20:55:43 +05:30
end