From e11ad5ad7616d35fb761ceecdd892888d1716fd1 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 11:20:44 -0700 Subject: [PATCH 1/4] [TM-812] Remove project establishment and seed collection from workday collections. --- app/Models/V2/Projects/ProjectReport.php | 20 --------------- app/Models/V2/Workdays/Workday.php | 8 ------ config/wri/linked-fields.php | 32 ------------------------ 3 files changed, 60 deletions(-) diff --git a/app/Models/V2/Projects/ProjectReport.php b/app/Models/V2/Projects/ProjectReport.php index 5c34ce39a..d56bd7050 100644 --- a/app/Models/V2/Projects/ProjectReport.php +++ b/app/Models/V2/Projects/ProjectReport.php @@ -239,11 +239,6 @@ public function treeSpecies() return $this->morphMany(TreeSpecies::class, 'speciesable'); } - public function workdaysPaidProjectEstablishment() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT); - } - public function workdaysPaidNurseryOperations() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS); @@ -254,21 +249,11 @@ public function workdaysPaidProjectManagement() return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT); } - public function workdaysPaidSeedCollection() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_SEED_COLLECTION); - } - public function workdaysPaidOtherActivities() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_PAID_OTHER); } - public function workdaysVolunteerProjectEstablishment() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT); - } - public function workdaysVolunteerNurseryOperations() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS); @@ -279,11 +264,6 @@ public function workdaysVolunteerProjectManagement() return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT); } - public function workdaysVolunteerSeedCollection() - { - return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION); - } - public function workdaysVolunteerOtherActivities() { return $this->morphMany(Workday::class, 'workdayable')->where('collection', Workday::COLLECTION_PROJECT_VOLUNTEER_OTHER); diff --git a/app/Models/V2/Workdays/Workday.php b/app/Models/V2/Workdays/Workday.php index 80850212f..bb1c3e0b1 100644 --- a/app/Models/V2/Workdays/Workday.php +++ b/app/Models/V2/Workdays/Workday.php @@ -33,27 +33,19 @@ class Workday extends Model 'indigeneity', ]; - public const COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT = 'paid-project-establishment'; public const COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS = 'paid-nursery-operations'; public const COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT = 'paid-project-management'; - public const COLLECTION_PROJECT_PAID_SEED_COLLECTION = 'paid-seed-collection'; public const COLLECTION_PROJECT_PAID_OTHER = 'paid-other-activities'; - public const COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT = 'volunteer-project-establishment'; public const COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS = 'volunteer-nursery-operations'; public const COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT = 'volunteer-project-management'; - public const COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION = 'volunteer-seed-collection'; public const COLLECTION_PROJECT_VOLUNTEER_OTHER = 'volunteer-other-activities'; public static $projectCollections = [ - self::COLLECTION_PROJECT_PAID_PROJECT_ESTABLISHMENT => 'Paid Project Establishment', self::COLLECTION_PROJECT_PAID_NURSERY_OPRERATIONS => 'Paid Nursery Operations', self::COLLECTION_PROJECT_PAID_PROJECT_MANAGEMENT => 'Paid Project Management', - self::COLLECTION_PROJECT_PAID_SEED_COLLECTION => 'Paid Seed Collection', self::COLLECTION_PROJECT_PAID_OTHER => 'Paid Other Activities', - self::COLLECTION_PROJECT_VOLUNTEER_PROJECT_ESTABLISHMENT => 'Volunteer Project Establishment', self::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPRERATIONS => 'Volunteer Nursery Operations', self::COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT => 'Volunteer Project Management', - self::COLLECTION_PROJECT_VOLUNTEER_SEED_COLLECTION => 'Volunteer Seed Collection', self::COLLECTION_PROJECT_VOLUNTEER_OTHER => 'Volunteer Other Activities', ]; diff --git a/config/wri/linked-fields.php b/config/wri/linked-fields.php index a79b1b5da..e4a2484c8 100644 --- a/config/wri/linked-fields.php +++ b/config/wri/linked-fields.php @@ -424,14 +424,6 @@ 'input_type' => 'treeSpecies', 'collection' => 'tree-planted', ], - // 'pro-rep-rel-paid-project-establishment' => [ - // 'property' => 'workdaysPaidProjectEstablishment', - // 'label' => 'Paid Project Establishment', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'paid-project-establishment', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-paid-nursery-operations' => [ 'property' => 'workdaysPaidNurseryOperations', 'label' => 'Paid Nursery Operations', @@ -448,14 +440,6 @@ 'collection' => 'paid-project-management', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-paid-seed-collection' => [ - // 'property' => 'workdaysPaidSeedCollection', - // 'label' => 'Paid Seed Collection', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'paid-seed-collection', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-paid-other-activities' => [ 'property' => 'workdaysPaidOtherActivities', 'label' => 'Paid Other Activities', @@ -464,14 +448,6 @@ 'collection' => 'paid-other-activities', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-volunteer-project-establishment' => [ - // 'property' => 'workdaysVolunteerProjectEstablishment', - // 'label' => 'Volunteer Project Establishment', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'volunteer-project-establishment', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-volunteer-nursery-operations' => [ 'property' => 'workdaysVolunteerNurseryOperations', 'label' => 'Volunteer Nursery Operations', @@ -488,14 +464,6 @@ 'collection' => 'volunteer-project-management', 'option_list_key' => 'workdays-ethnicity', ], - // 'pro-rep-rel-volunteer-seed-collection' => [ - // 'property' => 'workdaysVolunteerSeedCollection', - // 'label' => 'Volunteer Seed Collection', - // 'resource' => 'App\Http\Resources\V2\Workdays\WorkdayResource', - // 'input_type' => 'workdays', - // 'collection' => 'volunteer-seed-collection', - // 'option_list_key' => 'workdays-ethnicity', - // ], 'pro-rep-rel-volunteer-other-activities' => [ 'property' => 'workdaysVolunteerOtherActivities', 'label' => 'Volunteer Other Activities', From 9d365bfdfe32e07c43e7c94dbd018092b1b9eda2 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 11:49:09 -0700 Subject: [PATCH 2/4] Fix lint --- .../V2/Exports/ExportAllMonitoredEntitiesController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php index ded1eb6fa..3cfb9e4d0 100644 --- a/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php +++ b/app/Http/Controllers/V2/Exports/ExportAllMonitoredEntitiesController.php @@ -41,8 +41,10 @@ public function __invoke(Request $request, string $entity, string $framework) private function getSlug(string $framework) { $frameworkModel = Framework::where('access_code', $framework)->firstOrFail(); + return $frameworkModel->slug; } + private function getForm(string $modelClass, string $framework) { return Form::where('model', $modelClass) From 93bd4c3bd9513d1fbe9d778332b3ebd60cf4849d Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 13:43:30 -0700 Subject: [PATCH 3/4] [TM-782] Fix lint and failing unit test from staging. --- tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php index e1bdbb19e..f8059ba4e 100644 --- a/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php +++ b/tests/V2/Exports/ExportAllMonitoredEntitiesControllerTest.php @@ -4,6 +4,7 @@ use App\Helpers\CustomFormHelper; use App\Jobs\V2\GenerateAdminAllEntityRecordsExportJob; +use App\Models\Framework; use App\Models\User; use App\Models\V2\Nurseries\Nursery; use App\Models\V2\Nurseries\NurseryReport; @@ -31,6 +32,8 @@ public function test_an_admin_user_can_export_all_monitored_entities(string $per $user = User::factory()->admin()->create(); $user->givePermissionTo($permission); + Framework::factory()->create(['slug' => $fmKey, 'access_code' => $fmKey]); + $testCases = [ 'projects' => Project::factory()->count(5)->create(['framework_key' => $fmKey]), 'sites' => Site::factory()->count(5)->create(['framework_key' => $fmKey]), From bbbc874558496bdc9145935c7542185a3eef00c0 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Mon, 15 Apr 2024 15:13:59 -0700 Subject: [PATCH 4/4] [TM-515] Only assign spatie roles if the user doesn't already have them. --- app/Console/Commands/Migration/RolesMigrationCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Migration/RolesMigrationCommand.php b/app/Console/Commands/Migration/RolesMigrationCommand.php index 85c5fb696..dde843401 100644 --- a/app/Console/Commands/Migration/RolesMigrationCommand.php +++ b/app/Console/Commands/Migration/RolesMigrationCommand.php @@ -72,7 +72,9 @@ public function handle() User::whereIn('role', ['user','admin', 'terrafund-admin'])->get() ->each(function (User $user) { - assignSpatieRole($user); + if ($user->primary_role == null) { + assignSpatieRole($user); + } }); if ($this->option('log')) {