Add internal note for staff invitations

This commit is contained in:
Ion Bazan
2024-10-30 11:14:48 +08:00
parent 437c8dcc88
commit 87e547b444
6 changed files with 86 additions and 1 deletions
+9 -1
View File
@@ -93,10 +93,18 @@ class CreateNewUser implements CreatesNewUsers
$user->emailUpdates()->create();
if (config('other.invite-only') === true) {
Invite::where('code', '=', $input['code'])->update([
$invite = Invite::where('code', '=', $input['code'])->withoutTrashed()->first();
$invite->update([
'accepted_by' => $user->id,
'accepted_at' => now(),
]);
if ($invite->internal_note !== null) {
$user->notes()->create([
'message' => $invite->internal_note,
'staff_id' => $invite->user_id,
]);
}
}
// Select A Random Welcome Message
@@ -102,6 +102,7 @@ class InviteController extends Controller
$request->validate([
'bail',
'message' => 'required',
'internal_note' => Rule::unless($user->group->is_modo, 'missing'),
'email' => [
'required',
'string',
@@ -120,6 +121,7 @@ class InviteController extends Controller
'user_id' => $user->id,
'email' => $request->input('email'),
'code' => Uuid::uuid4()->toString(),
'internal_note' => $request->input('internal_note'),
'expires_on' => now()->addDays(config('other.invite_expire')),
'custom' => $request->input('message'),
]);
+1
View File
@@ -32,6 +32,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int|null $accepted_by
* @property string|null $accepted_at
* @property string|null $custom
* @property string|null $internal_note
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
@@ -0,0 +1,28 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('invites', static function (Blueprint $table): void {
$table->text('internal_note')->nullable()->after('custom');
});
}
};
@@ -69,6 +69,18 @@
{{ __('common.message') }}
</label>
</p>
@if ($user->group->is_modo)
<p class="form__group">
<textarea
id="internal_note"
class="form__textarea"
name="internal_note"
></textarea>
<label class="form__label form__label--floating" for="internal_note">
{{ __('ticket.staff-notes') }}
</label>
</p>
@endif
<p class="form__group">
<button class="form__button form__button--filled">
{{ __('common.submit') }}
@@ -181,6 +181,40 @@ test('store returns an ok response', function (): void {
]);
});
test('store with internal note as staff user', function (): void {
$group = Group::factory()->create(['is_modo' => true, 'can_invite' => true]);
$user = User::factory()->for($group)->create([
'can_invite' => 1,
'invites' => 1,
'two_factor_confirmed_at' => now(),
]);
$inviteEmail = 'test@unit3d.dev';
config(['other' => [
'invites_restriced' => true,
'invite_groups' => [$group->name],
],
'email-blacklist.enabled' => false,
]);
Mail::fake();
$response = $this->actingAs($user)->post(route('users.invites.store', [$user]), [
'email' => $inviteEmail,
'message' => 'Test Invite',
'internal_note' => 'Test Internal Note',
]);
$response->assertRedirect();
$this->assertDatabaseHas('invites', [
'user_id' => $user->id,
'email' => $inviteEmail,
'internal_note' => 'Test Internal Note',
]);
});
test('store aborts with a 403', function (): void {
$this->markTestIncomplete('This test case was generated by Shift. When you are ready, remove this line and complete this test case.');