-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:Timetracking-Project/timetracking i…
…nto feature/jetstream_typescript_support # Conflicts: # composer.json # composer.lock # resources/js/Layouts/AppLayout.vue # resources/js/Pages/Teams/Partials/DeleteTeamForm.vue # resources/js/Pages/Teams/Partials/TeamMemberManager.vue
- Loading branch information
Showing
69 changed files
with
1,853 additions
and
362 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
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,11 @@ | ||
name: PHP Linting | ||
on: push | ||
jobs: | ||
pint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: "laravel-pint" | ||
uses: aglipanci/[email protected] | ||
with: | ||
configPath: "pint.json" |
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
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,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Jetstream; | ||
|
||
use App\Models\Organization; | ||
use App\Models\OrganizationInvitation; | ||
use App\Models\User; | ||
use Closure; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Facades\Validator; | ||
use Korridor\LaravelModelValidationRules\Rules\UniqueEloquent; | ||
use Laravel\Jetstream\Contracts\InvitesTeamMembers; | ||
use Laravel\Jetstream\Events\InvitingTeamMember; | ||
use Laravel\Jetstream\Jetstream; | ||
use Laravel\Jetstream\Mail\TeamInvitation; | ||
use Laravel\Jetstream\Rules\Role; | ||
|
||
class InviteOrganizationMember implements InvitesTeamMembers | ||
{ | ||
/** | ||
* Invite a new team member to the given team. | ||
*/ | ||
public function invite(User $user, Organization $organization, string $email, ?string $role = null): void | ||
{ | ||
Gate::forUser($user)->authorize('addTeamMember', $organization); | ||
|
||
$this->validate($organization, $email, $role); | ||
|
||
InvitingTeamMember::dispatch($organization, $email, $role); | ||
|
||
$invitation = $organization->teamInvitations()->create([ | ||
'email' => $email, | ||
'role' => $role, | ||
]); | ||
|
||
Mail::to($email)->send(new TeamInvitation($invitation)); | ||
} | ||
|
||
/** | ||
* Validate the invite member operation. | ||
*/ | ||
protected function validate(Organization $organization, string $email, ?string $role): void | ||
{ | ||
Validator::make([ | ||
'email' => $email, | ||
'role' => $role, | ||
], $this->rules($organization), [ | ||
'email.unique' => __('This user has already been invited to the team.'), | ||
])->after( | ||
$this->ensureUserIsNotAlreadyOnTeam($organization, $email) | ||
)->validateWithBag('addTeamMember'); | ||
} | ||
|
||
/** | ||
* Get the validation rules for inviting a team member. | ||
* | ||
* @return array<string, ValidationRule|array|string> | ||
*/ | ||
protected function rules(Organization $organization): array | ||
{ | ||
return array_filter([ | ||
'email' => [ | ||
'required', | ||
'email', | ||
new UniqueEloquent(OrganizationInvitation::class, 'email', function (Builder $builder) use ($organization) { | ||
/** @var Builder<OrganizationInvitation> $builder */ | ||
return $builder->whereBelongsTo($organization, 'organization'); | ||
}), | ||
], | ||
'role' => Jetstream::hasRoles() | ||
? ['required', 'string', new Role] | ||
: null, | ||
]); | ||
} | ||
|
||
/** | ||
* Ensure that the user is not already on the team. | ||
*/ | ||
protected function ensureUserIsNotAlreadyOnTeam(Organization $organization, string $email): Closure | ||
{ | ||
return function ($validator) use ($organization, $email) { | ||
$validator->errors()->addIf( | ||
$organization->hasUserWithEmail($email), | ||
'email', | ||
__('This user already belongs to the team.') | ||
); | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.