From 33e32651dde41378437191854466bc554b4748e0 Mon Sep 17 00:00:00 2001
From: Madeline Collier <madeline@super.gd>
Date: Wed, 21 Aug 2024 19:28:05 +0200
Subject: [PATCH 1/3] Make Spree::Role names required

It doesn't make a lot of sense to allow blank on this considering it is
the only defining feature of a Role currently.

Co-authored-by: benjamin wil <benjamin@super.gd>
---
 core/app/models/spree/role.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/app/models/spree/role.rb b/core/app/models/spree/role.rb
index 3e2d7d1a234..6d140ed6ef0 100644
--- a/core/app/models/spree/role.rb
+++ b/core/app/models/spree/role.rb
@@ -5,7 +5,7 @@ class Role < Spree::Base
     has_many :role_users, class_name: "Spree::RoleUser", dependent: :destroy
     has_many :users, through: :role_users
 
-    validates_uniqueness_of :name, case_sensitive: true
+    validates :name, presence: true, uniqueness: { case_sensitive: true, allow_blank: true }
 
     def admin?
       name == "admin"

From 8c04a39f70bc3e7a1db6d415cf048a6f05acd57d Mon Sep 17 00:00:00 2001
From: Madeline Collier <madeline@super.gd>
Date: Wed, 21 Aug 2024 19:44:37 +0200
Subject: [PATCH 2/3] Add solidus_user_roles migrations to core

These migrations originally come from `solidus_user_roles`. We intend to
migrate some of the functionality from that extension into `core`, and
this is the first step. With the table check, these migrations should be
safe to (re)run for any store which might already have
`solidus_user_roles` installed.
---
 ...0240821173254_create_spree_permission_sets_in_core.rb | 9 +++++++++
 ...40821173341_create_spree_roles_permissions_in_core.rb | 9 +++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 core/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb
 create mode 100644 core/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb

diff --git a/core/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb b/core/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb
new file mode 100644
index 00000000000..bf827a11fa8
--- /dev/null
+++ b/core/db/migrate/20240821173254_create_spree_permission_sets_in_core.rb
@@ -0,0 +1,9 @@
+class CreateSpreePermissionSetsInCore < ActiveRecord::Migration[7.0]
+  def change
+    create_table :spree_permission_sets, if_not_exists: true do |t|
+      t.string :name
+      t.string :set
+      t.timestamps null: false
+    end
+  end
+end
diff --git a/core/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb b/core/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb
new file mode 100644
index 00000000000..d4bac14e445
--- /dev/null
+++ b/core/db/migrate/20240821173341_create_spree_roles_permissions_in_core.rb
@@ -0,0 +1,9 @@
+class CreateSpreeRolesPermissionsInCore < ActiveRecord::Migration[7.0]
+  def change
+    create_table :spree_role_permissions, if_not_exists: true do |t|
+      t.references :role
+      t.references :permission_set
+      t.timestamps null: false
+    end
+  end
+end

From 1aa18eee9e85f91c7debbb2d5d55d5b7124724fb Mon Sep 17 00:00:00 2001
From: Madeline Collier <madeline@super.gd>
Date: Wed, 21 Aug 2024 19:51:40 +0200
Subject: [PATCH 3/3] Add description to spree_roles table

---
 .../migrate/20240821173641_add_description_to_spree_roles.rb | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 core/db/migrate/20240821173641_add_description_to_spree_roles.rb

diff --git a/core/db/migrate/20240821173641_add_description_to_spree_roles.rb b/core/db/migrate/20240821173641_add_description_to_spree_roles.rb
new file mode 100644
index 00000000000..3578008ebf1
--- /dev/null
+++ b/core/db/migrate/20240821173641_add_description_to_spree_roles.rb
@@ -0,0 +1,5 @@
+class AddDescriptionToSpreeRoles < ActiveRecord::Migration[7.0]
+  def change
+    add_column :spree_roles, :description, :text
+  end
+end