Skip to content

Commit 08feab7

Browse files
authored
Fixed updating of assignments.
1 parent ebb2c8b commit 08feab7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Assignment.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function removeAllSuperAdminUsersFromOtherRoles($assignedUsers)
6969
public function assignUsersToRoles($assignedUsers)
7070
{
7171
foreach ($assignedUsers as $role => $users) {
72-
if ($role === 'SuperAdmin' || $role === 'Member') {
72+
if ($role === 'Member') {
7373
continue;
7474
}
7575

@@ -81,13 +81,15 @@ public function assignUsersToRoles($assignedUsers)
8181
}
8282
}
8383

84-
public function removeAllUsersFromRoles()
84+
public function removeUsersFromRoles($assignedUsers)
8585
{
8686
$this->roles
87-
->with('users')
87+
->with("users")
8888
->get()
89-
->each(function ($role) {
90-
$role->users()->detach();
89+
->each(function ($role) use ($assignedUsers) {
90+
$role->users()
91+
->whereIn("id", $assignedUsers)
92+
->detach();
9193
});
9294
}
9395

src/Http/Requests/CreateAssignmentRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function process(): void
2323
{
2424
$assignmentClass = config("genealabs-laravel-governor.models.assignment");
2525
$assignment = new $assignmentClass;
26-
$assignment->removeAllUsersFromRoles();
26+
$assignment->removeUsersFromRoles($this->users);
2727
$assignment->assignUsersToRoles($this->users);
2828
$assignment->addAllUsersToMemberRole();
2929
}

0 commit comments

Comments
 (0)