Class: Storytime::PostPolicy
- Inherits:
-
Object
- Object
- Storytime::PostPolicy
- Defined in:
- app/policies/storytime/post_policy.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #create? ⇒ Boolean
- #destroy? ⇒ Boolean
- #edit? ⇒ Boolean
- #index? ⇒ Boolean
-
#initialize(user, record) ⇒ PostPolicy
constructor
A new instance of PostPolicy.
- #manage? ⇒ Boolean
- #new? ⇒ Boolean
- #permitted_attributes ⇒ Object
- #publish? ⇒ Boolean
- #show? ⇒ Boolean
- #update? ⇒ Boolean
Constructor Details
#initialize(user, record) ⇒ PostPolicy
Returns a new instance of PostPolicy.
16 17 18 19 |
# File 'app/policies/storytime/post_policy.rb', line 16 def initialize(user, record) @user = user @post = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'app/policies/storytime/post_policy.rb', line 3 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/policies/storytime/post_policy.rb', line 3 def user @user end |
Instance Method Details
#create? ⇒ Boolean
25 26 27 |
# File 'app/policies/storytime/post_policy.rb', line 25 def create? @post.user == @user end |
#destroy? ⇒ Boolean
49 50 51 |
# File 'app/policies/storytime/post_policy.rb', line 49 def destroy? manage? end |
#edit? ⇒ Boolean
45 46 47 |
# File 'app/policies/storytime/post_policy.rb', line 45 def edit? manage? end |
#index? ⇒ Boolean
21 22 23 |
# File 'app/policies/storytime/post_policy.rb', line 21 def index? !@user.nil? end |
#manage? ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/policies/storytime/post_policy.rb', line 53 def manage? if @user == @post.user true else action = Storytime::Action.find_by(guid: "d8a1b1") if @user.nil? false else role = @user.storytime_role_in_site(Storytime::Site.current) role.present? && role.allowed_actions.include?(action) end end end |
#new? ⇒ Boolean
29 30 31 |
# File 'app/policies/storytime/post_policy.rb', line 29 def new? create? end |
#permitted_attributes ⇒ Object
83 84 85 86 87 |
# File 'app/policies/storytime/post_policy.rb', line 83 def permitted_attributes attrs = [:title, :draft_content, :draft_version_id, :excerpt, :featured_media_id, :secondary_media_id, :slug, :published_at_date, :notifications_enabled, :published_at_time, :canonical_url, {:tag_list => []}] attrs << :published if publish? attrs end |
#publish? ⇒ Boolean
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/policies/storytime/post_policy.rb', line 68 def publish? action = if @user == @post.user Storytime::Action.find_by(guid: "5030ed") else Storytime::Action.find_by(guid: "d8a1b1") end if @user.nil? false else role = user.storytime_role_in_site(Storytime::Site.current) role && role.allowed_actions.include?(action) end end |
#show? ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'app/policies/storytime/post_policy.rb', line 33 def show? if @post.preview manage? else true end end |
#update? ⇒ Boolean
41 42 43 |
# File 'app/policies/storytime/post_policy.rb', line 41 def update? manage? end |