action_authorization 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a6fc20effbb11ac51f0621e4bde8c2420c441e678b77b360706697bbaf72f59
4
- data.tar.gz: af35dcfb4cebd7f01f4049902aedc4cb98a8d8b5d44b82123021a1a67684ddf0
3
+ metadata.gz: 54416a7e815288367cea967a9198f197cc2fe10e76e35fcac702406c8b5f8215
4
+ data.tar.gz: 6097c18236273bf1ebce5439813ae6383805a2a66f264321fac402d64792aa2d
5
5
  SHA512:
6
- metadata.gz: 025ea907d5b10dc902061cafe949256fc7f0557c9b82d2949ded870d5f2beaa7b621b648e394114cf1ef8f0891d96d94a98028161358ab3a7332417a8c6c2bbf
7
- data.tar.gz: a9c81b7bcf37b1f03f25d49d1252b1533cd185ec2511799031f077f0562aa9d48d1400bf76517ff43064c035aae21b85f1ff6278d8b6752e72a1ea3a1878650f
6
+ metadata.gz: e3274dbb63f416cd663a7f47f817d7551fe3abdabaa222d0c067c2fad8e7503a074347a469a43c311c018b949d5bff0bbc36253381d38dc045ac92288295a7d1
7
+ data.tar.gz: f6fb7dbb58d0933b4c96623093fda6c8b902b5af769b2c2298ac35e053e39da9a659ea8bc86c8d1b4bb3b3d5ad188a7e4894c3f7a8603cb4f38fb7d56f5bdc61
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017-2023 Aaron Baldwin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # ActionAuthorization
2
-
3
2
  A base policy class for authorizing controller actions with access to the current_user and object.
4
3
 
5
4
  ## Installation
6
-
7
5
  Add this line to your application's Gemfile:
8
6
 
9
7
  ```ruby
@@ -11,19 +9,19 @@ gem 'action_authorization'
11
9
  ```
12
10
 
13
11
  And then execute:
12
+ ```bash
13
+ bundle
14
+ ```
14
15
 
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install action_authorization
16
+ Or install it with:
17
+ ```bash
18
+ gem install action_authorization
19
+ ```
20
20
 
21
21
  ## Requirements
22
-
23
22
  ActionAuthorization requires a **current_user** method that returns the currently logged in user.
24
23
 
25
24
  ## Usage
26
-
27
25
  Include the ActionAuthorization module in your ApplicationController (or indvidual controller(s))
28
26
 
29
27
  ```ruby
@@ -33,7 +31,6 @@ end
33
31
  ```
34
32
 
35
33
  Create an authorization policy for a resource.
36
-
37
34
  ``` ruby
38
35
  class DocumentPolicy < ActionAuthorization::BasePolicy
39
36
  def show?
@@ -43,7 +40,6 @@ end
43
40
  ```
44
41
 
45
42
  Call **authorize** method in controller action.
46
-
47
43
  ```ruby
48
44
  class DocumentController < ApplicationController
49
45
  def show
@@ -67,18 +63,5 @@ Check if authorized before displaying a link in the view.
67
63
  <%= link_to(@document.name, @document) if policy(@document).show? %>
68
64
  ```
69
65
 
70
-
71
- ## Development
72
-
73
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
-
75
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
-
77
- ## Contributing
78
-
79
- Bug reports and pull requests are welcome on GitHub at https://github.com/wwidea/action_authorization.
80
-
81
-
82
66
  ## License
83
-
84
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,10 +1,3 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
8
- end
1
+ require "bundler/setup"
9
2
 
10
- task :default => :test
3
+ require "bundler/gem_tasks"
@@ -2,6 +2,18 @@ module ActionAuthorization
2
2
  class BasePolicy
3
3
  attr_accessor :user, :object
4
4
 
5
+ def self.type
6
+ name.gsub('Policy', '')
7
+ end
8
+
9
+ def self.type_class
10
+ type.constantize
11
+ rescue NameError
12
+ NilClass
13
+ end
14
+
15
+ delegate :type, :type_class, to: :class
16
+
5
17
  def initialize(user, object)
6
18
  self.user = user
7
19
  self.object = object
@@ -9,7 +21,7 @@ module ActionAuthorization
9
21
 
10
22
  # create alias to object from subclass name
11
23
  def self.inherited(klass)
12
- klass.send(:alias_method, klass.name.gsub('Policy', '').underscore, :object)
24
+ klass.send(:alias_method, klass.type.underscore, :object)
13
25
  end
14
26
 
15
27
  def index?
@@ -1,3 +1,3 @@
1
1
  module ActionAuthorization
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,7 +1,8 @@
1
+ require "active_support/core_ext/module/delegation"
2
+ require "active_support/core_ext/string/inflections"
1
3
  require "action_authorization/version"
2
4
  require "action_authorization/base_policy"
3
5
  require "action_authorization/authorization_failure"
4
- require "active_support/core_ext/string/inflections"
5
6
 
6
7
  module ActionAuthorization
7
8
  def self.included(base)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Baldwin
8
+ - Brightways Learning
8
9
  autorequire:
9
- bindir: exe
10
+ bindir: bin
10
11
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
12
+ date: 2023-01-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -24,62 +25,6 @@ dependencies:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '5.0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.1'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.14'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.14'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.4'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '2.4'
83
28
  description: A base policy class for authorizing controller actions with access to
84
29
  the current_user and object.
85
30
  email:
@@ -88,17 +33,9 @@ executables: []
88
33
  extensions: []
89
34
  extra_rdoc_files: []
90
35
  files:
91
- - ".gitignore"
92
- - ".ruby-version"
93
- - ".travis.yml"
94
- - Gemfile
95
- - Guardfile
96
- - LICENSE.txt
36
+ - MIT-LICENSE
97
37
  - README.md
98
38
  - Rakefile
99
- - action_authorization.gemspec
100
- - bin/console
101
- - bin/setup
102
39
  - lib/action_authorization.rb
103
40
  - lib/action_authorization/authorization_failure.rb
104
41
  - lib/action_authorization/base_policy.rb
@@ -106,7 +43,10 @@ files:
106
43
  homepage: https://github.com/wwidea/action_authorization
107
44
  licenses:
108
45
  - MIT
109
- metadata: {}
46
+ metadata:
47
+ homepage_uri: https://github.com/wwidea/action_authorization
48
+ source_code_uri: https://github.com/wwidea/action_authorization
49
+ rubygems_mfa_required: 'true'
110
50
  post_install_message:
111
51
  rdoc_options: []
112
52
  require_paths:
@@ -115,14 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
55
  requirements:
116
56
  - - ">="
117
57
  - !ruby/object:Gem::Version
118
- version: '0'
58
+ version: 2.7.0
119
59
  required_rubygems_version: !ruby/object:Gem::Requirement
120
60
  requirements:
121
61
  - - ">="
122
62
  - !ruby/object:Gem::Version
123
63
  version: '0'
124
64
  requirements: []
125
- rubygems_version: 3.2.15
65
+ rubygems_version: 3.4.5
126
66
  signing_key:
127
67
  specification_version: 4
128
68
  summary: Rails controller object-level action authorization.
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /*.gem
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.0.1
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=0ff5e542d77e2710a003d2ee7a11d4e5a50aaa08fe97ab009a72768885197905
4
- language: ruby
5
- rvm:
6
- - 2.5.1
7
- before_script:
8
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
- - chmod +x ./cc-test-reporter
10
- - ./cc-test-reporter before-build
11
- script:
12
- - bundle exec rake test
13
- after_script:
14
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in rexport.gemspec
6
- gemspec
7
-
8
- group :test do
9
- gem 'simplecov'
10
- end
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard :minitest do
2
- watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
3
- watch(%r{^test/.+_test\.rb$})
4
- watch(%r{^test/test_helper\.rb$}) { 'test' }
5
- end
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Aaron Baldwin
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,30 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'action_authorization/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "action_authorization"
8
- spec.version = ActionAuthorization::VERSION
9
- spec.authors = ["Aaron Baldwin"]
10
- spec.email = ["baldwina@brightwayslearning.org"]
11
-
12
- spec.summary = %q{Rails controller object-level action authorization.}
13
- spec.description = %q{A base policy class for authorizing controller actions with access to the current_user and object.}
14
- spec.homepage = "https://github.com/wwidea/action_authorization"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_runtime_dependency "activesupport", ">= 5.0"
25
-
26
- spec.add_development_dependency "bundler", "~> 2.1"
27
- spec.add_development_dependency "rake", "~> 13.0"
28
- spec.add_development_dependency "guard", "~> 2.14"
29
- spec.add_development_dependency "guard-minitest", "~> 2.4"
30
- end
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "action_authorization"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here