Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/Domain/Tickets/Services/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1589,14 +1589,15 @@ public function quickAddMilestone(array $params): array|bool|int
*/
public function addTicket($values): array|int|bool
{
$userId = $values['userId'] ?? session('userdata.id');
$values = [
'id' => '',
'headline' => $values['headline'] ?? '',
'type' => $values['type'] ?? 'task',
'description' => $values['description'] ?? '',
'projectId' => $values['projectId'] ?? session('currentProject'),
'editorId' => $values['editorId'] ?? '',
'userId' => session('userdata.id'),
'userId' => $userId,
'date' => gmdate('Y-m-d H:i:s'),
'dateToFinish' => $values['dateToFinish'] ?? '',
'timeToFinish' => $values['timeToFinish'] ?? '',
Expand All @@ -1616,7 +1617,7 @@ public function addTicket($values): array|int|bool
'milestoneid' => $values['milestoneid'] ?? '',
];

if (! $this->projectService->isUserAssignedToProject(session('userdata.id'), $values['projectId'])) {
if (! $this->projectService->isUserAssignedToProject($userId, $values['projectId'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this approach is that is completely circumvents the roles, permissions and projects assigned to an API Key. Devs could just set the userId to any administrator and act on behalf of that admin.

return ['msg' => 'notifications.ticket_save_error_no_access', 'type' => 'error'];
}

Expand Down Expand Up @@ -1645,7 +1646,7 @@ public function addTicket($values): array|int|bool
$notification->module = 'tickets';
$notification->projectId = $values['projectId'] ?? session('currentProject') ?? -1;
$notification->subject = $subject;
$notification->authorId = session('userdata.id') ?? -1;
$notification->authorId = $userId ?? -1;
$notification->message = $message;

$this->projectService->notifyProjectUsers($notification);
Expand Down Expand Up @@ -1692,6 +1693,7 @@ public function addTicket($values): array|int|bool
*/
public function updateTicket($values): array|bool
{
$userId = $values['userId'] ?? session('userdata.id');
if (! isset($values['headline'])) {
$currentTicket = $this->getTicket($values['id']);

Expand Down Expand Up @@ -1732,7 +1734,7 @@ public function updateTicket($values): array|bool
return ['msg' => 'project id is not set', 'type' => 'error'];
}

if (! $this->projectService->isUserAssignedToProject(session('userdata.id'), $values['projectId'])) {
if (! $this->projectService->isUserAssignedToProject($userId, $values['projectId'])) {
return ['msg' => 'notifications.ticket_save_error_no_access', 'type' => 'error'];
}

Expand All @@ -1753,7 +1755,7 @@ public function updateTicket($values): array|bool
$notification->module = 'tickets';
$notification->projectId = $values['projectId'] ?? session('currentProject') ?? -1;
$notification->subject = $subject;
$notification->authorId = session('userdata.id') ?? -1;
$notification->authorId = $userId ?? -1;
$notification->message = $message;

$this->projectService->notifyProjectUsers($notification);
Expand Down