Skip to content

Commit

Permalink
Fix case with headless policies which wasn't intruded
Browse files Browse the repository at this point in the history
  • Loading branch information
dikond committed Aug 1, 2018
1 parent f6b9573 commit d03742e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
grabli (0.1.0)
grabli (0.2.0)
pundit (> 0)

GEM
Expand Down
6 changes: 4 additions & 2 deletions lib/grabli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def collect(user, subject)
isubject = subject.is_a?(Symbol) ? Intruder.new(false) : subject
policy = policy_class(subject).new(user, isubject)

collection << permission if allowed? policy, permission
collection << permission if allowed?(policy, permission)
end
end

Expand All @@ -58,7 +58,9 @@ def collect(user, subject)
#
def allowed?(policy, permission)
result = policy.public_send(permission)
return !policy.record.intruded if policy.record.is_a?(Intruder)

return false if policy.record.is_a?(Intruder) && policy.record.intruded

result
end

Expand Down
4 changes: 4 additions & 0 deletions spec/grabli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def update?
manage_occupied? || current_user.admin
end

def destroy?
false
end

def permitted_attributes
%i[foo]
end
Expand Down

0 comments on commit d03742e

Please sign in to comment.