-
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.
- Loading branch information
1 parent
c6d9c4e
commit e97d81b
Showing
2 changed files
with
36 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
Decidim::User.class_eval do | ||
def after_confirmation | ||
return unless available_members_picker_authorization? | ||
class UserDecorator | ||
def self.decorate | ||
Decidim::User.class_eval do | ||
def after_confirmation | ||
return unless available_members_picker_authorization? | ||
|
||
Decidim::Authorization.create_or_update_from(handler) | ||
end | ||
Decidim::Authorization.create_or_update_from(handler) | ||
end | ||
|
||
def grant_authorization | ||
after_confirmation | ||
end | ||
def grant_authorization | ||
after_confirmation | ||
end | ||
|
||
def email_changed? | ||
revoke_members_picker_authorization! | ||
end | ||
def email_changed? | ||
revoke_members_picker_authorization! | ||
end | ||
|
||
private | ||
private | ||
|
||
def available_members_picker_authorization? | ||
organization.available_authorizations.member?(handler_name) | ||
end | ||
def available_members_picker_authorization? | ||
organization.available_authorizations.member?(handler_name) | ||
end | ||
|
||
def handler_params | ||
@handler_params ||= { user: self, members_picker: email } | ||
end | ||
def handler_params | ||
@handler_params ||= { user: self, members_picker: email } | ||
end | ||
|
||
def handler_name | ||
@handler_name ||= Decidim::Verifications::MembersPicker::MembersPickerAuthorizationHandler.handler_name | ||
end | ||
def handler_name | ||
@handler_name ||= Decidim::Verifications::MembersPicker::MembersPickerAuthorizationHandler.handler_name | ||
end | ||
|
||
def handler | ||
@handler ||= Decidim::AuthorizationHandler.handler_for(handler_name, handler_params) | ||
end | ||
def handler | ||
@handler ||= Decidim::AuthorizationHandler.handler_for(handler_name, handler_params) | ||
end | ||
|
||
def granted_members_picker_authorization | ||
Decidim::Authorization.find_by(decidim_user_id: id, name: handler_name) | ||
end | ||
def granted_members_picker_authorization | ||
Decidim::Authorization.find_by(decidim_user_id: id, name: handler_name) | ||
end | ||
|
||
def revoke_members_picker_authorization! | ||
granted_members_picker_authorization.destroy! if granted_members_picker_authorization | ||
def revoke_members_picker_authorization! | ||
granted_members_picker_authorization.destroy! if granted_members_picker_authorization | ||
end | ||
end | ||
end | ||
end | ||
|
||
UserDecorator.decorate |