Skip to content

Commit

Permalink
add update_lock permission
Browse files Browse the repository at this point in the history
  • Loading branch information
toyhammered committed Nov 1, 2020
1 parent 73cc3d1 commit ae78d02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/graphql/mutations/post/lock_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load_post(value)
end

def authorized?(post:)
super(post, :update?)
super(post, :update_lock?)
end

def resolve(post:)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/post/unlock_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load_post(value)
end

def authorized?(post:)
super(post, :update?)
super(post, :update_lock?)
end

def resolve(post:)
Expand Down
8 changes: 8 additions & 0 deletions app/policies/post_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def update?
return false unless user
return false if user.has_role?(:banned)
return true if is_admin?
# NOTE: this is required to be here because posts are updated through json-api
return false if record.locked?
return true if group && has_group_permission?(:content)
is_owner?
Expand Down Expand Up @@ -36,6 +37,13 @@ def group
record.target_group
end

def update_lock?
return true if is_admin?
return true if group && has_group_permission(:content)

false
end

class Scope < Scope
def resolve
return scope if is_admin?
Expand Down

0 comments on commit ae78d02

Please sign in to comment.