Skip to content

Commit

Permalink
Basic pundit setup with OrderPolicy on create
Browse files Browse the repository at this point in the history
- Needs to be integrated into a controller with `authorize @order` to be useful
  • Loading branch information
jonny5 committed Jun 1, 2024
1 parent 2be7ed5 commit e9429c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
end

gem "pundit", "~> 2.3"
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ GEM
public_suffix (5.0.5)
puma (6.4.2)
nio4r (~> 2.0)
pundit (2.3.2)
activesupport (>= 3.0.0)
racc (1.7.3)
rack (3.0.10)
rack-session (2.0.0)
Expand Down Expand Up @@ -380,6 +382,7 @@ DEPENDENCIES
pg (~> 1.1)
pry (~> 0.14.2)
puma (>= 5.0)
pundit (~> 2.3)
rails (~> 7.1.3, >= 7.1.3.2)
selenium-webdriver
shadcn-ui (~> 0.0.12)
Expand Down
12 changes: 12 additions & 0 deletions app/policies/order_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class OrderPolicy
attr_reader :user, :order

def initialize(user, order)
@user = user
@order = order
end

def create?
user.portfolio == order.portfolio
end
end

0 comments on commit e9429c9

Please sign in to comment.