-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: export authorization metadata to user extended data #568
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution, I just have little feedbacks
} | ||
|
||
def export_to_user_extended_data | ||
Decidim::AuthorizationDataToUserDataService.run(name: name, user: user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use another Service or adapt this one because the after_commit
hook will fetch all authorizations for a given user and update every time her extended_data
column.
In the after_commit
hook we should update directly the extended_data
column
Example:
Decidim::AuthorizationDataToUserDataService.run(name: name, user: user) | |
extended_data = user.extended_data | |
extended_data.merge!({ name.to_s => authorization.metadata }) | |
user.extended_data = extended_data | |
user.save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service is already filtered with the name of the authorization (and it's not possible to have 2 authorizations with the same name and user).
The idea was to avoid duplicate the code if we need to edit the part that handle the data update.
app/services/decidim/authorization_data_to_user_data_service.rb
Outdated
Show resolved
Hide resolved
Co-authored-by: Quentin Champenois <26109239+Quentinchampenois@users.noreply.github.com>
Co-authored-by: Quentin Champenois <26109239+Quentinchampenois@users.noreply.github.com>
e8465c5
to
cf2e303
Compare
Usage example :
bundle exec rails authorizations:export_to_user_extended_data AUTHORIZATION_HANDLE_NAME=extended_socio_demographic_authorization_handler