guarda 0.1.0 → 0.4.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 +4 -4
- data/README.md +54 -18
- data/guarda.gemspec +4 -4
- data/lib/guarda/authorization.rb +2 -2
- data/lib/guarda/policy_finder.rb +1 -1
- data/lib/guarda/version.rb +1 -1
- metadata +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffe343cd6f4cd51a1b384fdb4e1299d14960e574a60fd2ef7e5d03298563289
|
4
|
+
data.tar.gz: 60096b5bd502a631c19b5df0a028fd2e4d96828645da9409f47a53f19ea74b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b1b618a33b3b7a27322cad51b872af9aca19d3d309dbeaf3004112e82b808c859bab5e4c688be6d6f0d98e6ef5ec4359f7573e464e105e8a64563b7d12e2170
|
7
|
+
data.tar.gz: 01bea2ae2c82935e7cfead682f1cedcee50ccace4810b14e1f5f4f5cfbb0d3e20f85fe19eaceccfb904693480c77d1e429e405c26ebcbc3f8da18366f79507fc
|
data/README.md
CHANGED
@@ -1,34 +1,70 @@
|
|
1
1
|
# Guarda
|
2
2
|
|
3
|
-
|
3
|
+
Is another authorization gem that was heavily inspired by [Pundit](https://rubygems.org/gems/pundit).
|
4
4
|
|
5
|
-
|
5
|
+
It assumes you are using [Current Attributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html) to get your currently authenticated user.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
9
|
Install the gem and add to the application's Gemfile by executing:
|
12
10
|
|
13
|
-
|
11
|
+
```bash
|
12
|
+
bundle add guarda
|
13
|
+
```
|
14
14
|
|
15
|
-
|
15
|
+
Include `Guarda::Authorization` in your application controller:
|
16
16
|
|
17
|
-
|
17
|
+
```ruby
|
18
|
+
class ApplicationController < ActionController::Base
|
19
|
+
include Guarda::Authorization
|
20
|
+
end
|
21
|
+
```
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
In the controller:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class PostsController < ApplicationController
|
29
|
+
def index
|
30
|
+
authorize
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
authorize @post
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
In the view:
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<% if policy("posts").index? %>
|
43
|
+
<%= link_to "Posts", "#" %>
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
<% if policy("posts", @post).update? %>
|
47
|
+
<%= link_to "Edit Post", "#" %>
|
48
|
+
<% end %>
|
49
|
+
```
|
50
|
+
|
51
|
+
With this policy class `app/policies/posts_policy.rb`:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class PostsPolicy
|
55
|
+
def initialize(post = nil)
|
56
|
+
@post = post
|
57
|
+
end
|
58
|
+
|
59
|
+
def index?
|
60
|
+
Current.person.admin?
|
61
|
+
end
|
62
|
+
|
63
|
+
def update?
|
64
|
+
@post.author == Current.person
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
32
68
|
|
33
69
|
## License
|
34
70
|
|
data/guarda.gemspec
CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["abdul@hey.com"]
|
10
10
|
|
11
11
|
spec.summary = "Another authorization gem"
|
12
|
-
spec.homepage = "https://
|
12
|
+
spec.homepage = "https://www.guidedrails.com"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">=
|
14
|
+
spec.required_ruby_version = ">= 3.1.0"
|
15
15
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
spec.metadata["source_code_uri"] = "https://github.com/Guided-Rails/guarda"
|
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_development_dependency "activesupport"
|
31
|
-
spec.add_development_dependency "minitest-reporters"
|
30
|
+
spec.add_development_dependency "activesupport", "~> 7.1", ">= 7.1.3"
|
31
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.6", ">= 1.6.1"
|
32
32
|
end
|
data/lib/guarda/authorization.rb
CHANGED
@@ -10,7 +10,7 @@ module Guarda
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def authorize(
|
13
|
+
def authorize(record = nil, controller: nil, query: nil)
|
14
14
|
@_authorization_performed = true
|
15
15
|
controller ||= controller_path
|
16
16
|
query ||= "#{action_name}?"
|
@@ -19,7 +19,7 @@ module Guarda
|
|
19
19
|
raise(NotAuthorizedError, self.class)
|
20
20
|
end
|
21
21
|
|
22
|
-
def policy(controller, record)
|
22
|
+
def policy(controller, record = nil)
|
23
23
|
PolicyFinder.find(controller).new(record)
|
24
24
|
end
|
25
25
|
|
data/lib/guarda/policy_finder.rb
CHANGED
data/lib/guarda/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guarda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdullah Hashim
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.1'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 7.1.3
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '7.1'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: 7.1.3
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: minitest-reporters
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.6'
|
31
40
|
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
42
|
+
version: 1.6.1
|
34
43
|
type: :development
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.6'
|
38
50
|
- - ">="
|
39
51
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
52
|
+
version: 1.6.1
|
41
53
|
description:
|
42
54
|
email:
|
43
55
|
- abdul@hey.com
|
@@ -54,11 +66,11 @@ files:
|
|
54
66
|
- lib/guarda/policy_finder.rb
|
55
67
|
- lib/guarda/version.rb
|
56
68
|
- sig/guarda.rbs
|
57
|
-
homepage: https://
|
69
|
+
homepage: https://www.guidedrails.com
|
58
70
|
licenses:
|
59
71
|
- MIT
|
60
72
|
metadata:
|
61
|
-
homepage_uri: https://
|
73
|
+
homepage_uri: https://www.guidedrails.com
|
62
74
|
source_code_uri: https://github.com/Guided-Rails/guarda
|
63
75
|
post_install_message:
|
64
76
|
rdoc_options: []
|
@@ -68,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
80
|
requirements:
|
69
81
|
- - ">="
|
70
82
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
83
|
+
version: 3.1.0
|
72
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
85
|
requirements:
|
74
86
|
- - ">="
|