This commit is contained in:
2018-11-11 10:12:43 -06:00
parent 8a7b3d8ae0
commit 869a9fc048
16 changed files with 412 additions and 13 deletions

View File

@ -0,0 +1,45 @@
# frozen_string_literal: true
class BlogPolicy < ApplicationPolicy
def show?
return true if update?
record.published?
end
def update?
return true if user&.acts_as_admin?
record.user_id == user&.id
end
def destroy?
update?
end
def create?
user&.acts_as_author?
end
def permitted_attributes
return base_attributes + %i[user_id] if user&.acts_as_admin?
base_attributes
end
def base_attributes
%i[
title
article
]
end
class Scope < Scope
def resolve
return scope if user&.acts_as_admin?
return scope.published.or(user.blogs) if user&.acts_as_author?
scope.published
end
end
end