allows('view', $comment->file)) { return false; } return $this->scope->for($user, $comment->file)->whereKey($comment->getKey())->exists(); } /** * Editing is the author's alone, inside a short window. Moderators are * deliberately excluded: deleting somebody's comment is moderation, * rewriting their words is not, and no permission in this app should * imply the latter. */ public function update(User $user, FileComment $comment): bool { return $comment->author_id === $user->id && $this->withinEditWindow($comment); } public function delete(User $user, FileComment $comment): bool { if ($this->moderate($user)) { return true; } return $comment->author_id === $user->id && $this->withinEditWindow($comment); } public function moderate(User $user): bool { return $user->isStaff() && $user->can('moderate_comments'); } private function withinEditWindow(FileComment $comment): bool { $minutes = $this->rules->editWindowMinutes(); if ($minutes <= 0) { return false; } return $comment->created_at !== null && $comment->created_at->diffInMinutes(now()) < $minutes; } }