Skip to content
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

Merged
merged 7 commits into from
Sep 16, 2024

Conversation

moustachu
Copy link
Member

Usage example :

bundle exec rails authorizations:export_to_user_extended_data AUTHORIZATION_HANDLE_NAME=extended_socio_demographic_authorization_handler

@moustachu moustachu requested review from Quentinchampenois, AyakorK and a team July 24, 2024 20:52
@luciegrau luciegrau added priority: high type: feature PRs that add a new feature labels Jul 25, 2024
Copy link
Contributor

@Quentinchampenois Quentinchampenois left a 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

lib/extends/models/decidim/authorization_extends.rb Outdated Show resolved Hide resolved
}

def export_to_user_extended_data
Decidim::AuthorizationDataToUserDataService.run(name: name, user: user)
Copy link
Contributor

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:

Suggested change
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

Copy link
Member Author

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.

lib/tasks/authorizations.rake Outdated Show resolved Hide resolved
@Quentinchampenois Quentinchampenois merged commit d183a2e into develop Sep 16, 2024
14 checks passed
@Quentinchampenois Quentinchampenois deleted the feat/export_ah_data_to_user branch September 16, 2024 09:02
@luciegrau luciegrau mentioned this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high type: feature PRs that add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants