diff --git a/app/Http/Controllers/Staff/GroupMemberController.php b/app/Http/Controllers/Staff/GroupMemberController.php index 402effd..3f80fbe 100644 --- a/app/Http/Controllers/Staff/GroupMemberController.php +++ b/app/Http/Controllers/Staff/GroupMemberController.php @@ -105,7 +105,7 @@ public function update(Group $group, User $member, Request $request) 'level' => new Enum(GroupUserLevel::class), ]); - $requestMember = $group->users()->find($request->user()->id)->pivot; + $requestMember = $group->users()->find($member->id)->pivot; $this->authorize("update", $requestMember); $pivot = $group->users()->find($member->id)->pivot; diff --git a/app/Http/Controllers/Staff/GroupsController.php b/app/Http/Controllers/Staff/GroupsController.php index 4dfa77d..4710f27 100644 --- a/app/Http/Controllers/Staff/GroupsController.php +++ b/app/Http/Controllers/Staff/GroupsController.php @@ -23,6 +23,7 @@ public function index(Request $request) $departments = Group::where('type', GroupTypeEnum::Department) ->withCount('users')->get(); + $departmentsSortedByMembershipAndUserCount = $departments->sortByDesc(fn($department) => [ $myDepartments->contains($department->id), $department->users_count @@ -51,6 +52,12 @@ public function show(Group $group, Request $request) public function update(GroupUpdateRequest $request, Group $group) { Gate::authorize('update', $group); + // if name isset then it needs to be not null + if (isset($request->validated()['name'])) { + $request->validate([ + 'name' => ['required', 'string', 'max:255'], + ]); + } $group->update($request->validated()); return redirect()->back(); diff --git a/app/Http/Requests/Groups/GroupUpdateRequest.php b/app/Http/Requests/Groups/GroupUpdateRequest.php index 904074e..7e012ba 100644 --- a/app/Http/Requests/Groups/GroupUpdateRequest.php +++ b/app/Http/Requests/Groups/GroupUpdateRequest.php @@ -10,7 +10,7 @@ public function rules(): array { return [ 'description' => ['nullable','string','max:10000'], - 'name' => ['required','string','max:255'], + 'name' => ['nullable','string','max:255'], ]; } diff --git a/app/Models/Group.php b/app/Models/Group.php index ca5686f..8169401 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -81,7 +81,11 @@ public function getHashidsConnection() public function setNameAttribute($value) { $this->attributes['name'] = $value; - $this->attributes['slug'] = Str::slug($value); + $prefix = ''; + if ($this->parent) { + $prefix = $this->parent->name.' / '; + } + $this->attributes['slug'] = $prefix.Str::slug($value); } public function getLogoUrlAttribute() diff --git a/app/Observers/GroupObserver.php b/app/Observers/GroupObserver.php index a2d26d5..d417cdf 100644 --- a/app/Observers/GroupObserver.php +++ b/app/Observers/GroupObserver.php @@ -6,12 +6,17 @@ use App\Enums\GroupUserLevel; use App\Models\Group; use App\Services\NextcloudService; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; class GroupObserver { public function created(Group $group) { + if (App::isLocal()) { + return; + } + if ($group->type === GroupTypeEnum::Team && $group->parent->nextcloud_folder_id) { NextcloudService::createGroup($group->hashid); // Parent->name / Group->name @@ -29,6 +34,10 @@ public function created(Group $group) public function updated(Group $group): void { + if (App::isLocal()) { + return; + } + if ($group->isDirty('nextcloud_folder_name') && !app()->runningUnitTests()) { // Update or create the folder via nextcloud if ($group->nextcloud_folder_id) { @@ -61,6 +70,10 @@ public function updated(Group $group): void public function deleted(Group $group) { + if (App::isLocal()) { + return; + } + NextcloudService::deleteGroup($group->hashid); } } diff --git a/app/Observers/GroupUserObserver.php b/app/Observers/GroupUserObserver.php index 433d760..1bfb27f 100644 --- a/app/Observers/GroupUserObserver.php +++ b/app/Observers/GroupUserObserver.php @@ -7,6 +7,7 @@ use App\Jobs\CheckStaffGroupMembershipJob; use App\Models\GroupUser; use App\Services\NextcloudService; +use Illuminate\Support\Facades\App; class GroupUserObserver { @@ -15,6 +16,9 @@ public function created(GroupUser $groupUser): void if ($groupUser->group->type === GroupTypeEnum::Department) { CheckStaffGroupMembershipJob::dispatch($groupUser->user); } + if (App::isLocal()) { + return; + } if (($groupUser->group->nextcloud_folder_name || $groupUser->group->parent?->nextcloud_folder_name) && !app()->runningUnitTests()) { NextcloudService::addUserToGroup($groupUser->group, $groupUser->user); $allowAclManagement = in_array($groupUser->level, [GroupUserLevel::Admin, GroupUserLevel::Owner]); @@ -26,6 +30,9 @@ public function created(GroupUser $groupUser): void public function updated(GroupUser $groupUser): void { + if (App::isLocal()) { + return; + } if ($groupUser->group->nextcloud_folder_name && !app()->runningUnitTests()) { if ($groupUser->isDirty('level')) { $allowAclManagement = in_array($groupUser->level, [GroupUserLevel::Admin, GroupUserLevel::Owner]); @@ -39,6 +46,9 @@ public function deleted(GroupUser $groupUser): void if ($groupUser->group->type === GroupTypeEnum::Department) { CheckStaffGroupMembershipJob::dispatch($groupUser->user); } + if (App::isLocal()) { + return; + } if ($groupUser->group->nextcloud_folder_name && !app()->runningUnitTests()) { NextcloudService::removeUserFromGroup($groupUser->group, $groupUser->user); if ($groupUser->group->type !== GroupTypeEnum::Team) {