Skip to content

Commit

Permalink
fix: migrate ticket read statuses to booleans
Browse files Browse the repository at this point in the history
They were previously nullable tiny ints, but they are only used as booleans.

There are no other cases where tiny ints are used as booleans and are missing the `(1)` display width.
  • Loading branch information
Roardom committed Feb 17, 2025
1 parent cff21fe commit 225de87
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/TicketAssigneeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final public function store(StoreTicketAssigneeRequest $request, Ticket $ticket)

$ticket->update([
'staff_id' => $request->staff_id,
'staff_read' => 0,
'staff_read' => false,
]);

return to_route('tickets.show', ['ticket' => $ticket])
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ final public function show(Request $request, Ticket $ticket): \Illuminate\Contra
abort_unless($request->user()->group->is_modo || $request->user()->id === $ticket->user_id, 403);

if ($request->user()->id === $ticket->user_id) {
$ticket->user_read = 1;
$ticket->user_read = true;
}

if ($request->user()->id === $ticket->staff_id) {
$ticket->staff_read = 1;
$ticket->staff_read = true;
}

$ticket->save();
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ final public function postReply(): void

if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) {
User::find($ticket->staff_id)->notify(new NewComment($this->model, $reply));
$this->model->update(['staff_read' => false]);
}

if ($this->user->id !== $ticket->user_id) {
User::find($ticket->user_id)->notify(new NewComment($this->model, $reply));
$this->model->update(['user_read' => false]);
}

if (!\in_array($this->comment->user_id, [$ticket->staff_id, $ticket->user_id, $this->user->id])) {
Expand Down
8 changes: 5 additions & 3 deletions app/Models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* @property int $category_id
* @property int $priority_id
* @property int|null $staff_id
* @property int|null $user_read
* @property int|null $staff_read
* @property bool $user_read
* @property bool $staff_read
* @property string $subject
* @property string $body
* @property \Illuminate\Support\Carbon|null $closed_at
Expand All @@ -51,11 +51,13 @@ class Ticket extends Model
/**
* Get the attributes that should be cast.
*
* @return array{closed_at: 'datetime', reminded_at: 'datetime'}
* @return array{user_read: 'bool', staff_read: 'bool', closed_at: 'datetime', reminded_at: 'datetime'}
*/
protected function casts(): array
{
return [
'user_read' => 'bool',
'staff_read' => 'bool',
'closed_at' => 'datetime',
'reminded_at' => 'datetime',
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* 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 Roardom <roardom@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('tickets', function (Blueprint $table): void {
$table->boolean('user_read')->default(false)->change();
$table->boolean('staff_read')->default(false)->change();
});
}
};
4 changes: 2 additions & 2 deletions resources/views/livewire/ticket-search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class="panel__tab panel__tab--full-width"
{{ $ticket->subject }}
</a>
@if ((auth()->user()->group->is_modo &&
(($ticket->staff_id === auth()->id() && $ticket->staff_read === 0) ||
(($ticket->staff_id === auth()->id() && $ticket->staff_read === false) ||
($ticket->staff_id === null && $ticket->closed_at === null))) ||
($ticket->user_id === auth()->id() && $ticket->user_read === 0))
($ticket->user_id === auth()->id() && $ticket->user_read === false))
<i
style="color: #0dffff; vertical-align: 1px"
class="fas fa-circle fa-xs"
Expand Down

0 comments on commit 225de87

Please sign in to comment.