From b6d74b39a37b5aaa259f0286b8a1c5932c187b00 Mon Sep 17 00:00:00 2001 From: buddh4 Date: Tue, 28 Mar 2017 17:36:06 +0200 Subject: [PATCH] Enh: Added Make Private/ Make Public link to wall entry controls Fix: Wallentry loader + badge render issue --- protected/humhub/docs/CHANGELOG.md | 1 + protected/humhub/modules/content/Events.php | 1 + .../content/controllers/ContentController.php | 50 ++++++++++++++----- .../humhub/modules/content/models/Content.php | 19 ++++--- .../content/widgets/VisibilityLink.php | 47 +++++++++++++++++ .../content/widgets/views/archiveLink.php | 6 +-- .../content/widgets/views/editLink.php | 33 ++++++------ .../modules/content/widgets/views/labels.php | 26 +++++----- .../content/widgets/views/visibilityLink.php | 18 +++++++ .../stream/resources/js/humhub.stream.js | 33 +++++++++--- 10 files changed, 177 insertions(+), 57 deletions(-) create mode 100644 protected/humhub/modules/content/widgets/VisibilityLink.php create mode 100644 protected/humhub/modules/content/widgets/views/visibilityLink.php diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 5941c6a682..4f3dd55325 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -25,6 +25,7 @@ HumHub Change Log - Fix: Default stream sort setting not applied - Enh: Show different login message, when registration is disabled - Fix: Norwegian translation code for Yii messages +- Enh: Added Make Private/ Make Public link to wall entry controls 1.2.0-beta.3 (March 20, 2017) diff --git a/protected/humhub/modules/content/Events.php b/protected/humhub/modules/content/Events.php index 439b6e7546..ab4cedd7b5 100644 --- a/protected/humhub/modules/content/Events.php +++ b/protected/humhub/modules/content/Events.php @@ -74,6 +74,7 @@ class Events extends \yii\base\Object $content = $event->sender->object; $stackWidget->addWidget(widgets\DeleteLink::className(), ['content' => $content], ['sortOrder' => 100]); + $stackWidget->addWidget(widgets\VisibilityLink::className(), ['contentRecord' => $content], ['sortOrder' => 250]); $stackWidget->addWidget(widgets\NotificationSwitchLink::className(), ['content' => $content], ['sortOrder' => 300]); $stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content], ['sortOrder' => 400] ); $stackWidget->addWidget(widgets\PinLink::className(), ['content' => $content], ['sortOrder' => 500]); diff --git a/protected/humhub/modules/content/controllers/ContentController.php b/protected/humhub/modules/content/controllers/ContentController.php index ce375b69d3..ace9d32bad 100644 --- a/protected/humhub/modules/content/controllers/ContentController.php +++ b/protected/humhub/modules/content/controllers/ContentController.php @@ -12,6 +12,7 @@ use Yii; use yii\web\HttpException; use humhub\components\Controller; use humhub\modules\content\models\Content; +use humhub\modules\content\permissions\CreatePublicContent; /** * ContentController is responsible for basic content objects. @@ -110,7 +111,6 @@ class ContentController extends Controller */ public function actionUnarchive() { - Yii::$app->response->format = 'json'; $this->forcePostRequest(); $json = array(); @@ -125,7 +125,39 @@ class ContentController extends Controller $json['success'] = true; } - return $json; + return $this->asJson($json); + } + + /** + * Switches the content visibility for the given content. + * + * @param type $id content id + * @return \yii\web\Response + * @throws HttpException + */ + public function actionToggleVisibility($id) + { + $this->forcePostRequest(); + $content = Content::findOne(['id' => $id]); + + if(!$content) { + throw new HttpException(400, Yii::t('ContentController.base', 'Invalid content id given!')); + } elseif(!$content->canEdit()) { + throw new HttpException(403); + } elseif($content->isPrivate() && !$content->container->permissionManager->can(new CreatePublicContent())) { + throw new HttpException(403); + } + + if($content->isPrivate()) { + $content->visibility = Content::VISIBILITY_PUBLIC; + } else { + $content->visibility = Content::VISIBILITY_PRIVATE; + } + + return $this->asJson([ + 'success' => $content->save(), + 'state' => $content->visibility + ]); } /** @@ -135,8 +167,6 @@ class ContentController extends Controller */ public function actionPin() { - Yii::$app->response->format = 'json'; - $this->forcePostRequest(); $json = array(); @@ -156,7 +186,7 @@ class ContentController extends Controller $json['error'] = Yii::t('ContentModule.controllers_ContentController', "Could not load requested object!"); } - return $json; + return $this->asJson($json); } /** @@ -166,11 +196,9 @@ class ContentController extends Controller */ public function actionUnPin() { - Yii::$app->response->format = 'json'; - $this->forcePostRequest(); - $json = array(); + $json = []; $json['success'] = false; $content = Content::findOne(['id' => Yii::$app->request->get('id', "")]); @@ -179,13 +207,11 @@ class ContentController extends Controller $json['success'] = true; } - return $json; + return $this->asJson($json); } public function actionNotificationSwitch() { - Yii::$app->response->format = 'json'; - $this->forcePostRequest(); $json = array(); @@ -199,7 +225,7 @@ class ContentController extends Controller $json['success'] = true; } - return $json; + return $this->asJson($json); } } diff --git a/protected/humhub/modules/content/models/Content.php b/protected/humhub/modules/content/models/Content.php index 54446126ba..0eb92b3988 100644 --- a/protected/humhub/modules/content/models/Content.php +++ b/protected/humhub/modules/content/models/Content.php @@ -220,18 +220,23 @@ class Content extends ContentDeprecated } /** - * Returns the public state of the contect object + * Checks if the content visiblity is set to public. * * @return boolean */ public function isPublic() { - - if ($this->visibility == self::VISIBILITY_PUBLIC) { - return true; - } - - return false; + return $this->visibility === self::VISIBILITY_PUBLIC; + } + + /** + * Checks if the content visiblity is set to private. + * + * @return boolean + */ + public function isPrivate() + { + return $this->visibility === self::VISIBILITY_PRIVATE; } /** diff --git a/protected/humhub/modules/content/widgets/VisibilityLink.php b/protected/humhub/modules/content/widgets/VisibilityLink.php new file mode 100644 index 0000000000..9d825c727c --- /dev/null +++ b/protected/humhub/modules/content/widgets/VisibilityLink.php @@ -0,0 +1,47 @@ +contentRecord->content; + $contentContainer = $content->container; + + if(!$content->canEdit()) { + return; + } else if($content->isPrivate() && !$contentContainer->permissionManager->can(new CreatePublicContent())) { + return; + } + + return $this->render('visibilityLink', [ + 'content' => $content, + 'toggleLink' => Url::to(['/content/content/toggle-visibility', 'id' => $content->id]) + ]); + } +} \ No newline at end of file diff --git a/protected/humhub/modules/content/widgets/views/archiveLink.php b/protected/humhub/modules/content/widgets/views/archiveLink.php index c09d98c6bf..2d15a64c33 100644 --- a/protected/humhub/modules/content/widgets/views/archiveLink.php +++ b/protected/humhub/modules/content/widgets/views/archiveLink.php @@ -10,11 +10,11 @@ $unarchiveLink = Url::to(['/content/content/unarchive', 'id' => $id]);
  • content->isArchived()): ?> - + - + - +
  • diff --git a/protected/humhub/modules/content/widgets/views/editLink.php b/protected/humhub/modules/content/widgets/views/editLink.php index efdfdce555..e202d4024a 100644 --- a/protected/humhub/modules/content/widgets/views/editLink.php +++ b/protected/humhub/modules/content/widgets/views/editLink.php @@ -6,19 +6,20 @@ use humhub\modules\content\widgets\WallEntry; ?>
  • - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
  • diff --git a/protected/humhub/modules/content/widgets/views/labels.php b/protected/humhub/modules/content/widgets/views/labels.php index 4e6a4cb8f0..ab0982ebb3 100644 --- a/protected/humhub/modules/content/widgets/views/labels.php +++ b/protected/humhub/modules/content/widgets/views/labels.php @@ -11,18 +11,20 @@ use humhub\modules\post\models\Post; * @since 0.5 */ ?> -content->isPinned()) : ?> - - + + content->isPinned()) : ?> + + -content->isArchived()) : ?> - - + content->isArchived()) : ?> + + -content->isPublic()) : ?> - - + content->isPublic()) : ?> + + - - getContentName(); ?> - \ No newline at end of file + + getContentName(); ?> + + \ No newline at end of file diff --git a/protected/humhub/modules/content/widgets/views/visibilityLink.php b/protected/humhub/modules/content/widgets/views/visibilityLink.php new file mode 100644 index 0000000000..1b8c4c1c05 --- /dev/null +++ b/protected/humhub/modules/content/widgets/views/visibilityLink.php @@ -0,0 +1,18 @@ + +
  • + isPrivate()) :?> + + + + + + + + +
  • diff --git a/protected/humhub/modules/stream/resources/js/humhub.stream.js b/protected/humhub/modules/stream/resources/js/humhub.stream.js index 3cc35729c6..a30697122d 100644 --- a/protected/humhub/modules/stream/resources/js/humhub.stream.js +++ b/protected/humhub/modules/stream/resources/js/humhub.stream.js @@ -208,10 +208,12 @@ humhub.module('stream', function (module, require, $) { var $loader = this.$.find('.stream-entry-loader'); if ($show === false) { loader.reset($loader); + this.$.find('.wallentry-labels').show(); this.$.find('.preferences').show(); return; } - + + this.$.find('.wallentry-labels').hide(); this.$.find('.preferences').hide(); loader.set($loader, { 'position': 'left', @@ -231,6 +233,23 @@ humhub.module('stream', function (module, require, $) { additions.highlight(this.getContent()); }; + StreamEntry.prototype.toggleVisibility = function (evt) { + this.loader(); + var that = this; + client.post(evt).then(function(response) { + if(response.success) { + that.reload(); + module.log.success('saved'); + } else { + module.log.error(response, true); + that.loader(false); + } + }).catch(function (e) { + that.loader(false); + module.log.error(e, true); + }); + }; + StreamEntry.prototype.pin = function (evt) { var that = this; this.loader(); @@ -603,13 +622,13 @@ humhub.module('stream', function (module, require, $) { }; Stream.prototype.prependEntry = function (html, respectPinnedPosts) { - if(respectPinnedPosts) { + if (respectPinnedPosts) { var $pinned = this.$.find('[data-stream-pinned="1"]:last'); - if($pinned.length) { + if ($pinned.length) { return this.after(html, $pinned); } } - + return this._streamEntryAnimation(html, function ($html) { this.$content.prepend($html); }); @@ -663,7 +682,7 @@ humhub.module('stream', function (module, require, $) { Stream.prototype.addEntries = function (response, cfg) { var that = this; var result = ''; - + $.each(response.contentOrder, function (i, key) { var $entry = that.entry(key); if ($entry.length) { @@ -689,8 +708,8 @@ humhub.module('stream', function (module, require, $) { } else { promise = this.appendEntry($result); } - - promise.then(function() { + + promise.then(function () { that.$.trigger('humhub:stream:afterAddEntries', [response, $result]); });