diff --git a/core/app/models/spree/permission_set.rb b/core/app/models/spree/permission_set.rb new file mode 100644 index 00000000000..10682e266ec --- /dev/null +++ b/core/app/models/spree/permission_set.rb @@ -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 diff --git a/core/app/models/spree/role.rb b/core/app/models/spree/role.rb index 6d140ed6ef0..2e42435a1c1 100644 --- a/core/app/models/spree/role.rb +++ b/core/app/models/spree/role.rb @@ -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 } diff --git a/core/app/models/spree/role_permission.rb b/core/app/models/spree/role_permission.rb new file mode 100644 index 00000000000..a194df5b2f0 --- /dev/null +++ b/core/app/models/spree/role_permission.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Spree + class RolePermission < Spree::Base + belongs_to :role + belongs_to :permission_set + end +end diff --git a/core/db/default/spree/permission_sets.rb b/core/db/default/spree/permission_sets.rb new file mode 100644 index 00000000000..323507fec4e --- /dev/null +++ b/core/db/default/spree/permission_sets.rb @@ -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 diff --git a/core/db/seeds.rb b/core/db/seeds.rb index e3d0b75d327..3196cf016b2 100644 --- a/core/db/seeds.rb +++ b/core/db/seeds.rb @@ -13,6 +13,7 @@ zones refund_reasons roles + permission_sets shipping_categories ).each do |seed| shell.say_status :seed, seed