From f292ce5331b1a0322ac5d301e2be56acfc56ec32 Mon Sep 17 00:00:00 2001 From: Xu Date: Wed, 6 Dec 2023 22:57:45 +0100 Subject: [PATCH] Edit Shirt requires bureaucrat permission --- ...0_change_edit_shirt_require_bureaucrat.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php diff --git a/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php b/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php new file mode 100644 index 00000000..32e91ece --- /dev/null +++ b/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php @@ -0,0 +1,57 @@ +db = $this->schema->getConnection(); + + $this->editShirt = $this->db->table('privileges') + ->where('name', 'user.edit.shirt') + ->get(['id']) + ->first()->id; + } + + /** + * Run the migration + */ + public function up(): void + { + $this->movePermission($this->editShirt, $this->shiCo, $this->bureaucrat); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->movePermission($this->editShirt, $this->bureaucrat, $this->shiCo); + } + + protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void + { + $this->db->table('group_privileges') + ->insertOrIgnore(['group_id' => $newGroup, 'privilege_id' => $privilege]); + + $this->db->table('group_privileges') + ->where(['group_id' => $oldGroup, 'privilege_id' => $privilege]) + ->delete(); + } +}