Skip to content

Commit f8559f0

Browse files
committed
WIP
1 parent 7b5ebc2 commit f8559f0

12 files changed

+307
-142
lines changed

.env.testing

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
APP_NAME="Open Food Network Vouchers"
2-
APP_ENV=local
2+
APP_ENV=testing
33
APP_KEY=base64:E/+xI5BYR6yy+PoKz6nv60FVET0yEcmB0d+bjDM4X2E=
44
APP_DEBUG=true
55
APP_TIMEZONE=UTC
6-
APP_URL=http://open-food-network-vouchers.test
6+
APP_URL=http://vine.test
7+
APP_PRODUCTION_URL=http://vine.test
78

89
APP_LOCALE=en
910
APP_FALLBACK_LOCALE=en

app/Enums/PersonalAccessTokenAbility.php

+81
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,85 @@ enum PersonalAccessTokenAbility: string
2828
case SYSTEM_STATISTICS_READ = 'system-statistics-read';
2929
case SYSTEM_STATISTICS_UPDATE = 'system-statistics-update';
3030
case SYSTEM_STATISTICS_DELETE = 'system-statistics-delete';
31+
case TEAMS_CREATE = 'teams-create';
32+
case TEAMS_READ = 'teams-read';
33+
case TEAMS_UPDATE = 'teams-update';
34+
case TEAMS_DELETE = 'teams-delete';
35+
36+
37+
public static function abilityLabels(): array
38+
{
39+
$returnArray = [
40+
self::SUPER_ADMIN->value => 'Super Admin',
41+
self::MY_PROFILE_CREATE->value => 'My Profile Create',
42+
self::MY_PROFILE_READ->value => 'My Profile Read',
43+
self::MY_PROFILE_UPDATE->value => 'My Profile Update',
44+
self::MY_PROFILE_DELETE->value => 'My Profile Delete',
45+
self::MY_TEAM_CREATE->value => 'My Team Create',
46+
self::MY_TEAM_READ->value => 'My Team Read',
47+
self::MY_TEAM_UPDATE->value => 'My Team Update',
48+
self::MY_TEAM_DELETE->value => 'My Team Delete',
49+
self::TEAMS_READ->value => 'Teams Read',
50+
self::TEAMS_CREATE->value => 'Teams Create',
51+
self::SYSTEM_STATISTICS_READ->value => 'System Statistics Read',
52+
// MUST MATCH FULL LIS
53+
];
54+
55+
// Assert$returnArray
56+
return $returnArray
57+
}
58+
59+
/**
60+
* The abilities that a "platform" app API token should have.
61+
*
62+
* Example: The OFN platform has a shop in its organisation chart, and the shop opts in to the vouchers' system.
63+
* The OFN API token needs to create the team in the vouchers API, create a user for the shop, create an API
64+
* token for that user, and save the API token locally in the OFN DB so that the shop may perform actions like redeeming, etc.
65+
*
66+
* @return PersonalAccessTokenAbility[]
67+
*/
68+
public static function platformAppTokenAbilities(): array
69+
{
70+
return [
71+
self::TEAMS_READ->value => self::abilityLabels()[self::TEAMS_READ->value],
72+
self::TEAMS_CREATE->value => self::abilityLabels()[self::TEAMS_CREATE->value],
73+
self::SYSTEM_STATISTICS_READ->value => self::abilityLabels()[self::SYSTEM_STATISTICS_READ->value],
74+
];
75+
}
76+
77+
78+
/**
79+
* The abilities that a "redemption" app API token should have.
80+
*
81+
* @return array
82+
*/
83+
public static function redemptionAppTokenAbilities(): array
84+
{
85+
return [
86+
87+
];
88+
}
89+
90+
public static function groupsAbilityCasesWithDefinitions(): array
91+
{
92+
return [
93+
[
94+
'name' => 'Super admin abilities',
95+
'description' => 'A group of API abilities that allow an app to perform any / all actions on the API. Be careful assigning this ability!',
96+
'abilities' => [
97+
self::SUPER_ADMIN
98+
]
99+
],
100+
[
101+
'name' => 'Platform App',
102+
'description' => 'Perform administrative tasks for your OFN platform implementation.',
103+
'abilities' => self::platformAppTokenAbilities()
104+
],
105+
[
106+
'name' => 'Redemptions',
107+
'description' => 'A group of API abilities that allow an app to perform redemptions on the system.',
108+
'abilities' => self::redemptionAppTokenAbilities()
109+
],
110+
];
111+
}
31112
}

app/Http/Middleware/HandleInertiaRequests.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ public function share(Request $request): array
3737
{
3838
return [
3939
...parent::share($request),
40-
'auth' => [
40+
'auth' => [
4141
'user' => $request->user(),
4242
'currentTeam' => Team::find($request->user()?->current_team_id),
4343
],
44-
'personalAccessTokenAbilities' => PersonalAccessTokenAbility::cases(),
44+
'personalAccessTokenAbilities' => PersonalAccessTokenAbility::groupsAbilityCasesWithDefinitions(),
45+
'platformAppTokenAbilities' => PersonalAccessTokenAbility::platformAppTokenAbilities(),
4546
];
4647
}
4748
}

composer.lock

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/scribe.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
// The base URL for the API tester to use (for example, you can set this to your staging URL).
8585
// Leave as null to use the current app URL when generating (config("app.url")).
86-
'base_url' => env('APP_URL'),
86+
'base_url' => env('APP_PRODUCTION_URL'),
8787

8888
// [Laravel Sanctum] Fetch a CSRF token before each request, and add it as an X-XSRF-TOKEN header.
8989
'use_csrf' => true,

0 commit comments

Comments
 (0)