needed a policy for tokens
This commit is contained in:
parent
b40fedda1a
commit
6f5258cbb7
2 changed files with 24 additions and 2 deletions
24
app/policies/token_policy.rb
Normal file
24
app/policies/token_policy.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
class TokenPolicy < ApplicationPolicy
|
||||||
|
class Scope < Scope
|
||||||
|
def resolve
|
||||||
|
if user
|
||||||
|
scope.where('tokens.user_id = ?', user.id)
|
||||||
|
else
|
||||||
|
where(:id => nil).where("id IS NOT ?", nil) # to just return none
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def my_tokens?
|
||||||
|
user.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
user.present? && record.user == user
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,9 +1,7 @@
|
||||||
class TokenSerializer < ActiveModel::Serializer
|
class TokenSerializer < ActiveModel::Serializer
|
||||||
embed :ids, include: true
|
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:token,
|
:token,
|
||||||
:description,
|
:description,
|
||||||
:user_id,
|
|
||||||
:created_at,
|
:created_at,
|
||||||
:updated_at
|
:updated_at
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue