symphonia 4.1.3 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +27 -1
- data/app/assets/javascripts/symphonia/application.js +3 -3
- data/app/assets/javascripts/symphonia/symphonia_bootstrap_dialog.js +23 -23
- data/app/assets/stylesheets/symphonia/_font_awesome.scss +8 -6
- data/app/assets/stylesheets/symphonia/_layout.scss +33 -1
- data/app/assets/stylesheets/symphonia/basic.scss +3 -99
- data/app/assets/stylesheets/symphonia/filters.scss +3 -5
- data/app/assets/stylesheets/symphonia/symphonia_bootstrap.scss +1 -1
- data/app/controllers/symphonia/accounts_controller.rb +7 -3
- data/app/controllers/symphonia/application_controller.rb +2 -1
- data/app/controllers/symphonia/users_controller.rb +17 -29
- data/app/helpers/symphonia/application_helper.rb +48 -26
- data/app/models/symphonia/preference.rb +5 -5
- data/app/models/symphonia/user.rb +3 -35
- data/app/models/symphonia/user_ability.rb +46 -0
- data/app/views/common/403.html.erb +4 -3
- data/app/views/layouts/symphonia/application.html.erb +4 -4
- data/app/views/symphonia/accounts/_detail.html.erb +21 -18
- data/app/views/symphonia/common/_filters.html.erb +15 -15
- data/app/views/symphonia/common/_share_links.html.erb +2 -3
- data/app/views/symphonia/users/_form.html.erb +1 -6
- data/app/views/symphonia/users/show.html.erb +15 -20
- data/config/locales/cs.yml +3 -2
- data/db/migrate/20130714140500_create_users.rb +0 -2
- data/db/seeds.rb +3 -3
- data/lib/generators/symphonia/entity_controller/entity_controller_generator.rb +2 -2
- data/lib/generators/symphonia/entity_controller/templates/{controller.rb → controller.rb.tt} +0 -0
- data/lib/symphonia/admin_constraint.rb +1 -1
- data/lib/symphonia/base_controller.rb +9 -17
- data/lib/symphonia/controller_extensions.rb +5 -15
- data/lib/symphonia/engine.rb +12 -43
- data/lib/symphonia/form_builder.rb +17 -16
- data/lib/symphonia/menu_manager.rb +15 -11
- data/lib/symphonia/model_attributes/attribute.rb +3 -3
- data/lib/symphonia/object.rb +9 -9
- data/lib/symphonia/spec_helper.rb +8 -4
- data/lib/symphonia/user_management.rb +1 -1
- data/lib/symphonia/version.rb +1 -1
- data/lib/symphonia.rb +12 -9
- data/spec/factories/factories.rb +0 -4
- data/spec/models/user_spec.rb +39 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/stub_users.rb +7 -7
- metadata +41 -140
- data/app/controllers/symphonia/roles_controller.rb +0 -39
- data/app/models/symphonia/role.rb +0 -55
- data/app/views/symphonia/roles/_form.html.erb +0 -26
- data/app/views/symphonia/roles/edit.html.erb +0 -5
- data/app/views/symphonia/roles/index.html.erb +0 -6
- data/app/views/symphonia/roles/new.html.erb +0 -4
- data/app/views/symphonia/roles/show.html.erb +0 -11
- data/db/migrate/20130714140501_create_roles.rb +0 -18
- data/db/migrate/20210509141420_roles_change_permissions_to_json.rb +0 -18
- data/db/migrate/20210509180525_roles_change_permissions_to_native_json.rb +0 -7
- data/lib/symphonia/permissions.rb +0 -93
- data/spec/controllers/roles_controller_spec.rb +0 -12
- data/spec/models/role_spec.rb +0 -13
- data/spec/requests/roles_spec.rb +0 -10
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symphonia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Pokorny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: api-pagination
|
@@ -38,48 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 6.4.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: awesome_nested_set
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.2.1
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.2.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bootstrap
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 4.6.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 4.6.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bootstrap-datepicker-rails
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
41
|
- !ruby/object:Gem::Dependency
|
84
42
|
name: bootstrap_form
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,47 +53,33 @@ dependencies:
|
|
95
53
|
- !ruby/object:Gem::Version
|
96
54
|
version: 4.4.0
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
56
|
+
name: cancancan
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
100
58
|
requirements:
|
101
59
|
- - "~>"
|
102
60
|
- !ruby/object:Gem::Version
|
103
|
-
version: 4
|
61
|
+
version: '3.4'
|
104
62
|
type: :runtime
|
105
63
|
prerelease: false
|
106
64
|
version_requirements: !ruby/object:Gem::Requirement
|
107
65
|
requirements:
|
108
66
|
- - "~>"
|
109
67
|
- !ruby/object:Gem::Version
|
110
|
-
version: 4
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: jquery-rails
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
68
|
+
version: '3.4'
|
125
69
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
70
|
+
name: net-smtp
|
127
71
|
requirement: !ruby/object:Gem::Requirement
|
128
72
|
requirements:
|
129
|
-
- - "
|
73
|
+
- - "~>"
|
130
74
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
75
|
+
version: 0.3.1
|
132
76
|
type: :runtime
|
133
77
|
prerelease: false
|
134
78
|
version_requirements: !ruby/object:Gem::Requirement
|
135
79
|
requirements:
|
136
|
-
- - "
|
80
|
+
- - "~>"
|
137
81
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
82
|
+
version: 0.3.1
|
139
83
|
- !ruby/object:Gem::Dependency
|
140
84
|
name: rails
|
141
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +98,16 @@ dependencies:
|
|
154
98
|
name: rails-i18n
|
155
99
|
requirement: !ruby/object:Gem::Requirement
|
156
100
|
requirements:
|
157
|
-
- - "
|
101
|
+
- - "~>"
|
158
102
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
103
|
+
version: '6.0'
|
160
104
|
type: :runtime
|
161
105
|
prerelease: false
|
162
106
|
version_requirements: !ruby/object:Gem::Requirement
|
163
107
|
requirements:
|
164
|
-
- - "
|
108
|
+
- - "~>"
|
165
109
|
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
110
|
+
version: '6.0'
|
167
111
|
- !ruby/object:Gem::Dependency
|
168
112
|
name: rake
|
169
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,20 +136,6 @@ dependencies:
|
|
192
136
|
- - ">="
|
193
137
|
- !ruby/object:Gem::Version
|
194
138
|
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: sass-rails
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :runtime
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
139
|
- !ruby/object:Gem::Dependency
|
210
140
|
name: scrypt
|
211
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,14 +170,14 @@ dependencies:
|
|
240
170
|
requirements:
|
241
171
|
- - "~>"
|
242
172
|
- !ruby/object:Gem::Version
|
243
|
-
version: '1.
|
173
|
+
version: '1.3'
|
244
174
|
type: :runtime
|
245
175
|
prerelease: false
|
246
176
|
version_requirements: !ruby/object:Gem::Requirement
|
247
177
|
requirements:
|
248
178
|
- - "~>"
|
249
179
|
- !ruby/object:Gem::Version
|
250
|
-
version: '1.
|
180
|
+
version: '1.3'
|
251
181
|
- !ruby/object:Gem::Dependency
|
252
182
|
name: sortable-table
|
253
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,20 +192,6 @@ dependencies:
|
|
262
192
|
- - ">="
|
263
193
|
- !ruby/object:Gem::Version
|
264
194
|
version: 0.1.1
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: turbolinks
|
267
|
-
requirement: !ruby/object:Gem::Requirement
|
268
|
-
requirements:
|
269
|
-
- - ">="
|
270
|
-
- !ruby/object:Gem::Version
|
271
|
-
version: '0'
|
272
|
-
type: :runtime
|
273
|
-
prerelease: false
|
274
|
-
version_requirements: !ruby/object:Gem::Requirement
|
275
|
-
requirements:
|
276
|
-
- - ">="
|
277
|
-
- !ruby/object:Gem::Version
|
278
|
-
version: '0'
|
279
195
|
- !ruby/object:Gem::Dependency
|
280
196
|
name: will_paginate
|
281
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -332,7 +248,6 @@ files:
|
|
332
248
|
- app/controllers/symphonia/application_controller.rb
|
333
249
|
- app/controllers/symphonia/filters_controller.rb
|
334
250
|
- app/controllers/symphonia/login_controller.rb
|
335
|
-
- app/controllers/symphonia/roles_controller.rb
|
336
251
|
- app/controllers/symphonia/user_sessions_controller.rb
|
337
252
|
- app/controllers/symphonia/users_controller.rb
|
338
253
|
- app/helpers/symphonia/application_helper.rb
|
@@ -344,8 +259,8 @@ files:
|
|
344
259
|
- app/models/symphonia/application_record.rb
|
345
260
|
- app/models/symphonia/email_preference.rb
|
346
261
|
- app/models/symphonia/preference.rb
|
347
|
-
- app/models/symphonia/role.rb
|
348
262
|
- app/models/symphonia/user.rb
|
263
|
+
- app/models/symphonia/user_ability.rb
|
349
264
|
- app/models/symphonia/user_session.rb
|
350
265
|
- app/views/base/_form.html.erb
|
351
266
|
- app/views/base/edit.html.erb
|
@@ -391,11 +306,6 @@ files:
|
|
391
306
|
- app/views/symphonia/notifier/user_change_to_active.text.erb
|
392
307
|
- app/views/symphonia/notifier/user_registered.html.erb
|
393
308
|
- app/views/symphonia/notifier/user_registered.text.erb
|
394
|
-
- app/views/symphonia/roles/_form.html.erb
|
395
|
-
- app/views/symphonia/roles/edit.html.erb
|
396
|
-
- app/views/symphonia/roles/index.html.erb
|
397
|
-
- app/views/symphonia/roles/new.html.erb
|
398
|
-
- app/views/symphonia/roles/show.html.erb
|
399
309
|
- app/views/symphonia/users/_form.html.erb
|
400
310
|
- app/views/symphonia/users/edit.html.erb
|
401
311
|
- app/views/symphonia/users/edit.js.erb
|
@@ -407,16 +317,13 @@ files:
|
|
407
317
|
- config/locales/en.yml
|
408
318
|
- config/routes.rb
|
409
319
|
- db/migrate/20130714140500_create_users.rb
|
410
|
-
- db/migrate/20130714140501_create_roles.rb
|
411
320
|
- db/migrate/20130714140502_create_preferences.rb
|
412
321
|
- db/migrate/20190706130409_add_external_id_to_users.rb
|
413
322
|
- db/migrate/20200428180001_add_uuid_to_users.rb
|
414
323
|
- db/migrate/20200428180008_add_avatar_to_users.rb
|
415
|
-
- db/migrate/20210509141420_roles_change_permissions_to_json.rb
|
416
|
-
- db/migrate/20210509180525_roles_change_permissions_to_native_json.rb
|
417
324
|
- db/seeds.rb
|
418
325
|
- lib/generators/symphonia/entity_controller/entity_controller_generator.rb
|
419
|
-
- lib/generators/symphonia/entity_controller/templates/controller.rb
|
326
|
+
- lib/generators/symphonia/entity_controller/templates/controller.rb.tt
|
420
327
|
- lib/generators/symphonia/query/query_generator.rb
|
421
328
|
- lib/generators/symphonia/setup/setup_generator.rb
|
422
329
|
- lib/generators/symphonia/setup/templates/Gemfile
|
@@ -448,7 +355,6 @@ files:
|
|
448
355
|
- lib/symphonia/model_filters/select_filter.rb
|
449
356
|
- lib/symphonia/model_filters/string_filter.rb
|
450
357
|
- lib/symphonia/object.rb
|
451
|
-
- lib/symphonia/permissions.rb
|
452
358
|
- lib/symphonia/query.rb
|
453
359
|
- lib/symphonia/query_columns.rb
|
454
360
|
- lib/symphonia/query_columns/attribute_column.rb
|
@@ -460,7 +366,6 @@ files:
|
|
460
366
|
- spec/controllers/base_controller_spec.rb
|
461
367
|
- spec/controllers/filters_controller_spec.rb
|
462
368
|
- spec/controllers/login_controller_spec.rb
|
463
|
-
- spec/controllers/roles_controller_spec.rb
|
464
369
|
- spec/controllers/users_controller_spec.rb
|
465
370
|
- spec/factories/factories.rb
|
466
371
|
- spec/helpers/symphonia/application_helper_spec.rb
|
@@ -472,12 +377,10 @@ files:
|
|
472
377
|
- spec/models/query/attribute_spec.rb
|
473
378
|
- spec/models/query/filters_spec.rb
|
474
379
|
- spec/models/query/symphonia_query_spec.rb
|
475
|
-
- spec/models/role_spec.rb
|
476
380
|
- spec/models/user_spec.rb
|
477
381
|
- spec/rails_helper.rb
|
478
382
|
- spec/requests/accounts_spec.rb
|
479
383
|
- spec/requests/login_spec.rb
|
480
|
-
- spec/requests/roles_spec.rb
|
481
384
|
- spec/requests/users_spec.rb
|
482
385
|
- spec/spec_helper.rb
|
483
386
|
- spec/support/query.rb
|
@@ -491,7 +394,8 @@ files:
|
|
491
394
|
homepage: https://github.com/luk4s
|
492
395
|
licenses:
|
493
396
|
- GPL-3.0
|
494
|
-
metadata:
|
397
|
+
metadata:
|
398
|
+
rubygems_mfa_required: 'true'
|
495
399
|
post_install_message: 'run: rails g symphonia:setup'
|
496
400
|
rdoc_options: []
|
497
401
|
require_paths:
|
@@ -507,41 +411,38 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
507
411
|
- !ruby/object:Gem::Version
|
508
412
|
version: '0'
|
509
413
|
requirements: []
|
510
|
-
rubygems_version: 3.
|
414
|
+
rubygems_version: 3.3.7
|
511
415
|
signing_key:
|
512
416
|
specification_version: 4
|
513
417
|
summary: My administration
|
514
418
|
test_files:
|
515
|
-
- spec/
|
516
|
-
- spec/
|
419
|
+
- spec/controllers/account_controller_spec.rb
|
420
|
+
- spec/controllers/admin_controller_spec.rb
|
421
|
+
- spec/controllers/base_controller_spec.rb
|
422
|
+
- spec/controllers/filters_controller_spec.rb
|
423
|
+
- spec/controllers/login_controller_spec.rb
|
424
|
+
- spec/controllers/users_controller_spec.rb
|
425
|
+
- spec/factories/factories.rb
|
426
|
+
- spec/helpers/symphonia/application_helper_spec.rb
|
427
|
+
- spec/helpers/symphonia/entity_decorator_spec.rb
|
428
|
+
- spec/helpers/symphonia/renderer_helper_spec.rb
|
429
|
+
- spec/libs/some_lib_spec.rb
|
517
430
|
- spec/mailers/previews/symphonia/notifier_preview.rb
|
518
|
-
- spec/
|
431
|
+
- spec/mailers/symphonia/notifier_spec.rb
|
519
432
|
- spec/models/query/attribute_spec.rb
|
520
|
-
- spec/models/query/symphonia_query_spec.rb
|
521
433
|
- spec/models/query/filters_spec.rb
|
434
|
+
- spec/models/query/symphonia_query_spec.rb
|
522
435
|
- spec/models/user_spec.rb
|
523
|
-
- spec/
|
524
|
-
- spec/requests/roles_spec.rb
|
525
|
-
- spec/requests/login_spec.rb
|
436
|
+
- spec/rails_helper.rb
|
526
437
|
- spec/requests/accounts_spec.rb
|
438
|
+
- spec/requests/login_spec.rb
|
527
439
|
- spec/requests/users_spec.rb
|
528
|
-
- spec/
|
529
|
-
- spec/support/
|
440
|
+
- spec/spec_helper.rb
|
441
|
+
- spec/support/query.rb
|
530
442
|
- spec/support/shared.rb
|
531
|
-
- spec/support/wait_for_ajax.rb
|
532
443
|
- spec/support/shared_controllers.rb
|
533
444
|
- spec/support/shared_requests.rb
|
534
|
-
- spec/support/
|
535
|
-
- spec/
|
536
|
-
- spec/
|
537
|
-
- spec/controllers/login_controller_spec.rb
|
538
|
-
- spec/controllers/users_controller_spec.rb
|
539
|
-
- spec/controllers/filters_controller_spec.rb
|
540
|
-
- spec/controllers/admin_controller_spec.rb
|
541
|
-
- spec/controllers/account_controller_spec.rb
|
542
|
-
- spec/controllers/base_controller_spec.rb
|
445
|
+
- spec/support/stub_users.rb
|
446
|
+
- spec/support/wait_for_ajax.rb
|
447
|
+
- spec/version_spec.rb
|
543
448
|
- spec/views/filters/options.html.erb_spec.rb
|
544
|
-
- spec/rails_helper.rb
|
545
|
-
- spec/helpers/symphonia/application_helper_spec.rb
|
546
|
-
- spec/helpers/symphonia/renderer_helper_spec.rb
|
547
|
-
- spec/helpers/symphonia/entity_decorator_spec.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class RolesController < ApplicationController
|
3
|
-
|
4
|
-
include BaseController
|
5
|
-
|
6
|
-
def model
|
7
|
-
Role
|
8
|
-
end
|
9
|
-
|
10
|
-
def safe_attributes
|
11
|
-
[:name, :description, permissions: []]
|
12
|
-
end
|
13
|
-
# helper Symphonia::RendererHelper
|
14
|
-
#
|
15
|
-
# before_action :authorize
|
16
|
-
before_action :load_permissions, only: [:new, :edit, :update, :create]
|
17
|
-
|
18
|
-
def create
|
19
|
-
@entity = @role = Role.new(entity_params)
|
20
|
-
@role.permissions = Symphonia::Permissions.find_all(params[:permissions]).map(&:name)
|
21
|
-
super
|
22
|
-
end
|
23
|
-
|
24
|
-
def update
|
25
|
-
@entity = @role = Role.find(params[:id])
|
26
|
-
@role.permissions = Symphonia::Permissions.find_all(params[:permissions]).map(&:name)
|
27
|
-
super
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def load_permissions
|
34
|
-
@permissions = Symphonia::Permissions.all
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class Role < ApplicationRecord
|
3
|
-
self.table_name = 'roles'
|
4
|
-
|
5
|
-
include ModelAttributes
|
6
|
-
|
7
|
-
register_query do
|
8
|
-
add_attribute :name, :link
|
9
|
-
end
|
10
|
-
|
11
|
-
validates :name, presence: true
|
12
|
-
|
13
|
-
serialize :permissions, Array
|
14
|
-
|
15
|
-
scope :active, -> {}
|
16
|
-
scope :sorted, -> { order(:name) }
|
17
|
-
|
18
|
-
# after_save :expire_cache
|
19
|
-
|
20
|
-
def allowed_to?(permission)
|
21
|
-
Rails.cache.fetch([self, permission]) do
|
22
|
-
!allowed_permissions.detect { |i| permission.to_sym == i.name }.nil?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def authorize?(controller, action)
|
27
|
-
Rails.cache.fetch([self, controller, action]) do
|
28
|
-
!allowed_permissions.detect { |p| p.allowed?(controller, action) }.nil?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def allowed_permissions
|
33
|
-
return @allowed_permissions if @allowed_permissions
|
34
|
-
|
35
|
-
@allowed_permissions = permissions.collect do |i|
|
36
|
-
i.is_a?(Symphonia::Permissions::Permission) ? i : Symphonia::Permissions.get(i.to_sym)
|
37
|
-
end.compact
|
38
|
-
|
39
|
-
@allowed_permissions
|
40
|
-
end
|
41
|
-
|
42
|
-
def permission_names
|
43
|
-
permissions #.map(&:name)
|
44
|
-
end
|
45
|
-
|
46
|
-
# private
|
47
|
-
#
|
48
|
-
# def expire_cache
|
49
|
-
# Rails.cache.delete_matched("role_#{self.id}_*")
|
50
|
-
# Rails.cache.delete_matched('user_allowed_to*')
|
51
|
-
# end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<%= symphonia_form_for(@role) do |f| %>
|
2
|
-
|
3
|
-
<%= f.text_field :name, required: true %>
|
4
|
-
<%= f.text_area :description, size: '50x5' %>
|
5
|
-
|
6
|
-
<fieldset>
|
7
|
-
<legend>
|
8
|
-
<%= link_to(fa_icon('check lg'), 'javascript:void(0)', onclick: "$(this).closest('fieldset').find('input:checkbox').trigger('click')", class: "pull-right") -%>
|
9
|
-
<%= content_tag(:h4, Symphonia::Role.human_attribute_name(:permissions)) %>
|
10
|
-
</legend>
|
11
|
-
<div class="card-body row">
|
12
|
-
<% @permissions.each do |perm| %>
|
13
|
-
<div class="col-sm-3">
|
14
|
-
<label class="checkbox-inline">
|
15
|
-
<%= check_box_tag('permissions[]', perm, @role.permission_names.include?(perm.name), id: perm, class: '') %>
|
16
|
-
<%= t(perm.name, :scope => [:permissions], :default => perm.to_s.humanize) %>
|
17
|
-
</label>
|
18
|
-
</div>
|
19
|
-
<% end %>
|
20
|
-
</div>
|
21
|
-
</fieldset>
|
22
|
-
|
23
|
-
<p class="buttons">
|
24
|
-
<%= f.primary %>
|
25
|
-
</p>
|
26
|
-
<% end %>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<%= title(@role.name, back: true) %>
|
2
|
-
|
3
|
-
<div class="formatted-text">
|
4
|
-
<%= format_text @role.description %>
|
5
|
-
</div>
|
6
|
-
|
7
|
-
<ul class="permissions fa-ul">
|
8
|
-
<% @role.permissions.each do |perm| %>
|
9
|
-
<li><%= fa_icon "li check", text: t("permissions.#{perm}", default: perm.to_s.humanize) %></li>
|
10
|
-
<% end %>
|
11
|
-
</ul>
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateRoles < ActiveRecord::Migration[6.1]
|
2
|
-
|
3
|
-
def up
|
4
|
-
create_table :roles do |t|
|
5
|
-
t.string :name, null: false
|
6
|
-
t.text :description, null: true
|
7
|
-
|
8
|
-
t.text :permissions
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def down
|
15
|
-
drop_table :roles
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class RolesChangePermissionsToJson < ActiveRecord::Migration[6.1]
|
2
|
-
|
3
|
-
def up
|
4
|
-
say_with_time "Convert 'roles.permissions' YAML to JSON" do
|
5
|
-
i = 0
|
6
|
-
Symphonia::Role.where.not(permissions: nil).each do |role|
|
7
|
-
yaml = product.read_attribute_before_type_cast :permissions
|
8
|
-
next unless yaml.start_with? "---"
|
9
|
-
|
10
|
-
role.update_columns permissions: YAML.safe_load(yaml)
|
11
|
-
i += 1
|
12
|
-
end
|
13
|
-
|
14
|
-
i
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
module Symphonia
|
3
|
-
module Permissions
|
4
|
-
@@mapper = []
|
5
|
-
@@used_names = []
|
6
|
-
mattr_accessor :mapper, :used_names
|
7
|
-
class PermissionMissingError < RuntimeError; end
|
8
|
-
class << self
|
9
|
-
|
10
|
-
def map(&block)
|
11
|
-
if block_given?
|
12
|
-
yield self
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def register(name, options={})
|
17
|
-
return if @@used_names.include?(name)
|
18
|
-
|
19
|
-
p = Permission.new(name, options)
|
20
|
-
@@used_names << p.name.to_s
|
21
|
-
mapper << p
|
22
|
-
|
23
|
-
p
|
24
|
-
end
|
25
|
-
|
26
|
-
def update(name)
|
27
|
-
self.get(name) || raise(PermissionMissingError)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns the permission of given name or nil if it wasn't found
|
31
|
-
# Argument should be a symbol
|
32
|
-
def get(name)
|
33
|
-
mapper.detect{|i| i.name == name}
|
34
|
-
end
|
35
|
-
|
36
|
-
def all
|
37
|
-
mapper
|
38
|
-
end
|
39
|
-
|
40
|
-
def find_all(permission_names=[])
|
41
|
-
ps = used_names & Array(permission_names).compact
|
42
|
-
ps.collect{|m| get(m.to_sym)}
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
class Permission
|
48
|
-
attr_reader :name
|
49
|
-
# actions => [:controller_name => [:action, :action, :action]]
|
50
|
-
def initialize(name, options={})
|
51
|
-
@name = name
|
52
|
-
@perms = Hash.new { |hash, key| hash[key] = Array.new }
|
53
|
-
end
|
54
|
-
alias_method :id, :name
|
55
|
-
|
56
|
-
def to_s
|
57
|
-
@name.to_s
|
58
|
-
end
|
59
|
-
|
60
|
-
def allowed?(controller, action)
|
61
|
-
Array(@perms[controller.to_sym]).include?(action.to_sym)
|
62
|
-
end
|
63
|
-
|
64
|
-
def add(controller, actions=[])
|
65
|
-
@perms[controller] += actions
|
66
|
-
end
|
67
|
-
|
68
|
-
def remove_actions(controller, actions=[])
|
69
|
-
@perms[controller] -= actions
|
70
|
-
end
|
71
|
-
|
72
|
-
def remove_controller(controller)
|
73
|
-
@perms.delete(controller)
|
74
|
-
end
|
75
|
-
|
76
|
-
def controllers
|
77
|
-
@controllers ||= @perms.keys
|
78
|
-
end
|
79
|
-
|
80
|
-
def allow_action?(controller, action)
|
81
|
-
controller = controller.to_sym
|
82
|
-
action = action.to_sym
|
83
|
-
|
84
|
-
if self.controllers.include?(controller)
|
85
|
-
return @perms[controller].include?(action)
|
86
|
-
else
|
87
|
-
return false
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# require_relative '../spec_helper.rb'
|
2
|
-
|
3
|
-
module Symphonia
|
4
|
-
describe RolesController, type: 'controller', logged: :admin do
|
5
|
-
routes { Symphonia::Engine.routes }
|
6
|
-
subject { Symphonia::Role }
|
7
|
-
|
8
|
-
include_examples 'a controller actions', :role
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
data/spec/models/role_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
RSpec.describe Symphonia::Role do
|
2
|
-
subject { FactoryBot.create :role, permissions: [:view_users] }
|
3
|
-
|
4
|
-
describe "#allowed_to?" do
|
5
|
-
it "false" do
|
6
|
-
expect(subject.allowed_to?( :non_exists)).to eq false
|
7
|
-
end
|
8
|
-
|
9
|
-
it "true" do
|
10
|
-
expect(subject.allowed_to?(:view_users)).to eq true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|