Initial install of action policy

This commit is contained in:
2024-09-12 12:41:38 +02:00
parent 74038c0615
commit 64289d045d
5 changed files with 61 additions and 4 deletions

View File

@@ -80,3 +80,5 @@ gem "authentication-zero", "~> 3.0"
# Use Pwned to check if a password has been found in any of the huge data breaches [https://github.com/philnash/pwned] # Use Pwned to check if a password has been found in any of the huge data breaches [https://github.com/philnash/pwned]
gem "pwned" gem "pwned"
gem "action_policy", "~> 0.7.1"

View File

@@ -2,6 +2,8 @@ GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
Ascii85 (1.1.1) Ascii85 (1.1.1)
action_policy (0.7.1)
ruby-next-core (>= 1.0)
actioncable (7.2.1) actioncable (7.2.1)
actionpack (= 7.2.1) actionpack (= 7.2.1)
activesupport (= 7.2.1) activesupport (= 7.2.1)
@@ -162,7 +164,7 @@ GEM
mini_mime (1.1.5) mini_mime (1.1.5)
minitest (5.25.1) minitest (5.25.1)
msgpack (1.7.2) msgpack (1.7.2)
net-imap (0.4.15) net-imap (0.4.16)
date date
net-protocol net-protocol
net-pop (0.1.2) net-pop (0.1.2)
@@ -247,7 +249,7 @@ GEM
redis-client (0.22.2) redis-client (0.22.2)
connection_pool connection_pool
regexp_parser (2.9.2) regexp_parser (2.9.2)
reline (0.5.9) reline (0.5.10)
io-console (~> 0.5) io-console (~> 0.5)
rexml (3.3.7) rexml (3.3.7)
rubocop (1.66.1) rubocop (1.66.1)
@@ -260,7 +262,7 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0) rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0) unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.2) rubocop-ast (1.32.3)
parser (>= 3.3.1.0) parser (>= 3.3.1.0)
rubocop-minitest (0.36.0) rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0) rubocop (>= 1.61, < 2.0)
@@ -268,7 +270,7 @@ GEM
rubocop-performance (1.21.1) rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0) rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.26.0) rubocop-rails (2.26.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0) rubocop (>= 1.52.0, < 2.0)
@@ -278,6 +280,7 @@ GEM
rubocop-minitest rubocop-minitest
rubocop-performance rubocop-performance
rubocop-rails rubocop-rails
ruby-next-core (1.0.3)
ruby-progressbar (1.13.0) ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5) ruby-rc4 (0.1.5)
ruby-vips (2.2.2) ruby-vips (2.2.2)
@@ -354,6 +357,7 @@ PLATFORMS
x86_64-linux x86_64-linux
DEPENDENCIES DEPENDENCIES
action_policy (~> 0.7.1)
authentication-zero (~> 3.0) authentication-zero (~> 3.0)
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
bootsnap bootsnap

View File

@@ -0,0 +1,18 @@
# Base class for application policies
class ApplicationPolicy < ActionPolicy::Base
# Configure additional authorization contexts here
# (`user` is added by default).
#
# authorize :account, optional: true
#
# Read more about authorization context: https://actionpolicy.evilmartians.io/#/authorization_context
private
# Define shared methods useful for most policies.
# For example:
#
# def owner?
# record.user_id == user.id
# end
end

View File

@@ -0,0 +1,20 @@
class JobPolicy < ApplicationPolicy
# See https://actionpolicy.evilmartians.io/#/writing_policies
#
# def index?
# true
# end
#
# def update?
# # here we can access our context and record
# user.admin? || (user.id == record.user_id)
# end
# Scoping
# See https://actionpolicy.evilmartians.io/#/scoping
#
# relation_scope do |relation|
# next relation if user.admin?
# relation.where(user: user)
# end
end

View File

@@ -0,0 +1,13 @@
require "test_helper"
# See https://actionpolicy.evilmartians.io/#/testing?id=testing-policies
class JobPolicyTest < ActiveSupport::TestCase
def test_index
end
def test_create
end
def test_manage
end
end