aki-operations 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +87 -0
  4. data/Rakefile +27 -0
  5. data/app/controllers/admin/operations/actions_controller.rb +28 -0
  6. data/app/controllers/admin/operations/users_controller.rb +28 -0
  7. data/app/controllers/admin/operations_controller.rb +12 -0
  8. data/app/controllers/operations/enforced_controller.rb +45 -0
  9. data/app/helpers/operations_helper.rb +15 -0
  10. data/app/views/admin/operations/actions/index.html.erb +20 -0
  11. data/app/views/admin/operations/actions/index/_edit.html.erb +0 -0
  12. data/app/views/admin/operations/actions/index/_view.html.erb +156 -0
  13. data/app/views/admin/operations/index.html.erb +88 -0
  14. data/app/views/admin/operations/users/index.html.erb +20 -0
  15. data/app/views/admin/operations/users/index/_edit.html.erb +4 -0
  16. data/app/views/admin/operations/users/index/_view.html.erb +158 -0
  17. data/config/routes.rb +13 -0
  18. data/lib/generators/operations_generator.rb +10 -0
  19. data/lib/generators/templates/operations.rb +33 -0
  20. data/lib/operations.rb +152 -0
  21. data/lib/operations/act_as_operationable.rb +26 -0
  22. data/lib/operations/config.rb +64 -0
  23. data/lib/operations/core_ext.rb +28 -0
  24. data/lib/operations/enforcer.rb +71 -0
  25. data/lib/operations/engine.rb +5 -0
  26. data/lib/operations/errors.rb +6 -0
  27. data/lib/operations/errors/base_exception.rb +12 -0
  28. data/lib/operations/errors/invalid_field_error.rb +9 -0
  29. data/lib/operations/errors/invalid_operation_error.rb +26 -0
  30. data/lib/operations/errors/not_authorized_error.rb +11 -0
  31. data/lib/operations/errors/not_implemented_error.rb +9 -0
  32. data/lib/operations/errors/not_logged_in_error.rb +10 -0
  33. data/lib/operations/operation.rb +167 -0
  34. data/lib/operations/railtie.rb +17 -0
  35. data/lib/operations/utils.rb +10 -0
  36. data/lib/operations/version.rb +3 -0
  37. data/lib/tasks/operations_tasks.rake +6 -0
  38. metadata +252 -0
@@ -0,0 +1,17 @@
1
+ module Operations
2
+ class Railtie < ::Rails::Railtie
3
+ config.operations_list = []
4
+ config.operations = []
5
+ config.user_roles = [
6
+ {name: :admin, value: 0, db_value: 0},
7
+ {name: :guest, value: 3, db_value: 1},
8
+ {name: :regular, value: 2, db_value: 2},
9
+ {name: :technician, value: 1, db_value: 3},
10
+ {name: :all},
11
+ {name: :nobody}
12
+ ]
13
+ config.operation_scope_regex = %r{\A(#{config.user_roles.map{|o| o[:name]}.join('|')})\z}
14
+ config.operation_name_regex = %r{\w}
15
+ config.operation_uuid_algorithm = OpenSSL::Digest::SHA256
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Operations
2
+ module Utils
3
+ class << self
4
+ def parse_to_regex(str)
5
+ escaped = Regexp.escape(str).gsub('\*','.*?')
6
+ Regexp.new "^#{escaped}$", Regexp::IGNORECASE
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Operations
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ namespace :operations do
2
+ desc "Installs a fresh default configuration file for operations."
3
+ task :operations_install do
4
+ # Task goes here
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aki-operations
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Akinyele Cafe-Febrissy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bootstrap
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.1.3
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.1.3
53
+ - !ruby/object:Gem::Dependency
54
+ name: jquery-rails
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.3'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.3.3
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.3'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 4.3.3
73
+ - !ruby/object:Gem::Dependency
74
+ name: jquery-ui-rails
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '6.0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '6.0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: bootstrap4-kaminari-views
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: sqlite3
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 1.3.6
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 1.3.6
115
+ - !ruby/object:Gem::Dependency
116
+ name: sass-rails
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '5.0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '5.0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: select2-rails
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: web-console
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ description: Manage your users' operations (permissions to execute some actions) in
158
+ your application.
159
+ email:
160
+ - akinyele.kafe.febrissy@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - MIT-LICENSE
166
+ - README.md
167
+ - Rakefile
168
+ - app/controllers/admin/operations/actions_controller.rb
169
+ - app/controllers/admin/operations/users_controller.rb
170
+ - app/controllers/admin/operations_controller.rb
171
+ - app/controllers/operations/enforced_controller.rb
172
+ - app/helpers/operations_helper.rb
173
+ - app/views/admin/operations/actions/index.html.erb
174
+ - app/views/admin/operations/actions/index/_edit.html.erb
175
+ - app/views/admin/operations/actions/index/_view.html.erb
176
+ - app/views/admin/operations/index.html.erb
177
+ - app/views/admin/operations/users/index.html.erb
178
+ - app/views/admin/operations/users/index/_edit.html.erb
179
+ - app/views/admin/operations/users/index/_view.html.erb
180
+ - config/routes.rb
181
+ - lib/generators/operations_generator.rb
182
+ - lib/generators/templates/operations.rb
183
+ - lib/operations.rb
184
+ - lib/operations/act_as_operationable.rb
185
+ - lib/operations/config.rb
186
+ - lib/operations/core_ext.rb
187
+ - lib/operations/enforcer.rb
188
+ - lib/operations/engine.rb
189
+ - lib/operations/errors.rb
190
+ - lib/operations/errors/base_exception.rb
191
+ - lib/operations/errors/invalid_field_error.rb
192
+ - lib/operations/errors/invalid_operation_error.rb
193
+ - lib/operations/errors/not_authorized_error.rb
194
+ - lib/operations/errors/not_implemented_error.rb
195
+ - lib/operations/errors/not_logged_in_error.rb
196
+ - lib/operations/operation.rb
197
+ - lib/operations/railtie.rb
198
+ - lib/operations/utils.rb
199
+ - lib/operations/version.rb
200
+ - lib/tasks/operations_tasks.rake
201
+ homepage: https://git.rakuten-it.com
202
+ licenses:
203
+ - MIT
204
+ metadata: {}
205
+ post_install_message:
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubyforge_project:
221
+ rubygems_version: 2.7.6
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: '# Rails Operations Manage your users'' operations (permissions to execute
225
+ some actions) in your Ruby on Rails application. ## Requirements Prior to installing,
226
+ please make sure these gems can be installed on your system: - rails (v5.2+) If
227
+ you wish to run this gem locally, the following gems are also to consider: - bootstrap
228
+ (v4.1+) - jquery-rails (v4.3+) - jquery-ui-rails (v6.0+) - bootstrap4-kaminari-views
229
+ - sqlite3 (v1.3.6+) - sass-rails (v5.0+) - select2-rails - web-console ## Installation
230
+ Add this line to your application''s Gemfile: ```ruby gem ''operations'' ``` And
231
+ then execute: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install
232
+ operations ``` ## Usage Here are the most relevant API entries from this Gem: ```ruby
233
+ ### From Operations module Operations.operations_list # All valid Operations::Operation
234
+ from Rails config Operations.from_string(name) # Gets the Operations::Operation
235
+ by string Operations.allows?(user, name) # Checks if the user can execute the
236
+ operation string Operations.user_roles # All users roles defined in
237
+ the Rails config ### From Operations::Operation class operation = Operations::Operation.new
238
+ do |operation| # Your operation name operation.name = ''my_operation'' # Allows
239
+ :admin, :technician, :regular and :guest. # These can be set in your config/application.rb
240
+ with the # variable config.user_roles. Example: # # module MyApp # class Application
241
+ < Rails::Application # config.user_roles += {name: ''my_other_scope''} # end
242
+ # end operation.scope = :admin end # Or operation = Operations::Operation.new{name:
243
+ :my_operation, scope: :admin} # Instance variable allowed_users = operation.users #
244
+ Returns a list of users based on the scope is_valid = operation.is_valid? #
245
+ For validation purposes ### Core extensions # Convert a string to a list of Operations::Operations
246
+ "bf9[..]a248".to_operation # From a UUID (example truncated) "{\"name\":\"my_operation\",\"scope\":\"admin\"}".to_operation
247
+ # From a valid JSON string ``` ## Contributing Do you wish to contribute? It''s
248
+ simple! All you need to do is: - Fork this project - Work your magic - **RUN TESTS**
249
+ - _Don''t forget to synchronize with the master branch!_ - Push to your fork - Make
250
+ a pull request! ## License The gem is available as open source under the terms
251
+ of the [MIT License](https://opensource.org/licenses/MIT).'
252
+ test_files: []