diff --git a/components/BaseContentController.php b/components/BaseContentController.php index f227264..23a8e06 100644 --- a/components/BaseContentController.php +++ b/components/BaseContentController.php @@ -21,6 +21,7 @@ use humhub\modules\topic\models\Topic; use humhub\modules\topic\permissions\AddTopic; use Yii; +use yii\base\DynamicModel; use yii\web\HttpException; use yii\web\UploadedFile; @@ -30,6 +31,7 @@ * * @package humhub\modules\rest\components */ + abstract class BaseContentController extends BaseController { /** @@ -396,6 +398,10 @@ protected function updateMetadata(ContentActiveRecord $activeRecord, array $data return false; } + if (!$this->updateScheduledAt($activeRecord, $data['metadata'])) { + return false; + } + return true; } @@ -482,4 +488,27 @@ protected function updateLockedComments(ContentActiveRecord $activeRecord, array $activeRecord->content->locked_comments = $data['locked_comments']; return $activeRecord->content->save(); } -} \ No newline at end of file + + protected function updateScheduledAt(ContentActiveRecord $activeRecord, array $data): bool + { + if (!isset($data['scheduled_at'])) { + return true; + } + + $validator = DynamicModel::validateData([ + 'scheduled_at' => $data['scheduled_at'] + ], [ + ['scheduled_at', 'datetime', 'format' => 'php:Y-m-d H:i:s'] + ]); + + if (!$validator->validate()) { + $activeRecord->addError('scheduled_at', $validator->getFirstError('scheduled_at')); + + return false; + } + + $activeRecord->content->getStateService()->schedule($data['scheduled_at']); + + return $activeRecord->content->save(); + } +} diff --git a/components/auth/JwtAuth.php b/components/auth/JwtAuth.php index e0a2edc..2310307 100644 --- a/components/auth/JwtAuth.php +++ b/components/auth/JwtAuth.php @@ -10,6 +10,7 @@ use yii\filters\auth\HttpBearerAuth; use Exception; use Firebase\JWT\JWT; +use Firebase\JWT\Key; use humhub\modules\rest\models\JwtAuthForm; use humhub\modules\user\models\User; @@ -23,7 +24,7 @@ public function authenticate($user, $request, $response) $token = $matches[1]; try { - $validData = JWT::decode($token, JwtAuthForm::getInstance()->jwtKey, ['HS512']); + $validData = JWT::decode($token, new Key(JwtAuthForm::getInstance()->jwtKey, 'HS512')); if ( !empty($validData->uid) && ($identity = User::find()->active()->andWhere(['user.id' => $validData->uid])->one()) && diff --git a/controllers/post/PostController.php b/controllers/post/PostController.php index 5e2a2fd..918c488 100644 --- a/controllers/post/PostController.php +++ b/controllers/post/PostController.php @@ -7,6 +7,7 @@ namespace humhub\modules\rest\controllers\post; + use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\post\models\Post; use humhub\modules\rest\components\BaseContentController; diff --git a/definitions/ContentDefinitions.php b/definitions/ContentDefinitions.php index 6de67e4..8e927b0 100644 --- a/definitions/ContentDefinitions.php +++ b/definitions/ContentDefinitions.php @@ -42,13 +42,16 @@ public static function getContentMetadata(Content $content) 'object_model' => $content->object_model, 'object_id' => $content->object_id, 'visibility' => (int) $content->visibility, + 'state' => (int) $content->state, 'archived' => (bool) $content->archived, + 'hidden' => (bool) $content->hidden, 'pinned' => (bool) $content->pinned, 'locked_comments' => (bool) $content->locked_comments, 'created_by' => $content->createdBy ? UserDefinitions::getUserShort($content->createdBy) : null, 'created_at' => $content->created_at, 'updated_by' => $content->updatedBy ? UserDefinitions::getUserShort($content->updatedBy) : null, 'updated_at' => $content->updated_at, + 'scheduled_at' => $content->scheduled_at, 'url' => $content->getUrl(true), 'contentcontainer_id' => $content->contentcontainer_id, 'stream_channel' => $content->stream_channel diff --git a/docs/html/content.html b/docs/html/content.html index 166c65c..7345bd1 100644 --- a/docs/html/content.html +++ b/docs/html/content.html @@ -396,11 +396,11 @@
{- "total": 76,
- "page": 1,
- "pages": 8,
- "links": {
- "self": "{endpoint_path}?page=1&per-page=10",
- "next": "{endpoint_path}?page=2&per-page=10",
- "last": "{endpoint_path}?page=8&per-page=10"
}, - "results": [
- {
- "metadata": {
- "id": 14,
- "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
- "object_model": "humhub\\modules\\post\\models\\Post",
- "object_id": 12,
- "visibility": 1,
- "archived": true,
- "pinned": false,
- "locked_comments": false,
- "created_by": {
- "id": 14,
- "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
- "display_name": "John Doe",
}, - "created_at": "2022-04-13 05:15:43",
- "updated_by": {
- "id": 14,
- "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
- "display_name": "John Doe",
}, - "updated_at": "2022-05-21 06:20:18",
- "contentcontainer_id": 5,
- "stream_channel": "default"
}, - "comments": {
- "total": 55,
- "latestComments": [
- {
- "id": 14,
- "message": "Calvin Klein – Between love and madness lies obsession.",
- "objectModel": "humhub\\modules\\post\\models\\Post",
- "objectId": 123,
- "createdBy": {
- "id": 14,
- "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
- "display_name": "John Doe",
}, - "createdAt": "2018-08-09 14:22:03",
- "commentsCount": 5,
- "comments": [
- { }
]
}
]
}, - "likes": {
- "total": 35
}, - "files": {
- "id": 14,
- "guid": "bded6dc7-e6f4-417e-a638-b653525529ca",
- "mime_type": "text/plain",
- "size": 14353,
- "file_name": "image.jpg",
}, - "topics": [
- {
- "id": 135,
- "name": "News"
}
]
}
]
}