decidim-centers 0.1.1

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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-AGPLv3.txt +661 -0
  3. data/README.md +144 -0
  4. data/Rakefile +40 -0
  5. data/app/commands/concerns/decidim/centers/create_omniauth_registration_override.rb +42 -0
  6. data/app/commands/concerns/decidim/centers/create_registration_override.rb +32 -0
  7. data/app/commands/concerns/decidim/centers/publish_center_update_event.rb +20 -0
  8. data/app/commands/concerns/decidim/centers/update_account_override.rb +35 -0
  9. data/app/commands/decidim/centers/admin/create_center.rb +50 -0
  10. data/app/commands/decidim/centers/admin/destroy_center.rb +47 -0
  11. data/app/commands/decidim/centers/admin/update_center.rb +47 -0
  12. data/app/commands/decidim/centers/create_or_update_center_user.rb +44 -0
  13. data/app/commands/decidim/centers/create_or_update_scope_user.rb +44 -0
  14. data/app/controllers/concerns/decidim/centers/admin/needs_select2_snippets.rb +35 -0
  15. data/app/controllers/concerns/decidim/centers/devise/omniauth_registrations_controller_override.rb +21 -0
  16. data/app/controllers/concerns/decidim/centers/devise/sessions_controller_override.rb +21 -0
  17. data/app/controllers/concerns/decidim/centers/with_scopes_helper.rb +15 -0
  18. data/app/controllers/decidim/centers/admin/application_controller.rb +24 -0
  19. data/app/controllers/decidim/centers/admin/centers_controller.rb +106 -0
  20. data/app/controllers/decidim/centers/admin/scopes_controller.rb +40 -0
  21. data/app/forms/concerns/decidim/centers/account_form_override.rb +36 -0
  22. data/app/forms/decidim/centers/admin/center_form.rb +18 -0
  23. data/app/forms/decidim/centers/verifications/center.rb +33 -0
  24. data/app/helpers/decidim/centers/application_helper.rb +17 -0
  25. data/app/jobs/decidim/centers/auto_verification_job.rb +46 -0
  26. data/app/jobs/decidim/centers/sync_center_user_job.rb +29 -0
  27. data/app/jobs/decidim/centers/sync_scope_user_job.rb +29 -0
  28. data/app/models/concerns/decidim/centers/unique_by_user.rb +19 -0
  29. data/app/models/concerns/decidim/centers/user_override.rb +33 -0
  30. data/app/models/decidim/centers/application_record.rb +10 -0
  31. data/app/models/decidim/centers/center.rb +25 -0
  32. data/app/models/decidim/centers/center_user.rb +28 -0
  33. data/app/models/decidim/centers/scope_user.rb +28 -0
  34. data/app/overrides/decidim/account/show/centers.html.erb.deface +3 -0
  35. data/app/overrides/decidim/devise/omniauth_registrations/new/centers.html.erb.deface +3 -0
  36. data/app/overrides/decidim/devise/registrations/new/centers.html.erb.deface +3 -0
  37. data/app/packs/entrypoints/decidim_centers_admin_select2.js +2 -0
  38. data/app/packs/src/decidim/centers/admin/resource_permissions_select2.js +68 -0
  39. data/app/packs/stylesheets/vendor/select2_foundation_theme.scss +345 -0
  40. data/app/permissions/decidim/centers/admin/permissions.rb +19 -0
  41. data/app/presenters/decidim/centers/admin_log/center_presenter.rb +29 -0
  42. data/app/views/decidim/centers/_profile_form.html.erb +5 -0
  43. data/app/views/decidim/centers/_registration_form.html.erb +11 -0
  44. data/app/views/decidim/centers/admin/centers/_form.html.erb +10 -0
  45. data/app/views/decidim/centers/admin/centers/edit.html.erb +8 -0
  46. data/app/views/decidim/centers/admin/centers/index.html.erb +45 -0
  47. data/app/views/decidim/centers/admin/centers/new.html.erb +8 -0
  48. data/config/assets.rb +8 -0
  49. data/config/i18n-tasks.yml +11 -0
  50. data/config/locales/en.yml +51 -0
  51. data/db/migrate/20231129114029_create_decidim_centers_centers.rb +13 -0
  52. data/db/migrate/20231130125631_create_decidim_centers_center_users.rb +12 -0
  53. data/db/migrate/20231205153627_create_decidim_centers_scope_users.rb +12 -0
  54. data/lib/decidim/centers/admin.rb +10 -0
  55. data/lib/decidim/centers/admin_engine.rb +40 -0
  56. data/lib/decidim/centers/engine.rb +79 -0
  57. data/lib/decidim/centers/test/factories.rb +25 -0
  58. data/lib/decidim/centers/test/shared_contexts.rb +22 -0
  59. data/lib/decidim/centers/verifications/center_action_authorizer.rb +49 -0
  60. data/lib/decidim/centers/verifications.rb +11 -0
  61. data/lib/decidim/centers/version.rb +10 -0
  62. data/lib/decidim/centers.rb +19 -0
  63. metadata +138 -0
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Decidim::Centers
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/decidim-centers.svg)](https://badge.fury.io/rb/decidim-centers)
4
+ [![[CI] Lint](https://github.com/Platoniq/decidim-module-centers/actions/workflows/lint.yml/badge.svg)](https://github.com/Platoniq/decidim-module-centers/actions/workflows/lint.yml)
5
+ [![[CI] Test](https://github.com/Platoniq/decidim-module-centers/actions/workflows/test.yml/badge.svg)](https://github.com/Platoniq/decidim-module-centers/actions/workflows/test.yml)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/6b1b656b229f9731a64b/maintainability)](https://codeclimate.com/github/Platoniq/decidim-module-centers/maintainability)
7
+ [![codecov](https://codecov.io/gh/Platoniq/decidim-module-centers/branch/main/graph/badge.svg)](https://codecov.io/gh/Platoniq/decidim-module-centers)
8
+
9
+ Manage your centers and scopes so the users can be authorized over them. As an admin you will be able
10
+ to create centers and scopes (we use the model Decidim currently provides).
11
+
12
+ When a user signs up in the platform two new fields will appear in the registration form.
13
+
14
+ - **Center**: Where the user works. For example: "University of Granada"
15
+ - **Scope**: The work scope in which the user works. For example: "Computer Science"
16
+
17
+ ![Registration form](examples/registration.png)
18
+
19
+ Users can change the values anytime they want from the profile page.
20
+
21
+ When they create the account or update their values, a `center` authorization will be created or updated
22
+ with the value of the center and scope the user has selected.
23
+
24
+ As an admin you will be able to configure the permissions of a component restricting the access to
25
+ specific centers and scopes. When you select multiple centers or scopes they work as "or". When you specify
26
+ both the center and the scope it will work as an "and" between them.
27
+
28
+ ![Permissions in the admin page](examples/permissions.png)
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem "decidim-centers", "~> 0.1.0"
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ ```bash
41
+ bundle
42
+ ```
43
+
44
+ Install (and run) migrations:
45
+
46
+ ```bash
47
+ bundle exec rails decidim_centers:install:migrations
48
+ bundle exec rails db:migrate
49
+ ```
50
+
51
+ Depending on your Decidim version, choose the corresponding version to ensure compatibility:
52
+
53
+ | Version | Compatible decidim versions |
54
+ |---------|-----------------------------|
55
+ | 0.1.x | v0.27.x |
56
+
57
+ ## Configuration
58
+
59
+ You can customize your installation using the environment variables below:
60
+
61
+ | ENV | Description | Default | Example |
62
+ |--------------------------------------|-----------------------------------------------------------|---------|--------------|
63
+ | DECIDIM_CENTERS_SCOPES_ENABLED | Use scopes to categorize users too along with the centers | true | false |
64
+
65
+ > **IMPORTANT**: Remember to activate the verification method `center` in the
66
+ > Decidim `/system` admin page for your organization.
67
+
68
+ ## Contributing
69
+
70
+ See [Decidim](https://github.com/decidim/decidim).
71
+
72
+ ### Developing
73
+
74
+ To start contributing to this project, first:
75
+
76
+ - Install the basic dependencies (such as Ruby and PostgreSQL)
77
+ - Clone this repository
78
+
79
+ Decidim's main repository also provides a Docker configuration file if you
80
+ prefer to use Docker instead of installing the dependencies locally on your
81
+ machine.
82
+
83
+ You can create the development app by running the following commands after
84
+ cloning this project:
85
+
86
+ ```bash
87
+ bundle
88
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake development_app
89
+ ```
90
+
91
+ Note that the database user has to have rights to create and drop a database in
92
+ order to create the dummy test app database.
93
+
94
+ Then to test how the module works in Decidim, start the development server:
95
+
96
+ ```bash
97
+ cd development_app
98
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rails s
99
+ ```
100
+
101
+ In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
102
+ [rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
103
+ can add the environment variables to the root directory of the project in a file
104
+ named `.rbenv-vars`. If these are defined for the environment, you can omit
105
+ defining these in the commands shown above.
106
+
107
+ #### Code Styling
108
+
109
+ Please follow the code styling defined by the different linters that ensure we
110
+ are all talking with the same language collaborating on the same project. This
111
+ project is set to follow the same rules that Decidim itself follows.
112
+
113
+ [Rubocop](https://rubocop.readthedocs.io/) linter is used for the Ruby language.
114
+
115
+ You can run the code styling checks by running the following commands from the
116
+ console:
117
+
118
+ ```bash
119
+ bundle exec rubocop
120
+ ```
121
+
122
+ To ease up following the style guide, you should install the plugin to your
123
+ favorite editor, such as:
124
+
125
+ - Atom - [linter-rubocop](https://atom.io/packages/linter-rubocop)
126
+ - Sublime Text - [Sublime RuboCop](https://github.com/pderichs/sublime_rubocop)
127
+ - Visual Studio Code - [Rubocop for Visual Studio Code](https://github.com/misogi/vscode-ruby-rubocop)
128
+
129
+ ### Testing
130
+
131
+ To run the tests run the following in the gem development path:
132
+
133
+ ```bash
134
+ bundle
135
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake test_app
136
+ DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rspec
137
+ ```
138
+
139
+ Note that the database user has to have rights to create and drop a database in
140
+ order to create the dummy test app database.
141
+
142
+ ## License
143
+
144
+ This engine is distributed under the [GNU AFFERO GENERAL PUBLIC LICENSE](LICENSE-AGPLv3.txt).
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/dev/common_rake"
4
+
5
+ def install_module(path)
6
+ Dir.chdir(path) do
7
+ system("bundle exec rake decidim_centers:install:migrations")
8
+ system("bundle exec rake db:migrate")
9
+ end
10
+ end
11
+
12
+ def seed_db(path)
13
+ Dir.chdir(path) do
14
+ system("bundle exec rake db:seed")
15
+ end
16
+ end
17
+
18
+ desc "Generates a dummy app for testing"
19
+ task test_app: "decidim:generate_external_test_app" do
20
+ ENV["RAILS_ENV"] = "test"
21
+ install_module("spec/decidim_dummy_app")
22
+ end
23
+
24
+ desc "Generates a development app."
25
+ task :development_app do
26
+ Bundler.with_original_env do
27
+ generate_decidim_app(
28
+ "development_app",
29
+ "--app_name",
30
+ "#{base_app_name}_development_app",
31
+ "--path",
32
+ "..",
33
+ "--recreate_db",
34
+ "--demo"
35
+ )
36
+ end
37
+
38
+ install_module("development_app")
39
+ seed_db("development_app")
40
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module CreateOmniauthRegistrationOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ include PublishCenterUpdateEvent
11
+
12
+ def call
13
+ verify_oauth_signature!
14
+
15
+ begin
16
+ if existing_identity
17
+ # :nocov:
18
+ user = existing_identity.user
19
+ verify_user_confirmed(user)
20
+
21
+ return broadcast(:ok, user)
22
+ # :nocov:
23
+ end
24
+ return broadcast(:invalid) if form.invalid?
25
+
26
+ transaction do
27
+ create_or_find_user
28
+ @identity = create_identity
29
+ end
30
+ trigger_omniauth_registration
31
+ publish_center_update_event
32
+
33
+ broadcast(:ok, @user)
34
+ rescue ActiveRecord::RecordInvalid => e
35
+ # :nocov:
36
+ broadcast(:error, e.record)
37
+ # :nocov:
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module CreateRegistrationOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ include PublishCenterUpdateEvent
11
+
12
+ def call
13
+ if form.invalid?
14
+ # :nocov:
15
+ user = User.has_pending_invitations?(form.current_organization.id, form.email)
16
+ user.invite!(user.invited_by) if user
17
+ return broadcast(:invalid)
18
+ # :nocov:
19
+ end
20
+
21
+ create_user
22
+ publish_center_update_event
23
+
24
+ broadcast(:ok, @user)
25
+ rescue ActiveRecord::RecordInvalid
26
+ # :nocov:
27
+ broadcast(:invalid)
28
+ # :nocov:
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module PublishCenterUpdateEvent
8
+ extend ActiveSupport::Concern
9
+
10
+ def publish_center_update_event
11
+ ActiveSupport::Notifications.publish(
12
+ "decidim.centers.user.updated",
13
+ user_id: @user.id,
14
+ center_id: @form.center_id,
15
+ scope_id: @form.scope_id
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module UpdateAccountOverride
8
+ extend ActiveSupport::Concern
9
+
10
+ include PublishCenterUpdateEvent
11
+
12
+ def call
13
+ return broadcast(:invalid) unless @form.valid?
14
+
15
+ update_personal_data
16
+ update_avatar
17
+ update_password
18
+
19
+ if @user.valid?
20
+ @user.save!
21
+ notify_followers
22
+ publish_center_update_event
23
+ broadcast(:ok, @user.unconfirmed_email.present?)
24
+ else
25
+ # :nocov:
26
+ [:avatar, :password, :password_confirmation].each do |key|
27
+ @form.errors.add key, @user.errors[key] if @user.errors.has_key? key
28
+ end
29
+ broadcast(:invalid)
30
+ # :nocov:
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ module Admin
6
+ # This command is executed when the user creates a Center from the admin
7
+ # panel.
8
+ class CreateCenter < Decidim::Command
9
+ # Initializes a CreateCenter Command.
10
+ #
11
+ # form - The form from which to get the data.
12
+ # current_user - The user who performs the action.
13
+ def initialize(form, current_user)
14
+ @form = form
15
+ @current_user = current_user
16
+ end
17
+
18
+ # Creates the center if valid.
19
+ #
20
+ # Broadcasts :ok if successful, :invalid otherwise.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ transaction do
25
+ create_center!
26
+ end
27
+
28
+ broadcast(:ok, @center)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :form, :current_user
34
+
35
+ def create_center!
36
+ attributes = {
37
+ organization: form.current_organization,
38
+ title: form.title
39
+ }
40
+
41
+ @center = Decidim.traceability.create!(
42
+ Center,
43
+ current_user,
44
+ attributes
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ module Admin
6
+ # This command is executed when the user destroys a Center from the admin
7
+ # panel.
8
+ class DestroyCenter < Decidim::Command
9
+ # Initializes a DestroyCenter Command.
10
+ #
11
+ # center - The current instance of the center to be destroyed.
12
+ # current_user - The user who performs the action.
13
+ def initialize(center, current_user)
14
+ @center = center
15
+ @current_user = current_user
16
+ end
17
+
18
+ # Destroys the center if valid.
19
+ #
20
+ # Broadcasts :ok if successful, :invalid otherwise.
21
+ def call
22
+ transaction do
23
+ destroy_center!
24
+ end
25
+
26
+ broadcast(:ok, center)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :center, :current_user
32
+
33
+ def destroy_center!
34
+ attributes = {
35
+ deleted_at: Time.current
36
+ }
37
+
38
+ Decidim.traceability.update!(
39
+ center,
40
+ current_user,
41
+ attributes
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ module Admin
6
+ # This command is executed when the user changes a Center from the admin
7
+ # panel.
8
+ class UpdateCenter < Decidim::Command
9
+ # Initializes a UpdateCenter Command.
10
+ #
11
+ # form - The form from which to get the data.
12
+ # center - The current instance of the center to be updated.
13
+ # current_user - The user who performs the action.
14
+ def initialize(form, center, current_user)
15
+ @form = form
16
+ @center = center
17
+ @current_user = current_user
18
+ end
19
+
20
+ # Updates the center if valid.
21
+ #
22
+ # Broadcasts :ok if successful, :invalid otherwise.
23
+ def call
24
+ return broadcast(:invalid) if form.invalid?
25
+
26
+ transaction do
27
+ update_center!
28
+ end
29
+
30
+ broadcast(:ok, center)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :form, :center, :current_user
36
+
37
+ def update_center!
38
+ Decidim.traceability.update!(
39
+ center,
40
+ current_user,
41
+ title: form.title
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ # This command is executed when a new relationship between user
6
+ # and center is created
7
+ class CreateOrUpdateCenterUser < Decidim::Command
8
+ # Initializes a CreateOrUpdateCenterUser Command.
9
+ #
10
+ # center - The center to be related with the user.
11
+ # user - The user to be related with the center.
12
+ def initialize(center, user)
13
+ @center = center
14
+ @user = user
15
+ end
16
+
17
+ # Creates or update the center user if valid.
18
+ #
19
+ # Broadcasts :ok if successful, :invalid otherwise.
20
+ def call
21
+ transaction do
22
+ delete_existing_center_user!
23
+ create_center_user!
24
+ rescue ActiveRecord::RecordInvalid
25
+ broadcast(:invalid)
26
+ end
27
+
28
+ broadcast(:ok, @center_user)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :center, :user
34
+
35
+ def delete_existing_center_user!
36
+ CenterUser.where(user: user).destroy_all
37
+ end
38
+
39
+ def create_center_user!
40
+ @center_user = CenterUser.create!(center: center, user: user)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ # This command is executed when a new relationship between user
6
+ # and scope is created
7
+ class CreateOrUpdateScopeUser < Decidim::Command
8
+ # Initializes a CreateOrUpdateScopeUser Command.
9
+ #
10
+ # scope - The scope to be related with the user.
11
+ # user - The user to be related with the scope.
12
+ def initialize(scope, user)
13
+ @scope = scope
14
+ @user = user
15
+ end
16
+
17
+ # Creates or update the scope user if valid.
18
+ #
19
+ # Broadcasts :ok if successful, :invalid otherwise.
20
+ def call
21
+ transaction do
22
+ delete_existing_scope_user!
23
+ create_scope_user!
24
+ rescue ActiveRecord::RecordInvalid
25
+ broadcast(:invalid)
26
+ end
27
+
28
+ broadcast(:ok, @scope_user)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :scope, :user
34
+
35
+ def delete_existing_scope_user!
36
+ ScopeUser.where(user: user).destroy_all
37
+ end
38
+
39
+ def create_scope_user!
40
+ @scope_user = ScopeUser.create!(scope: scope, user: user)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module Admin
8
+ module NeedsSelect2Snippets
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ helper_method :snippets
13
+ end
14
+
15
+ def snippets
16
+ @snippets ||= Decidim::Snippets.new
17
+
18
+ unless @snippets.any?(:select2)
19
+ @snippets.add(:select2, ActionController::Base.helpers.stylesheet_link_tag("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css"))
20
+ @snippets.add(:select2, ActionController::Base.helpers.javascript_include_tag("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"))
21
+ @snippets.add(:head, @snippets.for(:select2))
22
+ end
23
+
24
+ unless @snippets.any?(:centers_admin_select2)
25
+ @snippets.add(:centers_admin_select2, ActionController::Base.helpers.javascript_pack_tag("decidim_centers_admin_select2"))
26
+ @snippets.add(:centers_admin_select2, ActionController::Base.helpers.stylesheet_pack_tag("decidim_centers_admin_select2"))
27
+ @snippets.add(:head, @snippets.for(:centers_admin_select2))
28
+ end
29
+
30
+ @snippets
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module Devise
8
+ module OmniauthRegistrationsControllerOverride
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ alias_method :original_first_login_and_not_authorized?, :first_login_and_not_authorized?
13
+
14
+ def first_login_and_not_authorized?(user)
15
+ original_first_login_and_not_authorized?(user) && Decidim::Verifications.workflows.any? { |manifest| manifest.name != "center" }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module Devise
8
+ module SessionsControllerOverride
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ alias_method :original_first_login_and_not_authorized?, :first_login_and_not_authorized?
13
+
14
+ def first_login_and_not_authorized?(user)
15
+ original_first_login_and_not_authorized?(user) && current_organization.available_authorizations.excluding("center").any?
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Centers
7
+ module WithScopesHelper
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ helper Decidim::ScopesHelper
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Centers
5
+ module Admin
6
+ # This controller is the abstract class from which all other controllers of
7
+ # this engine inherit.
8
+ #
9
+ # Note that it inherits from `Decidim::Admin::ApplicationController`, which
10
+ # override its layout and provide all kinds of useful methods.
11
+ class ApplicationController < Decidim::Admin::ApplicationController
12
+ register_permissions(::Decidim::Centers::Admin::ApplicationController,
13
+ ::Decidim::Centers::Admin::Permissions,
14
+ ::Decidim::Admin::Permissions)
15
+
16
+ private
17
+
18
+ def permission_class_chain
19
+ ::Decidim.permissions_registry.chain_for(::Decidim::Centers::Admin::ApplicationController)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end