active_entry 1.2.4 → 2.0.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 +275 -141
- data/app/controllers/concerns/active_entry/concern.rb +57 -0
- data/app/helpers/active_entry/view_helper.rb +20 -0
- data/lib/active_entry.rb +7 -88
- data/lib/active_entry/base.rb +66 -0
- data/lib/active_entry/errors.rb +44 -61
- data/lib/active_entry/generators.rb +4 -0
- data/lib/active_entry/policy_finder.rb +25 -0
- data/lib/active_entry/railtie.rb +6 -6
- data/lib/active_entry/rspec.rb +56 -0
- data/lib/active_entry/version.rb +1 -1
- data/lib/generators/active_entry/install/USAGE +8 -0
- data/lib/generators/active_entry/install/install_generator.rb +9 -0
- data/lib/generators/active_entry/install/templates/application_policy.rb +7 -0
- data/lib/generators/policy/USAGE +8 -0
- data/lib/generators/policy/policy_generator.rb +7 -0
- data/lib/generators/policy/templates/policy.rb +53 -0
- data/lib/generators/rspec/USAGE +8 -0
- data/lib/generators/rspec/policy_generator.rb +11 -0
- data/lib/generators/rspec/templates/policy_spec.rb +5 -0
- metadata +19 -5
- data/lib/active_entry/controller_methods.rb +0 -99
data/lib/active_entry/version.rb
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
module ActiveEntry
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
def create_application_policy
|
6
|
+
template "application_policy.rb", File.join("app/policies/application_policy.rb"), skip: true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module <%= class_name %>Policy
|
2
|
+
class Authentication < ApplicationPolicy::Authentication
|
3
|
+
# It's all about decision makers. In your decision makers you tell
|
4
|
+
# Active Entry when and if somebody is authenticated/authorized.
|
5
|
+
#
|
6
|
+
# You can declare decision makers for any method you want.
|
7
|
+
# Just use the same name as your action and add a ? at the end.
|
8
|
+
|
9
|
+
# def index?
|
10
|
+
# end
|
11
|
+
|
12
|
+
# def new?
|
13
|
+
# end
|
14
|
+
|
15
|
+
# def create?
|
16
|
+
# end
|
17
|
+
|
18
|
+
# def show?
|
19
|
+
# end
|
20
|
+
|
21
|
+
# def edit?
|
22
|
+
# end
|
23
|
+
|
24
|
+
# def update?
|
25
|
+
# end
|
26
|
+
|
27
|
+
# def destroy?
|
28
|
+
# end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Authorization < ApplicationPolicy::Authorization
|
32
|
+
# def index?
|
33
|
+
# end
|
34
|
+
|
35
|
+
# def new?
|
36
|
+
# end
|
37
|
+
|
38
|
+
# def create?
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def show?
|
42
|
+
# end
|
43
|
+
|
44
|
+
# def edit?
|
45
|
+
# end
|
46
|
+
|
47
|
+
# def update?
|
48
|
+
# end
|
49
|
+
|
50
|
+
# def destroy?
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Generators
|
3
|
+
class PolicyGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def create_policy_spec
|
7
|
+
template "policy_spec.rb", File.join("spec/policies", class_path, "#{file_name}_policy_spec.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_entry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TFM Agency GmbH
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -81,8 +81,8 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
description: An easy and flexible access control system.
|
85
|
-
|
84
|
+
description: An easy and flexible access control system. Authentication and authorization
|
85
|
+
before a method/action is executed.
|
86
86
|
email:
|
87
87
|
- hello@tfm.agency
|
88
88
|
executables: []
|
@@ -92,11 +92,25 @@ files:
|
|
92
92
|
- MIT-LICENSE
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
|
+
- app/controllers/concerns/active_entry/concern.rb
|
96
|
+
- app/helpers/active_entry/view_helper.rb
|
95
97
|
- lib/active_entry.rb
|
96
|
-
- lib/active_entry/
|
98
|
+
- lib/active_entry/base.rb
|
97
99
|
- lib/active_entry/errors.rb
|
100
|
+
- lib/active_entry/generators.rb
|
101
|
+
- lib/active_entry/policy_finder.rb
|
98
102
|
- lib/active_entry/railtie.rb
|
103
|
+
- lib/active_entry/rspec.rb
|
99
104
|
- lib/active_entry/version.rb
|
105
|
+
- lib/generators/active_entry/install/USAGE
|
106
|
+
- lib/generators/active_entry/install/install_generator.rb
|
107
|
+
- lib/generators/active_entry/install/templates/application_policy.rb
|
108
|
+
- lib/generators/policy/USAGE
|
109
|
+
- lib/generators/policy/policy_generator.rb
|
110
|
+
- lib/generators/policy/templates/policy.rb
|
111
|
+
- lib/generators/rspec/USAGE
|
112
|
+
- lib/generators/rspec/policy_generator.rb
|
113
|
+
- lib/generators/rspec/templates/policy_spec.rb
|
100
114
|
- lib/tasks/active_entry_tasks.rake
|
101
115
|
homepage: https://github.com/TFM-Agency/active_entry
|
102
116
|
licenses:
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# @author Tobias Feistmantl
|
2
|
-
#
|
3
|
-
# Helper methods for your controller
|
4
|
-
# to identify RESTful actions.
|
5
|
-
module ActiveEntry
|
6
|
-
# @!visibility private
|
7
|
-
def method_missing method_name, *args
|
8
|
-
method_name_str = method_name.to_s
|
9
|
-
|
10
|
-
if methods.include?(:action_name) && method_name_str.include?("_action?")
|
11
|
-
method_name_str.slice! "_action?"
|
12
|
-
|
13
|
-
if methods.include? method_name_str.to_sym
|
14
|
-
return method_name_str == action_name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [Boolean]
|
22
|
-
# True if the called action
|
23
|
-
# is a only-read action.
|
24
|
-
def read_action?
|
25
|
-
action_name == 'index' ||
|
26
|
-
action_name == 'show'
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [Boolean]
|
30
|
-
# True if the called action
|
31
|
-
# is a write action.
|
32
|
-
def write_action?
|
33
|
-
action_name == 'new' ||
|
34
|
-
action_name == 'create' ||
|
35
|
-
action_name == 'edit' ||
|
36
|
-
action_name == 'update' ||
|
37
|
-
action_name == 'destroy'
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return [Boolean]
|
41
|
-
# True if the called action
|
42
|
-
# is a change action.
|
43
|
-
def change_action?
|
44
|
-
action_name == 'edit' ||
|
45
|
-
action_name == 'update' ||
|
46
|
-
action_name == 'destroy'
|
47
|
-
end
|
48
|
-
|
49
|
-
# @note
|
50
|
-
# Also true for the pseudo
|
51
|
-
# update action `new`.
|
52
|
-
#
|
53
|
-
# @note
|
54
|
-
# Only true for create methods
|
55
|
-
# such as new and create.
|
56
|
-
#
|
57
|
-
# @return [Boolean]
|
58
|
-
# True if the called action
|
59
|
-
# is a create action.
|
60
|
-
def create_action?
|
61
|
-
action_name == 'new' ||
|
62
|
-
action_name == 'create'
|
63
|
-
end
|
64
|
-
|
65
|
-
# @note
|
66
|
-
# Also true for the pseudo
|
67
|
-
# update action `edit`.
|
68
|
-
#
|
69
|
-
# @return [Boolean]
|
70
|
-
# True if the called action
|
71
|
-
# is a update action.
|
72
|
-
def update_action?
|
73
|
-
action_name == 'edit' ||
|
74
|
-
action_name == 'update'
|
75
|
-
end
|
76
|
-
|
77
|
-
# @return [Boolean]
|
78
|
-
# True if it's a destroy action.
|
79
|
-
def destroy_action?
|
80
|
-
action_name == 'destroy'
|
81
|
-
end
|
82
|
-
alias delete_action? destroy_action?
|
83
|
-
|
84
|
-
# @return [Boolean]
|
85
|
-
# True if called action
|
86
|
-
# is index, new or create.
|
87
|
-
def collection_action?
|
88
|
-
action_name == 'index' ||
|
89
|
-
action_name == 'new' ||
|
90
|
-
action_name == 'create'
|
91
|
-
end
|
92
|
-
|
93
|
-
# @return [Boolean]
|
94
|
-
# True if called action
|
95
|
-
# is not a collection action.
|
96
|
-
def member_action?
|
97
|
-
!collection_action?
|
98
|
-
end
|
99
|
-
end
|