Files
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

57 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Comments\Http\Resources\Api;
use App\Modules\Comments\Models\FileComment;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin FileComment
*
* Every field is listed explicitly, never $comment->toArray(): that would
* publish whatever the next migration adds. Two columns are held back on
* purpose:
*
* - `ip_address` is recorded for anonymous comments so repeat spam can be
* acted on. It is personal data collected for moderation, and an
* integration reading a thread has no business with it.
* - `client_context_id` is which client's conversation a comment belongs
* to. It is surfaced as `thread` below, and only to tokens whose owner
* is staff — which every API token is today, but stating the rule here
* means it survives a future client-facing token.
*/
class FileCommentResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$viewer = $request->user();
return [
'id' => $this->id,
'file_id' => $this->file_id,
'body' => $this->body,
'visibility' => $this->visibility->value,
'author' => [
'id' => $this->author_id,
'name' => $this->authorName(),
'type' => $this->author_id === null ? 'guest' : ($this->author?->isStaff() === true ? 'staff' : 'client'),
],
// Whose conversation this is, when it is one client's rather
// than every client's. Staff only, and null on a comment
// addressed to all of them.
'conversation' => $viewer?->isStaff() === true && $this->client_context_id !== null
? ['client_id' => $this->client_context_id, 'client_name' => $this->clientContext?->name]
: null,
'approved' => ! $this->isPending(),
'created_at' => $this->created_at?->toIso8601String(),
'edited_at' => $this->edited_at?->toIso8601String(),
];
}
}