needed a policy for tokens

This commit is contained in:
Connor Turland 2016-03-14 08:19:26 +11:00
parent b40fedda1a
commit 6f5258cbb7
2 changed files with 24 additions and 2 deletions

View 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

View file

@ -1,9 +1,7 @@
class TokenSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id,
:token,
:description,
:user_id,
:created_at,
:updated_at