Skip to content

Commit

Permalink
Fixed updating of assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Jun 29, 2023
1 parent ebb2c8b commit 08feab7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function removeAllSuperAdminUsersFromOtherRoles($assignedUsers)
public function assignUsersToRoles($assignedUsers)
{
foreach ($assignedUsers as $role => $users) {
if ($role === 'SuperAdmin' || $role === 'Member') {
if ($role === 'Member') {
continue;
}

Expand All @@ -81,13 +81,15 @@ public function assignUsersToRoles($assignedUsers)
}
}

public function removeAllUsersFromRoles()
public function removeUsersFromRoles($assignedUsers)
{
$this->roles
->with('users')
->with("users")
->get()
->each(function ($role) {
$role->users()->detach();
->each(function ($role) use ($assignedUsers) {
$role->users()
->whereIn("id", $assignedUsers)
->detach();
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/CreateAssignmentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function process(): void
{
$assignmentClass = config("genealabs-laravel-governor.models.assignment");
$assignment = new $assignmentClass;
$assignment->removeAllUsersFromRoles();
$assignment->removeUsersFromRoles($this->users);
$assignment->assignUsersToRoles($this->users);
$assignment->addAllUsersToMemberRole();
}
Expand Down

0 comments on commit 08feab7

Please sign in to comment.