Sha256: 2659d8fc61a1fda6b055f87f490966992585cb8988f406fa3a9996cded27a660
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module Storytime class PostPolicy attr_reader :user, :record class Scope < Struct.new(:user, :scope) def resolve action = Storytime::Action.find_by(guid: "d8a1b1") if user.role.allowed_actions.include?(action) scope.all else scope.where(user_id: user.id) end end end def initialize(user, record) @user = user @post = record end def index? !@user.nil? end def create? @post.user == @user end def new? create? end def update? manage? end def edit? manage? end def destroy? manage? end def manage? if @user == @post.user true else action = Storytime::Action.find_by(guid: "d8a1b1") @user.role.allowed_actions.include?(action) end end def publish? action = if @user == @post.user Storytime::Action.find_by(guid: "5030ed") else Storytime::Action.find_by(guid: "d8a1b1") end @user.role.allowed_actions.include?(action) end def permitted_attributes if publish? [:title, :draft_content, :draft_version_id, :excerpt, :post_type, :tag_list, :published] else [:title, :draft_content, :draft_version_id, :excerpt, :post_type, :tag_list] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
storytime-0.0.1 | app/policies/storytime/post_policy.rb |