Skip to content

Commit

Permalink
Adapt to Zeitwerk
Browse files Browse the repository at this point in the history
  • Loading branch information
tramuntanal committed Aug 6, 2024
1 parent c6d9c4e commit e97d81b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Following Semantic Versioning 2.
## Version 0.0.6 (MINOR)
- Increase minimum Decidim version to 0.27.6
- Downgrade Ruby version to 3.0.7
- Adapt to Zeitwerk

## Version 0.0.5 (MINOR)
- Increase minimum Decidim version to 0.27.2
Expand Down
64 changes: 35 additions & 29 deletions app/decorators/models/decidim/user_decorator.rb
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

0 comments on commit e97d81b

Please sign in to comment.