Skip to content

Commit

Permalink
Add PermissionSet, RolePermission models
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.

Co-authored-by: benjamin wil <[email protected]>
  • Loading branch information
MadelineCollier and benjaminwil committed Sep 6, 2024
1 parent d81043a commit ba1081b
Show file tree
Hide file tree
Showing 3 changed files with 21 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

0 comments on commit ba1081b

Please sign in to comment.