action_authorization 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8db241a524b3efac2f3bc9bb6b7120964bad8c2b3579cb7e995eaa1f2fb6769
4
- data.tar.gz: 3b290a3e506102c966d72b1d50a3ce79601131eb57a8c43b1fb0d8abfaeae9d0
3
+ metadata.gz: d6ec2bb21ab2cd6e7a6fc961076931ba385d327272437427e2653f07dabd0901
4
+ data.tar.gz: 6b01e8b343d8fc465e9ad5c36bf76f515ca7f1b809bfc28f2ba4f66d106f6d5c
5
5
  SHA512:
6
- metadata.gz: d885298da22ba1f83a3d476e9919176b00be7c1af51d7809e32b2a64a35ca792729f76a68071fe4398f55be133508d24d57c7b3065127d1e083910d1f0d7e244
7
- data.tar.gz: 7537d47e65899fc07b30780518f6144be9ede5fad9cce0dd743f4a6ee7ddc197b20b50032538f20518f8ecc69a4f3456f20b3021e0a3bcf32998eac68f4a5ebe
6
+ metadata.gz: d91740824f6f3aca60f1c98de4ac7fea9e3e231e710e1ce027465cb8908596264885710c0d3b3ca98d8cd877d26d9ef83a3d1c6848624aa171f2bedc0798fe52
7
+ data.tar.gz: 8f6b3b6a14ba8533f6361aa1cd1241141ee246ee1561098cfa88fba41b53d64124be783a4a45ec01b4ef95fe2f3628b327b17f4171652be16e4e8d33bb775d4a
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,5 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
3
2
 
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
3
+ require "bundler/setup"
9
4
 
10
- task :default => :test
5
+ require "bundler/gem_tasks"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
4
  class AuthorizationFailure < StandardError
3
5
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
4
  class BasePolicy
3
5
  attr_accessor :user, :object
4
6
 
5
7
  def self.type
6
- name.gsub('Policy', '')
8
+ name.delete_suffix("Policy")
7
9
  end
8
10
 
9
11
  def self.type_class
@@ -21,6 +23,7 @@ module ActionAuthorization
21
23
 
22
24
  # create alias to object from subclass name
23
25
  def self.inherited(klass)
26
+ super
24
27
  klass.send(:alias_method, klass.type.underscore, :object)
25
28
  end
26
29
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionAuthorization
2
- VERSION = "0.2.3"
4
+ VERSION = "0.3.1"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/delegation"
2
4
  require "active_support/core_ext/string/inflections"
3
5
  require "action_authorization/version"
@@ -14,11 +16,9 @@ module ActionAuthorization
14
16
  protected
15
17
 
16
18
  def authorize(object, action: action_name, policy_class: nil)
17
- if policy(object, policy_class).send("#{action}?")
18
- object
19
- else
20
- raise ActionAuthorization::AuthorizationFailure
21
- end
19
+ raise AuthorizationFailure unless policy(object, policy_class).public_send(:"#{action}?")
20
+
21
+ object
22
22
  end
23
23
 
24
24
  def policy(object, policy_class = nil)
@@ -26,6 +26,6 @@ module ActionAuthorization
26
26
  end
27
27
 
28
28
  def policy_class_for(object)
29
- "#{object.class.name}Policy".constantize
29
+ "#{object.model_name}Policy".constantize
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Baldwin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-05 00:00:00.000000000 Z
12
+ date: 2024-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -33,6 +33,7 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - MIT-LICENSE
36
37
  - README.md
37
38
  - Rakefile
38
39
  - lib/action_authorization.rb
@@ -44,7 +45,7 @@ licenses:
44
45
  - MIT
45
46
  metadata:
46
47
  homepage_uri: https://github.com/wwidea/action_authorization
47
- source_code_uri: https://github.com/wwidea/action_authorization
48
+ rubygems_mfa_required: 'true'
48
49
  post_install_message:
49
50
  rdoc_options: []
50
51
  require_paths:
@@ -53,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
54
  requirements:
54
55
  - - ">="
55
56
  - !ruby/object:Gem::Version
56
- version: '0'
57
+ version: 3.1.0
57
58
  required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - ">="
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  requirements: []
63
- rubygems_version: 3.2.15
64
+ rubygems_version: 3.5.11
64
65
  signing_key:
65
66
  specification_version: 4
66
67
  summary: Rails controller object-level action authorization.