-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Odoo users as action delegator method
- Loading branch information
Showing
12 changed files
with
196 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...action_delegator/verifications/delegations_verifier/authorizations_controller_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module ActionDelegator | ||
module Verifications | ||
module DelegationsVerifier | ||
module AuthorizationsControllerOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def new | ||
@authorization.destroy! if authorization&.persisted? && !authorization&.granted? | ||
|
||
enforce_permission_to :create, :authorization, authorization: authorization | ||
@form = form(verifier_form).instance(setting: setting) | ||
participant = @form&.participant | ||
|
||
return unless ActionDelegator.authorize_on_login && setting&.verify_with_email? | ||
|
||
Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do | ||
on(:ok) do | ||
grant_and_redirect(participant) | ||
end | ||
on(:invalid) do | ||
render :new | ||
end | ||
end | ||
end | ||
|
||
def create | ||
enforce_permission_to :create, :authorization, authorization: authorization | ||
|
||
@form = form(verifier_form).from_params(form_params, setting: setting) | ||
participant = @form&.participant | ||
|
||
Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do | ||
on(:ok) do | ||
if setting.phone_required? | ||
flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.sms") | ||
authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name) | ||
redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url) | ||
else | ||
grant_and_redirect(participant) | ||
end | ||
end | ||
on(:invalid) do | ||
flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.sms") | ||
render :new | ||
end | ||
end | ||
end | ||
|
||
def grant_and_redirect(participant) | ||
authorization.grant! | ||
if participant | ||
participant.update!(decidim_user: authorization.user) | ||
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms") | ||
end | ||
redirect | ||
end | ||
|
||
def verifier_form | ||
setting&.odoo_required? ? Decidim::Odoo::Verifications::OdooMember : DelegationsVerifierForm | ||
end | ||
|
||
def form_params | ||
params.merge(user: current_user) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
app/forms/concerns/decidim/odoo/verifications/odoo_member_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Odoo | ||
module Verifications | ||
module OdooMemberOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def participant | ||
nil | ||
end | ||
|
||
# currently, we rely on the last setting. | ||
# This could be improved by allowing the user to select the setting (or related phone). | ||
def setting | ||
@setting ||= context[:setting] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
app/models/concerns/decidim/action_delegator/setting_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module ActionDelegator | ||
module SettingOverride | ||
extend ActiveSupport::Concern | ||
included do | ||
enum authorization_method: { phone: 0, email: 1, both: 2, odoo: 3 } | ||
|
||
def odoo_required? | ||
verify_with_odoo? | ||
end | ||
|
||
def verify_with_odoo? | ||
authorization_method == "odoo" | ||
end | ||
end | ||
end | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
...errides/decidim/action_delegator/admin/settings/_form/include_odoo_option.html.erb.deface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- replace 'erb[loud]:contains("decidim.action_delegator.admin.settings.authorization_method")' --> | ||
|
||
<%= form.select :authorization_method, [:both, :phone, :email, :odoo].map { |op| [t(op, scope: "decidim.action_delegator.admin.settings.authorization_method"), op] } %> |
25 changes: 25 additions & 0 deletions
25
app/overrides/decidim/action_delegator/verifications/delegations_authorizer_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module ActionDelegator | ||
module Verifications | ||
module DelegationsAuthorizerOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def authorize | ||
status = super | ||
return status unless status == [:ok, {}] | ||
|
||
# if used outside a consultation, allow all | ||
return [:ok, {}] if consultation.blank? | ||
return [:ok, {}] if setting.odoo_required? | ||
return [:ok, {}] if belongs_to_consultation? && user_in_census? | ||
|
||
[:unauthorized, { extra_explanation: extra_explanations }] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.config.to_prepare do | ||
Decidim::ActionDelegator::Verifications::DelegationsVerifier::AuthorizationsController.include( | ||
Decidim::ActionDelegator::Verifications::DelegationsVerifier::AuthorizationsControllerOverride | ||
) | ||
Decidim::ActionDelegator::Setting.include(Decidim::ActionDelegator::SettingOverride) | ||
Decidim::ActionDelegator::Verifications::DelegationsAuthorizer.include(Decidim::ActionDelegator::Verifications::DelegationsAuthorizerOverride) | ||
Decidim::Odoo::Verifications::OdooMember.include(Decidim::Odoo::Verifications::OdooMemberOverride) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
ca: | ||
decidim: | ||
action_delegator: | ||
admin: | ||
settings: | ||
authorization_method: | ||
odoo: Només membres d'Odoo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,8 @@ | ||
# Files in the config/locales directory are used for internationalization | ||
# and are automatically loaded by Rails. If you want to use locales other | ||
# than English, add the necessary files in this directory. | ||
# | ||
# To use the locales, use `I18n.t`: | ||
# | ||
# I18n.t 'hello' | ||
# | ||
# In views, this is aliased to just `t`: | ||
# | ||
# <%= t('hello') %> | ||
# | ||
# To use a different locale, set it with `I18n.locale`: | ||
# | ||
# I18n.locale = :es | ||
# | ||
# This would use the information in config/locales/es.yml. | ||
# | ||
# The following keys must be escaped otherwise they will not be retrieved by | ||
# the default I18n backend: | ||
# | ||
# true, false, on, off, yes, no | ||
# | ||
# Instead, surround them with single quotes. | ||
# | ||
# en: | ||
# 'true': 'foo' | ||
# | ||
# To learn more, please read the Rails Internationalization guide | ||
# available at https://guides.rubyonrails.org/i18n.html. | ||
|
||
--- | ||
en: | ||
hello: "Hello world" | ||
decidim: | ||
action_delegator: | ||
admin: | ||
settings: | ||
authorization_method: | ||
odoo: Only Odoo members |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
es: | ||
decidim: | ||
action_delegator: | ||
admin: | ||
settings: | ||
authorization_method: | ||
odoo: Solo miembros de Odoo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters