Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions controllers/AbstractTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\tasks\models\forms\TaskFilter;
use humhub\modules\tasks\models\Task;
use humhub\modules\tasks\permissions\CreateTask;
use humhub\modules\tasks\permissions\ManageTasks;
use humhub\modules\tasks\traits\DataExport;
use Yii;
Expand All @@ -29,7 +28,7 @@ protected function getTaskById($id)

protected function canCreateTask()
{
return $this->contentContainer->can(CreateTask::class);
return (new Task($this->contentContainer))->content->canEdit();
}

protected function canManageTasks()
Expand Down
9 changes: 3 additions & 6 deletions controllers/rest/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use humhub\modules\tasks\helpers\RestDefinitions;
use humhub\modules\tasks\models\forms\TaskForm;
use humhub\modules\tasks\models\Task;
use humhub\modules\tasks\permissions\CreateTask;
use humhub\modules\tasks\permissions\ManageTasks;
use Yii;

class TasksController extends BaseContentController
Expand Down Expand Up @@ -57,8 +55,7 @@ public function actionCreate($containerId)
/** @var ContentContainerActiveRecord $container */
$container = $containerRecord->getPolymorphicRelation();

if (! in_array($container::class, Yii::$app->getModule('tasks')->getContentContainerTypes())
|| ! $container->permissionManager->can([CreateTask::class, ManageTasks::class])) {
if (!in_array($container::class, Yii::$app->getModule('tasks')->getContentContainerTypes())) {
return $this->returnError(403, 'You are not allowed to create task!');
}

Expand All @@ -72,8 +69,8 @@ public function actionCreate($containerId)
]);
$taskForm->createNew($container);

if (! $taskForm->task->content->canEdit()) {
return $this->returnError(403, 'You are not allowed to edit this task!');
if (!$taskForm->task->content->canEdit()) {
return $this->returnError(403, 'You are not allowed to create task!');
}

if ($this->saveTask($taskForm)) {
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.9.8 (Unreleased)
------------------
- Fix #256: Allow task creation via REST API and list button for users with "Manage All Content" permission

1.9.7 (September 8, 2026)
-------------------------
- Fix #329: Make action elements focusable in task list via keyboard
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"project",
"management"
],
"version": "1.9.7",
"version": "1.9.8",
"homepage": "https://github.com/humhub/tasks",
"humhub": {
"minVersion": "1.18.0-beta.6",
Expand Down
35 changes: 35 additions & 0 deletions tests/codeception/api/TaskCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Codeception\Util\HttpCode;
use tasks\ApiTester;
use tests\codeception\_support\HumHubApiTestCest;
use Yii;
use yii\web\UploadedFile;

class TaskCest extends HumHubApiTestCest
Expand Down Expand Up @@ -140,4 +141,38 @@ public function testTaskFiles(ApiTester $I)
$I->sendDelete('tasks/task/1/remove-file/2');
$I->seeNotFoundMessage('Could not find requested content record or file!');
}

public function testCreateTaskOnOtherUserProfile(ApiTester $I)
{
if (!$this->isRestModuleEnabled()) {
return;
}

$I->wantTo('create a task on profile of another user');

$I->amGoingTo('create a task as admin without "Manage All Content" permission');
Yii::$app->getModule('admin')->enableManageAllContentPermission = false;
$I->amAdmin();
$I->createTask('Task on User1 profile', 'Task content', ['containerId' => 2]);
$I->seeForbiddenMessage('You are not allowed to create task!');

$I->amGoingTo('create a task as admin with "Manage All Content" permission');
Yii::$app->getModule('admin')->enableManageAllContentPermission = true;
$I->createTask('Task on User1 profile', 'Task content', ['containerId' => 2]);
$I->seeLastCreatedTaskDefinition();
$I->seeResponseContainsJson(['content' => ['metadata' => ['contentcontainer_id' => 2]]]);
}

public function testCannotCreateTaskOnOtherUserProfileAsRegularUser(ApiTester $I)
{
if (!$this->isRestModuleEnabled()) {
return;
}

$I->wantTo('not create a task on profile of another user as regular user');
Yii::$app->getModule('admin')->enableManageAllContentPermission = true;
$I->amUser1();
$I->createTask('Task on User2 profile', 'Task content', ['containerId' => 3]);
$I->seeForbiddenMessage('You are not allowed to create task!');
}
}
Loading