Skip to content

Commit 74eeeda

Browse files
authored
🛂 Enable Profile Editor Roles to Manage Profiles With Multiple Schools or Departments (#174)
* Verify `school_editor_rol` to check for multiple schools associated to a profile * 🛂 Update Profile Policy class to allow profile editor roles to verify their ability to edit profiles with multiple schools or departments associated
1 parent 2109193 commit 74eeeda

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎app/Policies/ProfilePolicy.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function before($user, $ability)
3535
*/
3636
protected function checkSchoolEditor(User $user, Profile $profile)
3737
{
38-
return $user->hasRoleOption('school_profiles_editor', 'schools', $profile->user->school_id ?? -1);
38+
$profile_schools = $profile->user->schools;
39+
40+
return $profile_schools->contains(fn($school) => $user->hasRoleOption('school_profiles_editor', 'schools', $school->id ?? -1));
3941
}
4042

4143
/**
@@ -47,7 +49,9 @@ protected function checkSchoolEditor(User $user, Profile $profile)
4749
*/
4850
protected function checkDepartmentEditor(User $user, Profile $profile)
4951
{
50-
return $user->hasRoleOption('department_profiles_editor', 'departments', $profile->user->department ?? 'none');
52+
$profile_departments = $profile->user->departments;
53+
54+
return $profile_departments->contains(fn($department) => $user->hasRoleOption('department_profiles_editor', 'departments', $department ?? 'none'));
5155
}
5256

5357
/**

0 commit comments

Comments
 (0)