mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 09:05:08 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Groups\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Modules\Audit\Action;
|
|
use App\Modules\Audit\ActivityLogger;
|
|
use App\Modules\Groups\Models\Group;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class GroupMembersController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ActivityLogger $activity,
|
|
) {}
|
|
|
|
public function store(Request $request, Group $group): RedirectResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'user_id' => ['required', 'integer', 'exists:users,id'],
|
|
]);
|
|
|
|
/** @var User $client */
|
|
$client = User::query()->findOrFail((int) $validated['user_id']);
|
|
|
|
// Membership is clients-only — staff never belong to groups.
|
|
if (! $client->isClient()) {
|
|
throw ValidationException::withMessages([
|
|
'user_id' => __('Only clients can be group members.'),
|
|
]);
|
|
}
|
|
|
|
$group->members()->syncWithoutDetaching([$client->id]);
|
|
|
|
$this->activity->log(Action::GroupMemberAdded, subject: $group, context: ['member' => $client->name]);
|
|
|
|
return back();
|
|
}
|
|
|
|
public function destroy(Group $group, User $member): RedirectResponse
|
|
{
|
|
$group->members()->detach($member->id);
|
|
|
|
$this->activity->log(Action::GroupMemberRemoved, subject: $group, context: ['member' => $member->name]);
|
|
|
|
return back();
|
|
}
|
|
}
|