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

Add rake task to import current Roles to new permission system #361

Conversation

the-krg
Copy link

@the-krg the-krg commented Aug 22, 2023

Summary

This rake task creates Spree::PermissionSet records for each existing permission set subclass in Spree::PermissionSets::*, and Spree::RolePermission records for each role's associated permission sets.
(It is designed to work with both new installations and existing Solidus stores that have custom roles and permissions).

Usage

bin/rails solidus:import_existing_permission_sets

@the-krg the-krg force-pushed the the-krg/add-task-to-import-permissions branch from bc04003 to 50c2659 Compare August 22, 2023 20:13
@the-krg the-krg changed the title Add task to import current permissions Add rake task to import current Roles to new permission system Aug 22, 2023
@the-krg the-krg self-assigned this Aug 22, 2023
@the-krg the-krg force-pushed the the-krg/add-task-to-import-permissions branch from 50c2659 to 2e874bd Compare August 22, 2023 20:30
@the-krg the-krg marked this pull request as ready for review August 22, 2023 20:33
Copy link

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @the-krg, nice work! I left some comments.

namespace :solidus do
desc "Import existing permission sets to role permissions table"
task import_existing_permission_sets: :environment do
Spree::PermissionSets::Base.subclasses.each do |permission|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prepend with Zeitwerk::Loader.eager_load_all? Otherwise, we might skip subclasses that haven't yet been loaded in the development environment.

Also, should we consider subclasses of subclasses?

For both questions, I'm thinking about user-defined permission sets, as they're not a problem in vanilla Solidus.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion!

Did some tests with custom permission sets on Sandbox and it worked.
Also changed from subclasses to descendants, so we do get subclasses of subclasses as well as permission sets inherited from other permission sets.

@the-krg the-krg force-pushed the the-krg/add-task-to-import-permissions branch from 2e874bd to 1744dc8 Compare August 24, 2023 14:29
This commit introduces a simple rake task that imports the
Permission Sets to the DB, then iterates over the
defined permissions on AppConfiguration to create the
RolePermissions.
@the-krg the-krg force-pushed the the-krg/add-task-to-import-permissions branch from 1744dc8 to 5adee72 Compare August 24, 2023 14:50
Copy link

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@the-krg the-krg merged commit ef2de84 into rainerd/incorporate-roles-management-code-into-the-core Aug 25, 2023
@the-krg the-krg deleted the the-krg/add-task-to-import-permissions branch August 25, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants