From d73233bea7b623ef64b52bce664cb4268ae8a267 Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Wed, 15 May 2024 17:09:42 -0400 Subject: [PATCH 1/3] Update tag permissions for new system. --- ...> 2024_05_15_200655_create_tag_tables.php} | 0 ...05_15_200656_seed_permissions_for_tags.php | 33 ++++++++++++++++++ ...00657_data_activate_tags_feature_flag.php} | 0 .../Concerns/CanModifyPermissions.php | 34 +++++++++++++------ 4 files changed, 57 insertions(+), 10 deletions(-) rename database/migrations/{2024_05_08_192655_create_tag_tables.php => 2024_05_15_200655_create_tag_tables.php} (100%) create mode 100644 database/migrations/2024_05_15_200656_seed_permissions_for_tags.php rename database/migrations/{2024_05_08_192850_data_activate_tags_feature_flag.php => 2024_05_15_200657_data_activate_tags_feature_flag.php} (100%) diff --git a/database/migrations/2024_05_08_192655_create_tag_tables.php b/database/migrations/2024_05_15_200655_create_tag_tables.php similarity index 100% rename from database/migrations/2024_05_08_192655_create_tag_tables.php rename to database/migrations/2024_05_15_200655_create_tag_tables.php diff --git a/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php new file mode 100644 index 000000000..a114b88cf --- /dev/null +++ b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php @@ -0,0 +1,33 @@ + 'Tag', + 'tag.create' => 'Tag', + 'tag.*.view' => 'Tag', + 'tag.*.update' => 'Tag', + 'tag.*.delete' => 'Tag', + 'tag.*.restore' => 'Tag', + 'tag.*.force-delete' => 'Tag', + ]; + + private array $guards = [ + 'web', + 'api', + ]; + + public function up(): void + { + $this->createPermissions($this->permissions, $this->guards); + } + + public function down(): void + { + $this->deletePermissions(array_keys($this->permissions), $this->guards); + } +}; diff --git a/database/migrations/2024_05_08_192850_data_activate_tags_feature_flag.php b/database/migrations/2024_05_15_200657_data_activate_tags_feature_flag.php similarity index 100% rename from database/migrations/2024_05_08_192850_data_activate_tags_feature_flag.php rename to database/migrations/2024_05_15_200657_data_activate_tags_feature_flag.php diff --git a/database/migrations/Concerns/CanModifyPermissions.php b/database/migrations/Concerns/CanModifyPermissions.php index 8e40b032e..7b0cc98f0 100644 --- a/database/migrations/Concerns/CanModifyPermissions.php +++ b/database/migrations/Concerns/CanModifyPermissions.php @@ -44,7 +44,7 @@ trait CanModifyPermissions /** * @param array $names The keys of the array should be the permission names and the values should be the name of the group they belong to. */ - public function createPermissions(array $names, string $guardName): void + public function createPermissions(array $names, string|array $guardName): void { $groups = DB::table('permission_groups') ->pluck('id', 'name') @@ -75,15 +75,29 @@ public function createPermissions(array $names, string $guardName): void ...$newGroups, ]; + collect($guardName) + ->each(function (string $guardName) use ($names, $groups): void { + DB::table('permissions') + ->insert(array_map(function (string $name, string $groupName) use ($groups, $guardName): array { + return [ + 'id' => (string) Str::orderedUuid(), + 'group_id' => $groups[$groupName], + 'guard_name' => $guardName, + 'name' => $name, + 'created_at' => now(), + ]; + }, array_keys($names), array_values($names))); + }); + } + + /** + * @param array $names Just the names of the permissions to delete. The group is not needed. + */ + public function deletePermissions(array $names, string|array $guardName): void + { DB::table('permissions') - ->insert(array_map(function (string $name, string $groupName) use ($groups, $guardName): array { - return [ - 'id' => (string) Str::orderedUuid(), - 'group_id' => $groups[$groupName], - 'guard_name' => $guardName, - 'name' => $name, - 'created_at' => now(), - ]; - }, array_keys($names), array_values($names))); + ->whereIn('name', $names) + ->whereIn('guard_name', collect($guardName)) + ->delete(); } } From 04ccc210e82961db9308e7450f8f4d82dab4ef2d Mon Sep 17 00:00:00 2001 From: mxm1070 Date: Wed, 15 May 2024 21:12:21 +0000 Subject: [PATCH 2/3] chore: fix enforcement of copyright on all files --- ...05_15_200656_seed_permissions_for_tags.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php index a114b88cf..599816632 100644 --- a/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php +++ b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php @@ -1,5 +1,39 @@ + + Copyright © 2016-2024, Canyon GBS LLC. All rights reserved. + + Aiding App™ is licensed under the Elastic License 2.0. For more details, + see + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Aiding App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + or contact us via email at legal@canyongbs.com. + + +*/ + use Illuminate\Database\Migrations\Migration; use Database\Migrations\Concerns\CanModifyPermissions; From a0b69c02d5aa2abc6506021951cac1a98587512a Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Wed, 15 May 2024 18:40:07 -0400 Subject: [PATCH 3/3] fix --- ...05_15_200656_seed_permissions_for_tags.php | 12 ++++++++- .../Concerns/CanModifyPermissions.php | 25 ++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php index 599816632..91e73c86e 100644 --- a/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php +++ b/database/migrations/2024_05_15_200656_seed_permissions_for_tags.php @@ -34,6 +34,8 @@ */ +use Illuminate\Support\Arr; +use Illuminate\Support\Facades\DB; use Illuminate\Database\Migrations\Migration; use Database\Migrations\Concerns\CanModifyPermissions; @@ -57,7 +59,15 @@ public function up(): void { - $this->createPermissions($this->permissions, $this->guards); + collect($this->guards) + ->each(function (string $guard) { + $permissions = Arr::except($this->permissions, keys: DB::table('permissions') + ->where('guard_name', $guard) + ->pluck('name') + ->all()); + + $this->createPermissions($permissions, $guard); + }); } public function down(): void diff --git a/database/migrations/Concerns/CanModifyPermissions.php b/database/migrations/Concerns/CanModifyPermissions.php index 7b0cc98f0..996e20f51 100644 --- a/database/migrations/Concerns/CanModifyPermissions.php +++ b/database/migrations/Concerns/CanModifyPermissions.php @@ -44,7 +44,7 @@ trait CanModifyPermissions /** * @param array $names The keys of the array should be the permission names and the values should be the name of the group they belong to. */ - public function createPermissions(array $names, string|array $guardName): void + public function createPermissions(array $names, string $guardName): void { $groups = DB::table('permission_groups') ->pluck('id', 'name') @@ -75,19 +75,16 @@ public function createPermissions(array $names, string|array $guardName): void ...$newGroups, ]; - collect($guardName) - ->each(function (string $guardName) use ($names, $groups): void { - DB::table('permissions') - ->insert(array_map(function (string $name, string $groupName) use ($groups, $guardName): array { - return [ - 'id' => (string) Str::orderedUuid(), - 'group_id' => $groups[$groupName], - 'guard_name' => $guardName, - 'name' => $name, - 'created_at' => now(), - ]; - }, array_keys($names), array_values($names))); - }); + DB::table('permissions') + ->insert(array_map(function (string $name, string $groupName) use ($groups, $guardName): array { + return [ + 'id' => (string) Str::orderedUuid(), + 'group_id' => $groups[$groupName], + 'guard_name' => $guardName, + 'name' => $name, + 'created_at' => now(), + ]; + }, array_keys($names), array_values($names))); } /**