mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-18 23:42:04 -05:00
Update: Rework to conform to project code styling.
- Use Inline Model Syntax - Divide the functionality of revive from resend, requiring the user to explicitly Resend the invite. - Inline Blade Logic to remove @php ... @endphp block - Add 'revive' endpoint for Invites. - Add missing default translations
This commit is contained in:
@@ -160,50 +160,21 @@ class InviteController extends Controller
|
||||
*/
|
||||
public function send(Request $request, User $user, Invite $sentInvite): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$isModo = $request->user()->group->is_modo;
|
||||
|
||||
abort_unless($isModo || ($request->user()->is($user) && ($user->can_invite ?? $user->group->can_invite)), 403);
|
||||
abort_unless($request->user()->group->is_modo || ($request->user()->is($user) && ($user->can_invite ?? $user->group->can_invite)), 403);
|
||||
|
||||
if ($sentInvite->accepted_by !== null) {
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-already-used'));
|
||||
|
||||
}
|
||||
|
||||
if ($sentInvite->deleted_at !== null) {
|
||||
|
||||
if ($isModo && config('other.modo_revive_deleted_invites')) {
|
||||
|
||||
$sentInvite->expires_on = now()->addDays(config('other.invite_expire'));
|
||||
$sentInvite->deleted_at = null;
|
||||
$sentInvite->internal_note .= (!empty($sentInvite->internal_note)? PHP_EOL : '').
|
||||
"Invite Revived by Modo ".$request->user()->username." @ ". now()->toDateString() . PHP_EOL ;
|
||||
$sentInvite->save();
|
||||
|
||||
} else {
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-deleted'));
|
||||
|
||||
}
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-deleted'));
|
||||
}
|
||||
|
||||
if ($sentInvite->expires_on < now()) {
|
||||
|
||||
if($isModo && config('other.modo_revive_expired_invites')) {
|
||||
|
||||
$sentInvite->expires_on = now()->addDays(config('other.invite_expire'));
|
||||
$sentInvite->save();
|
||||
|
||||
} else {
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-expired'));
|
||||
|
||||
}
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-expired'));
|
||||
}
|
||||
|
||||
Mail::to($sentInvite->email)->send(new InviteUser($sentInvite));
|
||||
@@ -211,4 +182,25 @@ class InviteController extends Controller
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withSuccess(trans('user.invite-resent-success'));
|
||||
}
|
||||
|
||||
public function revive(Request $request, User $user, Invite $sentInvite): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->group->is_modo && (config('other.modo_revive_expired_invites') || config('other.modo_revive_deleted_invites')), 403);
|
||||
|
||||
if (($sentInvite->deleted_at !== null && config('other.modo_revive_deleted_invites')) ||
|
||||
($sentInvite->expires_on < now() && config('other.modo_revive_expired_invites'))) {
|
||||
$sentInvite->update(
|
||||
[
|
||||
'expires_on' => now()->addDays(config('other.invite_expire')),
|
||||
'deleted_at' => null,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withErrors(trans('user.invite-revive-failed'));
|
||||
}
|
||||
|
||||
return to_route('users.invites.index', ['user' => $user])
|
||||
->withSuccess(trans('user.invite-revive-success'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +125,9 @@ return [
|
||||
'invite-only' => true,
|
||||
'invite_expire' => 14,
|
||||
|
||||
/* Allow Modo Staff to Revive (Restore, Renew & Resend) Deleted Invites */
|
||||
/* Allow Modo Staff to Revive (Restore & Renew) Deleted Invites */
|
||||
'modo_revive_deleted_invites' => true,
|
||||
/* Allow Modo Staff to Revive (Restore, Renew & Resend) Expired Invites */
|
||||
/* Allow Modo Staff to Revive (Restore & Renew) Expired Invites */
|
||||
'modo_revive_expired_invites' => true,
|
||||
|
||||
'invites_restriced' => false,
|
||||
|
||||
@@ -156,6 +156,8 @@ return [
|
||||
'invite-expired' => 'The invite you are trying to resend has expired.',
|
||||
'invite-friend' => 'Invite your friend (Email + Message Required)',
|
||||
'invite-resent-success' => 'Invite was resent successfully!',
|
||||
'invite-revive-success' => 'Invite was revived successfully!',
|
||||
'invite-revive-failed' => 'Invite was not able to be revived.',
|
||||
'invite-sent-success' => 'Invite was sent successfully!',
|
||||
'invite-tree' => 'Invite Tree',
|
||||
'invites' => 'Invites',
|
||||
|
||||
@@ -107,39 +107,41 @@
|
||||
<td>
|
||||
<menu class="data-table__actions">
|
||||
<li class="data-table__action">
|
||||
@php
|
||||
$revive =
|
||||
$invite->accepted_at === null &&
|
||||
(($invite->deleted_at !== null && config('other.modo_revive_deleted_invites')) ||
|
||||
($invite->expires_on < now() && config('other.modo_revive_expired_invites'))) &&
|
||||
auth()->user()->group->is_modo;
|
||||
@endphp
|
||||
|
||||
<form
|
||||
action="{{ route('users.invites.send', ['user' => $user, 'sentInvite' => $invite]) }}"
|
||||
method="POST"
|
||||
x-data="confirmation"
|
||||
>
|
||||
@csrf
|
||||
@if ($revive)
|
||||
@if ($invite->accepted_at === null &&
|
||||
(($invite->deleted_at !== null && config('other.modo_revive_deleted_invites')) ||
|
||||
($invite->expires_on < now() && config('other.modo_revive_expired_invites'))) &&
|
||||
auth()->user()->group->is_modo)
|
||||
<form
|
||||
action="{{ route('users.invites.revive', ['user' => $user, 'sentInvite' => $invite]) }}"
|
||||
method="POST"
|
||||
x-data="confirmation"
|
||||
>
|
||||
@csrf
|
||||
<button
|
||||
x-on:click.prevent="confirmAction"
|
||||
data-b64-deletion-message="{{ base64_encode('Are you sure you want to revive the invite for ' . $invite->email . ' and resend it?') }}"
|
||||
data-b64-deletion-message="{{ base64_encode('Are you sure you want to revive the invite for ' . $invite->email .'?') }}"
|
||||
class="form__button form__button--text"
|
||||
>
|
||||
{{ __('common.revive') }}
|
||||
</button>
|
||||
@else
|
||||
</form>
|
||||
@else
|
||||
<form
|
||||
action="{{ route('users.invites.send', ['user' => $user, 'sentInvite' => $invite]) }}"
|
||||
method="POST"
|
||||
x-data="confirmation"
|
||||
>
|
||||
@csrf
|
||||
<button
|
||||
x-on:click.prevent="confirmAction"
|
||||
data-b64-deletion-message="{{ base64_encode('Are you sure you want to resend the email to: ' . $invite->email . '?') }}"
|
||||
data-b64-deletion-message="{{ base64_encode('Are you sure you want to resend the invite email to ' . $invite->email . '?') }}"
|
||||
class="form__button form__button--text"
|
||||
@disabled($invite->accepted_at !== null || $invite->expires_on < now() || $invite->deleted_at !== null)
|
||||
>
|
||||
{{ __('common.resend') }}
|
||||
</button>
|
||||
@endif
|
||||
</form>
|
||||
</form>
|
||||
@endif
|
||||
</li>
|
||||
<li class="data-table__action">
|
||||
<form
|
||||
|
||||
@@ -511,7 +511,8 @@ Route::middleware('language')->group(function (): void {
|
||||
Route::prefix('invites')->name('invites.')->group(function (): void {
|
||||
Route::get('/create', [App\Http\Controllers\User\InviteController::class, 'create'])->name('create');
|
||||
Route::post('/store', [App\Http\Controllers\User\InviteController::class, 'store'])->name('store');
|
||||
Route::post('/{sentInvite}/send', [App\Http\Controllers\User\InviteController::class, 'send'])->name('send')->withTrashed();
|
||||
Route::post('/{sentInvite}/send', [App\Http\Controllers\User\InviteController::class, 'send'])->name('send');
|
||||
Route::post('/{sentInvite}/revive', [App\Http\Controllers\User\InviteController::class, 'revive'])->name('revive')->withTrashed();
|
||||
Route::delete('/{sentInvite}', [App\Http\Controllers\User\InviteController::class, 'destroy'])->name('destroy')->withTrashed();
|
||||
Route::get('/', [App\Http\Controllers\User\InviteController::class, 'index'])->name('index')->withTrashed();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user