Skip to content

Commit

Permalink
Set default roles and groups from Statamic when making users (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Sep 4, 2024
1 parent 7673e81 commit 9d02d3c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Http/Controllers/Webhooks/CustomerCreateUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ private function processWebhook(Request $request, Closure $eventCallback)

if (! $customerEntry) {

if (! $data->email) {
return response()->json([
'message' => 'Customer cannot be created as no email was provided',
], 200);
}

$customerEntry = User::query()
->where('email', $data->email)
->first();
Expand All @@ -48,6 +54,14 @@ private function processWebhook(Request $request, Closure $eventCallback)
'name' => collect([$data->first_name, $data->last_name])->filter()->join(' '),
]);
}

if ($roles = config('statamic.users.new_user_roles')) {
$customerEntry->explicitRoles($roles);
}

if ($groups = config('statamic.users.new_user_groups')) {
$customerEntry->groups($groups);
}
}

if ($customerEntry) {
Expand Down

0 comments on commit 9d02d3c

Please sign in to comment.