Skip to content

Commit

Permalink
Add task to import current permissions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-krg committed Aug 22, 2023
1 parent 81d1dee commit bc04003
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/lib/tasks/solidus/import_existing_permission_sets.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

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|
Spree::PermissionSet.find_or_create_by(name: permission.to_s.split('PermissionSets::').last, set: permission.to_s)
end

Spree::AppConfiguration.new.roles.roles.each do |role_name, role_config|
role_config.permission_sets.each do |permission_set|
role = Spree::Role.find_or_create_by(name: role_name)
permission_set = Spree::PermissionSet.find_by_set(permission_set.name)

next unless permission_set

Spree::RolePermission.find_or_create_by!(
role: role,
permission_set: permission_set
)
end
end
end
end

0 comments on commit bc04003

Please sign in to comment.