Skip to content

Commit

Permalink
Add PermissionSet, RolePermission models & seeds
Browse files Browse the repository at this point in the history
This is building off of the new migrations in
solidusio#5833

These originate from `solidus_user_roles`. We intend to migrate some of
the functionality from that extension into `core`, and this is the
(second) step.
  • Loading branch information
MadelineCollier committed Sep 3, 2024
1 parent e8c9675 commit 3f82669
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/app/models/spree/permission_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Spree
class PermissionSet < Spree::Base
has_many :role_permissions
has_many :roles, through: :role_permissions
validates :name, :set, presence: true
scope :display_permissions, -> { where('name LIKE ?', '%Display') }
scope :management_permissions, -> { where('name LIKE ?', '%Management') }
end
end
2 changes: 2 additions & 0 deletions core/app/models/spree/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Spree
class Role < Spree::Base
has_many :role_users, class_name: "Spree::RoleUser", dependent: :destroy
has_many :users, through: :role_users
has_many :role_permissions, dependent: :destroy
has_many :permission_sets, through: :role_permissions

validates :name, presence: true, uniqueness: { case_sensitive: true, allow_blank: true }

Expand Down
8 changes: 8 additions & 0 deletions core/app/models/spree/role_permission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module Spree
class RolePermission < Spree::Base
belongs_to :role
belongs_to :permission_set
end
end
5 changes: 5 additions & 0 deletions core/db/default/spree/permission_sets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Spree::PermissionSets::Base.subclasses.each do |permission|
Spree::PermissionSet.create(name: permission.to_s.split('PermissionSets::').last, set: permission.to_s)
end
1 change: 1 addition & 0 deletions core/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
zones
refund_reasons
roles
permission_sets
shipping_categories
).each do |seed|
shell.say_status :seed, seed
Expand Down

0 comments on commit 3f82669

Please sign in to comment.