Skip to content

Commit

Permalink
Add translations and skip first login if only center verification is …
Browse files Browse the repository at this point in the history
…configured
  • Loading branch information
fblupi committed Dec 4, 2023
1 parent ce70e15 commit c32cc88
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
module Centers
module Devise
module OmniauthRegistrationsControllerOverride
extend ActiveSupport::Concern

included do
alias_method :original_first_login_and_not_authorized?, :first_login_and_not_authorized?

def first_login_and_not_authorized?(user)
original_first_login_and_not_authorized?(user) && Decidim::Verifications.workflows.any? { |manifest| manifest.name != "center" }
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
module Centers
module Devise
module SessionsControllerOverride
extend ActiveSupport::Concern

included do
alias_method :original_first_login_and_not_authorized?, :first_login_and_not_authorized?

def first_login_and_not_authorized?(user)
original_first_login_and_not_authorized?(user) && current_organization.available_authorizations.excluding("center").any?
end
end
end
end
end
end
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ignore_missing:

ignore_unused:
- decidim.centers.admin_log.*
- decidim.authorization_handlers.*
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
en:
decidim:
authorization_handlers:
center:
explanation: Get verified with the center of the user
name: Center
centers:
actions:
confirm_destroy: Are you sure you want to delete this center?
Expand Down
7 changes: 7 additions & 0 deletions lib/decidim/centers/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class Engine < ::Rails::Engine
Decidim::User.include(Decidim::Centers::UserOverride)
end

initializer "decidim_centers.overrides", after: "decidim.action_controller" do
config.to_prepare do
Decidim::Devise::SessionsController.include(Decidim::Centers::Devise::SessionsControllerOverride)
Decidim::Devise::OmniauthRegistrationsController.include(Decidim::Centers::Devise::OmniauthRegistrationsControllerOverride)
end
end

initializer "decidim_centers.sync" do
ActiveSupport::Notifications.subscribe "decidim.centers.user.updated" do |_name, data|
Decidim::Centers::SyncCenterUserJob.perform_now(data)
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"/app/commands/decidim/create_omniauth_registration.rb" => "586139f98ded0645eb83e480ef5dd6bd",
"/app/commands/decidim/create_registration.rb" => "8bf3456d42c21036d08ccafe16e9105a",
"/app/commands/decidim/update_account.rb" => "29d81617f5bf1af310d2777a916b4d8b",
"/app/controllers/decidim/devise/omniauth_registrations_controller.rb" => "05bc35af4b5f855736f14efbd22e439b",
"/app/controllers/decidim/devise/sessions_controller.rb" => "235cbe9844cdd39f65c72d3dc87f5f23",
"/app/forms/decidim/account_form.rb" => "73a8150ed1620d515a1c96f680e98ec0",
"/app/forms/decidim/omniauth_registration_form.rb" => "ee09e2b5675c9d1cb4dc955dded05393",
"/app/forms/decidim/registration_form.rb" => "32b55eb5a1742b6b8ed7bbb4c7643dc0",
Expand Down

0 comments on commit c32cc88

Please sign in to comment.