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
816 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
2023-03-17 16:20:25 +05:30
desc "Todo has internal note"
condition(:has_internal_note, scope: :subject) { @subject&.note&.confidential? }
2022-10-02 17:18:49 +05:30
2023-03-17 16:20:25 +05:30
desc "User can read the todo's internal note"
condition(:can_read_todo_internal_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
2023-03-17 16:20:25 +05:30
rule { has_internal_note & ~can_read_todo_internal_note }.policy do
2022-10-02 17:18:49 +05:30
prevent :read_todo
prevent :update_todo
end
2019-12-21 20:55:43 +05:30
end