add pundit
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -21,6 +21,7 @@ gem "administrate"
|
|||||||
gem "graphql"
|
gem "graphql"
|
||||||
gem "tailwindcss-rails"
|
gem "tailwindcss-rails"
|
||||||
gem "httparty"
|
gem "httparty"
|
||||||
|
gem "pundit"
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem "dotenv-rails"
|
gem "dotenv-rails"
|
||||||
|
|||||||
@@ -174,6 +174,8 @@ GEM
|
|||||||
public_suffix (4.0.6)
|
public_suffix (4.0.6)
|
||||||
puma (5.4.0)
|
puma (5.4.0)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
|
pundit (2.1.0)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
racc (1.5.2)
|
racc (1.5.2)
|
||||||
rack (2.2.3)
|
rack (2.2.3)
|
||||||
rack-proxy (0.7.0)
|
rack-proxy (0.7.0)
|
||||||
@@ -322,6 +324,7 @@ DEPENDENCIES
|
|||||||
pg (~> 1.1)
|
pg (~> 1.1)
|
||||||
pry-byebug
|
pry-byebug
|
||||||
puma (~> 5.0)
|
puma (~> 5.0)
|
||||||
|
pundit
|
||||||
rails (~> 6.1.4)
|
rails (~> 6.1.4)
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rubocop-rails
|
rubocop-rails
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
include Pundit
|
||||||
end
|
end
|
||||||
|
|||||||
50
app/policies/application_policy.rb
Normal file
50
app/policies/application_policy.rb
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
class ApplicationPolicy
|
||||||
|
attr_reader :user, :record
|
||||||
|
|
||||||
|
def initialize(user, record)
|
||||||
|
@user = user
|
||||||
|
@record = record
|
||||||
|
end
|
||||||
|
|
||||||
|
def index?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def show?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def new?
|
||||||
|
create?
|
||||||
|
end
|
||||||
|
|
||||||
|
def update?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit?
|
||||||
|
update?
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
class Scope
|
||||||
|
attr_reader :user, :scope
|
||||||
|
|
||||||
|
def initialize(user, scope)
|
||||||
|
@user = user
|
||||||
|
@scope = scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve
|
||||||
|
scope.all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user