Skip to content

Commit

Permalink
Merge pull request #146 from wri/fix/TM-833-new-framework
Browse files Browse the repository at this point in the history
[TM-833] Allow creation of new frameworks without breaking existing API access.
  • Loading branch information
roguenet authored Apr 16, 2024
2 parents 8892d8b + 58f4d7c commit 488dbb3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 50 deletions.
9 changes: 7 additions & 2 deletions app/Console/Commands/Migration/RolesMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function handle()

if (Role::where('name', 'admin-super')->count() === 0) {
$role = Role::create(['name' => 'admin-super']);
$role->givePermissionTo(['framework-terrafund', 'framework-ppc', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']);
$role->givePermissionTo(['framework-terrafund', 'framework-ppc', 'framework-terrafund-enterprises', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']);
}

if (Role::where('name', 'admin-ppc')->count() === 0) {
Expand All @@ -62,14 +62,19 @@ public function handle()

if (Role::where('name', 'admin-terrafund')->count() === 0) {
$role = Role::create(['name' => 'admin-terrafund']);
$role->givePermissionTo(['framework-terrafund', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']);
$role->givePermissionTo(['framework-terrafund', 'framework-terrafund-enterprises', 'custom-forms-manage', 'users-manage', 'monitoring-manage', 'reports-manage']);
}

if (Role::where('name', 'project-developer')->count() === 0) {
$role = Role::create(['name' => 'project-developer']);
$role->givePermissionTo(['manage-own']);
}

if (Role::where('name', 'greenhouse-service-account')->count() === 0) {
$role = Role::create(['name' => 'greenhouse-service-account']);
$role->givePermissionTo(['projects-read', 'polygons-manage', 'media-manage']);
}

User::whereIn('role', ['user','admin', 'terrafund-admin'])->get()
->each(function (User $user) {
if ($user->primary_role == null) {
Expand Down
46 changes: 0 additions & 46 deletions app/Console/Commands/OneOff/CreateGreenhouseServiceAccountRole.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Http/Controllers/Traits/IsAdminIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function isolateAuthorizedFrameworks(QueryBuilder $query, string $tabl
$query->where(function ($query) use ($tableName, $frameworkNames, $user) {
foreach ($frameworkNames as $framework) {
$frameworkPermission = 'framework-' . $framework;
if ($user->hasPermissionTo($frameworkPermission)) {
if ($user->can($frameworkPermission)) {
$query->orWhere("$tableName.framework_key", $framework);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __invoke(Request $request): UpdateRequestsCollection
$query->where(function ($query) use ($frameworkNames, $user) {
foreach ($frameworkNames as $framework) {
$frameworkPermission = 'framework-' . $framework;
if ($user->hasPermissionTo($frameworkPermission)) {
if ($user->can($frameworkPermission)) {
$query->orWhere('framework_key', $framework);
}
}
Expand Down
1 change: 1 addition & 0 deletions config/wri/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [
'framework-ppc' => 'Framework PPC',
'framework-terrafund' => 'Framework Terrafund',
'framework-terrafund-enterprises' => 'Framework Terrafund Enterprises',
'custom-forms-manage' => 'Manage custom forms',
'users-manage' => 'Manage users',
'monitoring-manage' => 'Manage monitoring',
Expand Down

0 comments on commit 488dbb3

Please sign in to comment.