2019-10-17 11:06:17 -04:00
|
|
|
# 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
|
2021-08-03 17:09:39 -04:00
|
|
|
condition(:can_read_target) do
|
|
|
|
@user && @subject.target&.readable_by?(@user)
|
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
rule { own_todo & can_read_target }.enable :read_todo
|
|
|
|
rule { own_todo & can_read_target }.enable :update_todo
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|