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 @@

Responses

Response samples

Content type
application/json
{
  • "total": 76,
  • "page": 1,
  • "pages": 8,
  • "links": {
    },
  • "results": [
    ]
}

Get content by id

path Parameters
id
required
integer

The id of the content

+

Response samples

Content type
application/json
{
  • "total": 76,
  • "page": 1,
  • "pages": 8,
  • "links": {
    },
  • "results": [
    ]
}

Get content by id

path Parameters
id
required
integer

The id of the content

Responses

Response samples

Content type
application/json
{
  • "metadata": {
    },
  • "comments": {
    },
  • "likes": {
    },
  • "files": {},
  • "topics": [
    ]
}

Deletes a content by id

path Parameters
id
required
integer

The id of content

+

Response samples

Content type
application/json
{
  • "metadata": {
    },
  • "comments": {
    },
  • "likes": {
    },
  • "files": {},
  • "topics": [
    ]
}

Deletes a content by id

path Parameters
id
required
integer

The id of content

Responses

Container

API to access and manage content containers.

@@ -410,7 +410,7 @@

Response samples

Content type
application/json
{
  • "total": 76,
  • "page": 1,
  • "pages": 8,
  • "links": {
    },
  • "results": [
    ]
}

Tags

Group API