diff --git a/app/Api/v1/Controllers/GroupController.php b/app/Api/v1/Controllers/GroupController.php index 53bc544b..2abdf7f9 100644 --- a/app/Api/v1/Controllers/GroupController.php +++ b/app/Api/v1/Controllers/GroupController.php @@ -107,6 +107,8 @@ class GroupController extends Controller $group->loadCount('twofaccounts'); } catch (ModelNotFoundException $exc) { abort(404); + } catch (\Throwable $th) { + abort(409, 'Conflict'); } return new GroupResource($group); diff --git a/app/Services/GroupService.php b/app/Services/GroupService.php index 882fb3d7..79d8f59c 100644 --- a/app/Services/GroupService.php +++ b/app/Services/GroupService.php @@ -59,7 +59,7 @@ class GroupService $ids = is_array($ids) ? $ids : [$ids]; DB::transaction(function () use ($group, $ids, $user) { - $group = Group::lockForUpdate()->find($group->id); + $group = Group::sharedLock()->find($group->id); $twofaccounts = TwoFAccount::sharedLock()->find($ids); if (! $group) { @@ -73,7 +73,7 @@ class GroupService $group->twofaccounts()->saveMany($twofaccounts); Log::info(sprintf('Twofaccounts #%s assigned to group %s (ID #%s)', implode(',', $ids), var_export($group->name, true), $group->id)); - }); + }, 5); } else { Log::info('Cannot find a group to assign the TwoFAccounts to'); }