From 2c6bdc2d93e00d4829cc1d0e8967163df31ceca8 Mon Sep 17 00:00:00 2001 From: Garllon Date: Fri, 2 Apr 2021 22:16:54 +0200 Subject: [PATCH 1/2] add pundit gem --- Gemfile | 1 + Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index 39dafaf..6afcc2c 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'jquery-rails', '~> 4.4' gem 'lazy_high_charts', '~> 1.6' gem 'pg', '~> 1.1' gem 'puma', '~> 5.0' +gem 'pundit', '~> 2.1' gem 'rails', '~> 6.1.1' gem 'sass-rails', '>= 6' gem 'sprockets', '~> 4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 96cda2d..5a00032 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -140,6 +140,8 @@ GEM public_suffix (4.0.6) puma (5.2.1) nio4r (~> 2.0) + pundit (2.1.0) + activesupport (>= 3.0.0) racc (1.5.2) rack (2.2.3) rack-mini-profiler (2.3.1) @@ -259,6 +261,7 @@ DEPENDENCIES listen (~> 3.3) pg (~> 1.1) puma (~> 5.0) + pundit (~> 2.1) rack-mini-profiler (~> 2.0) rails (~> 6.1.1) rubocop (~> 1.9) From d7ba0142b9c54955af01af6fc2d15cf36e8166d0 Mon Sep 17 00:00:00 2001 From: Garllon Date: Fri, 2 Apr 2021 23:54:05 +0200 Subject: [PATCH 2/2] pundit init --- app/controllers/application_controller.rb | 1 + app/policies/application_policy.rb | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 app/policies/application_policy.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7944f9f..5dde212 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base + include Pundit end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb new file mode 100644 index 0000000..eefe976 --- /dev/null +++ b/app/policies/application_policy.rb @@ -0,0 +1,49 @@ +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