-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added placeholder users; Better exception handling; Enhanced local setup
- Loading branch information
Showing
38 changed files
with
880 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ MAIL_PORT=1025 | |
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
AWS_ACCESS_KEY_ID= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ yarn-error.log | |
/blob-report/ | ||
/playwright/.cache/ | ||
/coverage | ||
/extensions/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions\Api; | ||
|
||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use LogicException; | ||
|
||
abstract class ApiException extends Exception | ||
{ | ||
/** | ||
* Render the exception into an HTTP response. | ||
*/ | ||
public function render(Request $request): JsonResponse | ||
{ | ||
return response() | ||
->json([ | ||
'error' => true, | ||
'key' => $this->getKey(), | ||
'message' => $this->getTranslatedMessage(), | ||
], 400); | ||
} | ||
|
||
/** | ||
* Get the key for the exception. | ||
*/ | ||
public function getKey(): string | ||
{ | ||
if (defined(static::class.'::KEY')) { | ||
return static::KEY; | ||
} | ||
|
||
throw new LogicException('API exceptions need the KEY constant defined.'); | ||
} | ||
|
||
/** | ||
* Get the translated message for the exception. | ||
*/ | ||
public function getTranslatedMessage(): string | ||
{ | ||
return __('exceptions.api.'.$this->getKey()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions\Api; | ||
|
||
class TimeEntryStillRunningApiException extends ApiException | ||
{ | ||
const string KEY = 'time_entry_still_running'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Exceptions\Api; | ||
|
||
class UserNotPlaceholderApiException extends ApiException | ||
{ | ||
const string KEY = 'user_not_placeholder'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Exceptions\Api\UserNotPlaceholderApiException; | ||
use App\Http\Requests\V1\User\UserIndexRequest; | ||
use App\Http\Resources\V1\User\UserCollection; | ||
use App\Models\Organization; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Laravel\Jetstream\Contracts\InvitesTeamMembers; | ||
|
||
class UserController extends Controller | ||
{ | ||
/** | ||
* List all users in an organization | ||
* | ||
* @throws AuthorizationException | ||
*/ | ||
public function index(Organization $organization, UserIndexRequest $request): UserCollection | ||
{ | ||
$this->checkPermission($organization, 'users:view'); | ||
|
||
$users = $organization->users() | ||
->paginate(); | ||
|
||
return UserCollection::make($users); | ||
} | ||
|
||
/** | ||
* Invite a placeholder user to become a real user in the organization | ||
* | ||
* @throws AuthorizationException|UserNotPlaceholderApiException | ||
*/ | ||
public function invitePlaceholder(Organization $organization, User $user, Request $request): JsonResponse | ||
{ | ||
$this->checkPermission($organization, 'users:invite-placeholder'); | ||
|
||
if (! $user->is_placeholder) { | ||
throw new UserNotPlaceholderApiException(); | ||
} | ||
|
||
app(InvitesTeamMembers::class)->invite( | ||
$request->user(), | ||
$organization, | ||
$user->email, | ||
'employee' | ||
); | ||
|
||
return response()->json($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests\V1\User; | ||
|
||
use App\Models\Organization; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* @property Organization $organization | ||
*/ | ||
class UserIndexRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, array<string|ValidationRule>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
Oops, something went wrong.