mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-13 10:42:16 +01:00
Added member and invitation endpoints
This commit is contained in:
@@ -6,21 +6,32 @@ namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Exceptions\Api\UserNotPlaceholderApiException;
|
||||
use App\Http\Requests\V1\Member\MemberIndexRequest;
|
||||
use App\Http\Resources\V1\User\MemberCollection;
|
||||
use App\Http\Resources\V1\User\MemberResource;
|
||||
use App\Http\Requests\V1\Member\MemberUpdateRequest;
|
||||
use App\Http\Resources\V1\Member\MemberCollection;
|
||||
use App\Http\Resources\V1\Member\MemberPivotResource;
|
||||
use App\Http\Resources\V1\Member\MemberResource;
|
||||
use App\Models\Membership;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Laravel\Jetstream\Contracts\InvitesTeamMembers;
|
||||
|
||||
class MemberController extends Controller
|
||||
{
|
||||
protected function checkPermission(Organization $organization, string $permission, ?Membership $membership = null): void
|
||||
{
|
||||
parent::checkPermission($organization, $permission);
|
||||
if ($membership !== null && $membership->organization_id !== $organization->id) {
|
||||
throw new AuthorizationException('Member does not belong to organization');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all members of an organization
|
||||
*
|
||||
* @return MemberCollection<MemberResource>>
|
||||
* @return MemberCollection<MemberPivotResource>>
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*
|
||||
@@ -37,15 +48,51 @@ class MemberController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite a placeholder user to become a member of the organization
|
||||
* Update a member of the organization
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*
|
||||
* @operationId updateMember
|
||||
*/
|
||||
public function update(Organization $organization, Membership $membership, MemberUpdateRequest $request): JsonResource
|
||||
{
|
||||
$this->checkPermission($organization, 'members:update', $membership);
|
||||
|
||||
$membership->billable_rate = $request->input('billable_rate');
|
||||
$membership->role = $request->input('role');
|
||||
$membership->save();
|
||||
|
||||
return new MemberResource($membership);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a member of the organization.
|
||||
*
|
||||
* @throws AuthorizationException
|
||||
*
|
||||
* @operationId removeMember
|
||||
*/
|
||||
public function destroy(Organization $organization, Membership $membership): JsonResponse
|
||||
{
|
||||
$this->checkPermission($organization, 'members:delete', $membership);
|
||||
|
||||
$membership->delete();
|
||||
|
||||
return response()
|
||||
->json(null, 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite a placeholder member to become a real member of the organization
|
||||
*
|
||||
* @throws AuthorizationException|UserNotPlaceholderApiException
|
||||
*
|
||||
* @operationId invitePlaceholder
|
||||
*/
|
||||
public function invitePlaceholder(Organization $organization, User $user, Request $request): JsonResponse
|
||||
public function invitePlaceholder(Organization $organization, Membership $membership, Request $request): JsonResponse
|
||||
{
|
||||
$this->checkPermission($organization, 'members:invite-placeholder');
|
||||
$this->checkPermission($organization, 'members:invite-placeholder', $membership);
|
||||
$user = $membership->user;
|
||||
|
||||
if (! $user->is_placeholder) {
|
||||
throw new UserNotPlaceholderApiException();
|
||||
|
||||
Reference in New Issue
Block a user