active_admin_basic_authorization_adapter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d223b336653df7044e325219500a1b53aa821fb8a31156939e9306d7bc7600d9
4
+ data.tar.gz: 473e20a9ce65a60386bdf7fc5fd5a9960f0384623aee406d7e4ed14e5db98d1e
5
+ SHA512:
6
+ metadata.gz: d86e76bc1d6469bdf7e39300288255e1b22eafb8b8b4b337de9d7a43595c09235e63b09f1ee7cd20944857c8c8000752626f2f70ac9316e59e839fd8e99be8b9
7
+ data.tar.gz: 55169f7eda6c323b743df8fe9f6697ac24d6c5ec4599868a8a1385b270763f39a950f087c0f330ebfcb471b6492ede6de9171bec65e06001b683ca1550fd3fd4
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ActiveAdminBasicAuthorizationAdapter < ActiveAdmin::AuthorizationAdapter
4
+ def authorized?(action, subject = nil)
5
+ return unless should_ask_authorization(subject)
6
+
7
+ set_record(subject)
8
+ set_authorization_class(subject)
9
+ @authorization_class.new(user, @record).send(action)
10
+ rescue NameError
11
+ begin
12
+ ActiveAdmin::Authorizations::DefaultAuthorization.new(user, @record).send(action)
13
+ rescue StandardError
14
+ false
15
+ end
16
+ end
17
+
18
+ def should_ask_authorization(subject)
19
+ subject.is_a?(Class) ||
20
+ subject.instance_of?(ActiveAdmin::Page) ||
21
+ subject.is_a?(ActiveRecord::Base)
22
+ end
23
+
24
+ def set_record(subject)
25
+ @record = subject.is_a?(ActiveRecord::Base) ? subject : nil
26
+ end
27
+
28
+ def set_authorization_class(subject)
29
+ @author_class_name = if subject.is_a?(ActiveRecord::Base)
30
+ subject.class.name
31
+ else
32
+ subject.name.gsub(' ', '')
33
+ end
34
+ @authorization_class = "ActiveAdmin::Authorizations::#{@author_class_name}Authorization".constantize
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ Description:
2
+ Generates admin authorizations file with default crud to false.
3
+ Customize methods to change the authorizations
4
+
5
+ Example:
6
+ bin/rails generate basic_admin_authorization Thing
7
+
8
+ This will create:
9
+ app/admin/authorizations/thing_authorization.rb
10
+
11
+ You can also pass an option admin_type that will the default code in all the basic CRUD methods
12
+
13
+ Example:
14
+ bin/rails generate basic_admin_authorization Thing --admin_type 'true'
15
+
16
+ This will create:
17
+ app/admin/authorizations/thing_authorization.rb
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BasicAdminAuthorizationGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('templates', __dir__)
5
+ class_option :admin_type, type: :string, desc: 'Admin type', default: false
6
+
7
+ def create_authorizations_file
8
+ authorization = options[:admin_type]
9
+
10
+ create_file "app/admin/authorizations/#{file_name}_authorization.rb", <<~FILE
11
+ # frozen_string_literal: true
12
+
13
+ module ActiveAdmin
14
+ module Authorizations
15
+ class #{class_name}Authorization < DefaultAuthorization
16
+ def read
17
+ #{authorization}
18
+ end
19
+
20
+ def create
21
+ #{authorization}
22
+ end
23
+
24
+ def update
25
+ #{authorization}
26
+ end
27
+
28
+ def destroy
29
+ #{authorization}
30
+ end
31
+
32
+ # Add your custom member_actions here
33
+ end
34
+ end
35
+ end
36
+ FILE
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates default admin authorization file with default crud to false.
3
+
4
+ Example:
5
+ bin/rails generate default_basic_admin_authorization
6
+
7
+ This will create:
8
+ app/admin/authorizations/default_authorization.rb
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DefaultBasicAdminAuthorizationGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ def create_authorizations_file
7
+ create_file 'app/admin/authorizations/default_authorization.rb', <<~FILE
8
+ # frozen_string_literal: true
9
+
10
+ module ActiveAdmin
11
+ module Authorizations
12
+ class DefaultAuthorization
13
+ def initialize(user, record = nil)
14
+ @user = user
15
+ @record = record
16
+ end
17
+
18
+ def read
19
+ false
20
+ end
21
+
22
+ def create
23
+ false
24
+ end
25
+
26
+ def update
27
+ false
28
+ end
29
+
30
+ def destroy
31
+ false
32
+ end
33
+ end
34
+ end
35
+ end
36
+ FILE
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_basic_authorization_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rémi Wallaere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pundit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activeadmin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.14.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.14.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: railties
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '13.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '13.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.24.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.24.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 2.0.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 2.0.0
167
+ description: |-
168
+ Warning, this gem is just a test for now has not a good test coverage.
169
+ Feel free to open an issue for any problem, and please wait for a stable version before any integration.
170
+ And it is a simple gem to handle authorizations for active admin
171
+ email: remi.wallaere02200@hotmail.fr
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - lib/active_admin_basic_authorization_adapter.rb
177
+ - lib/generators/admin_authorization/USAGE
178
+ - lib/generators/admin_authorization/basic_admin_authorization_generator.rb
179
+ - lib/generators/default_admin_authorization/USAGE
180
+ - lib/generators/default_admin_authorization/default_basic_admin_authorization_generator.rb
181
+ homepage: https://rubygems.org/gems/active_admin_basic_authorization_adapter
182
+ licenses:
183
+ - MIT
184
+ metadata:
185
+ rubygems_mfa_required: 'true'
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 2.7.5
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubygems_version: 3.1.6
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: An unofficial and badly tested Basic active admin authorization
205
+ test_files: []