mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Added advanced space settings (#5932)
* Added advanced space settings * Modified Changelog [skip-ci] * Improve usage of AdvancedSettings * Improved usage of Space Advanced Settings * Updated Changelog [skip ci] * Hide Followers Option * Replace Checkbox [skip ci] * Added missing hideFollowers rule [skip ci] * Allow default values for all Space Advanced Settings * Default Settings * Added tests
This commit is contained in:
parent
e674a50b2e
commit
bfc6ff9c63
@ -25,5 +25,6 @@ HumHub Changelog
|
||||
- Fix #5926: Renamed default profile field `Url` to `Website URL`
|
||||
- Enh #5686: Add the logo image to the registration page
|
||||
- Fix #5856: Fixed Mail Settings Help Text SMTPS Port to 465
|
||||
- Enh #5932: Added advanced space settings `Hide About Page`, `Hide Activity Sidebar Widget`, `Hide Follower` and `Hide Members`
|
||||
- Enh #5931: Show `Spaces` pages always when in Guest Mode
|
||||
- Enh #5929: Add property `createMode` for wall stream entry widget
|
||||
|
@ -61,17 +61,35 @@ class Module extends \humhub\components\Module
|
||||
public $minimumSpaceUrlLength = 2;
|
||||
|
||||
/**
|
||||
* @var bool hide about page in space menu
|
||||
* @var bool hide about page in space menu (default value for advanced settings page)
|
||||
* @since 1.7
|
||||
*/
|
||||
public $hideAboutPage = false;
|
||||
|
||||
/**
|
||||
* @var bool hide "Spaces" in top menu
|
||||
* @var bool Hide "Spaces" in top menu
|
||||
* @since 1.10
|
||||
*/
|
||||
public $hideSpacesPage = false;
|
||||
|
||||
/**
|
||||
* @var bool Hide Activity Sidebar Widget (default value for advanced settings page)
|
||||
* @since 1.13
|
||||
*/
|
||||
public $hideActivities = false;
|
||||
|
||||
/**
|
||||
* @var bool Hide Members (default value for advanced settings page)
|
||||
* @since 1.13
|
||||
*/
|
||||
public $hideMembers = false;
|
||||
|
||||
/**
|
||||
* @var bool Hide Followers (default value for advanced settings page)
|
||||
* @since 1.13
|
||||
*/
|
||||
public $hideFollowers = false;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
namespace humhub\modules\space\components;
|
||||
|
||||
use humhub\modules\space\Module;
|
||||
use Yii;
|
||||
use yii\validators\Validator;
|
||||
use URLify;
|
||||
@ -21,21 +22,47 @@ use humhub\modules\space\models\Space;
|
||||
*/
|
||||
class UrlValidator extends Validator
|
||||
{
|
||||
/**
|
||||
* @var Space
|
||||
*/
|
||||
public $space;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validateAttribute($model, $attribute)
|
||||
{
|
||||
$value = $model->$attribute;
|
||||
if (mb_strtolower($value) != URLify::filter($value, 45)) {
|
||||
$value = mb_strtolower($model->$attribute);
|
||||
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
|
||||
$stringValidator = new yii\validators\StringValidator([
|
||||
'max' => $module->maximumSpaceUrlLength,
|
||||
'min' => $module->minimumSpaceUrlLength
|
||||
]);
|
||||
if (!$stringValidator->validate($value, $error)) {
|
||||
$this->addError($model, $attribute, $error);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value !== URLify::filter($value, 45)) {
|
||||
$this->addError($model, $attribute, Yii::t('SpaceModule.manage', 'The url contains illegal characters!'));
|
||||
}
|
||||
|
||||
$query = Space::find()->where(['url' => $value]);
|
||||
if (!$this->space->isNewRecord) {
|
||||
$query->andWhere(['!=', 'id', $this->space->id]);
|
||||
}
|
||||
if ($query->count() > 0) {
|
||||
$this->addError($model, $attribute, Yii::t('SpaceModule.manage', 'The URL has already been taken.'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique space url
|
||||
*
|
||||
*
|
||||
* @param string $name
|
||||
* @return string a unique space url
|
||||
*/
|
||||
|
@ -8,15 +8,13 @@
|
||||
|
||||
namespace humhub\modules\space\controllers;
|
||||
|
||||
use humhub\components\behaviors\AccessControl;
|
||||
use humhub\modules\admin\permissions\ManageUsers;
|
||||
use humhub\modules\content\components\ContentContainerController;
|
||||
use humhub\modules\content\components\ContentContainerControllerAccess;
|
||||
use humhub\modules\space\jobs\AddUsersToSpaceJob;
|
||||
use humhub\modules\space\models\forms\InviteForm;
|
||||
use humhub\modules\space\models\forms\RequestMembershipForm;
|
||||
use humhub\modules\space\models\Membership;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\Module;
|
||||
use humhub\modules\space\permissions\InviteUsers;
|
||||
use humhub\modules\space\widgets\MembershipButton;
|
||||
use humhub\modules\user\models\UserPicker;
|
||||
@ -33,7 +31,7 @@ use yii\web\HttpException;
|
||||
* memberships.
|
||||
*
|
||||
* @author Luke
|
||||
* @package humhub.modules_core.space.controllers
|
||||
* @property Module $module
|
||||
* @since 0.5
|
||||
*/
|
||||
class MembershipController extends ContentContainerController
|
||||
@ -49,7 +47,7 @@ class MembershipController extends ContentContainerController
|
||||
'receive-notifications',
|
||||
'search-invite',
|
||||
'switch-dashboard-display'
|
||||
]
|
||||
]
|
||||
],
|
||||
[ContentContainerControllerAccess::RULE_AJAX_ONLY => ['members-list']],
|
||||
];
|
||||
@ -63,6 +61,10 @@ class MembershipController extends ContentContainerController
|
||||
{
|
||||
Yii::$app->response->format = 'json';
|
||||
|
||||
if ($this->canViewMembers()) {
|
||||
throw new HttpException(403);
|
||||
}
|
||||
|
||||
$space = $this->getSpace();
|
||||
$visibility = (int)$space->visibility;
|
||||
if ($visibility === Space::VISIBILITY_NONE && !$space->isMember() ||
|
||||
@ -200,10 +202,10 @@ class MembershipController extends ContentContainerController
|
||||
$model = new InviteForm(['space' => $this->getSpace()]);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
if($model->isQueuedJob()) {
|
||||
if ($model->isQueuedJob()) {
|
||||
$success = ($model->withoutInvite)
|
||||
? Yii::t( 'SpaceModule.base', 'User memberships have been added to the queue')
|
||||
: Yii::t( 'SpaceModule.base', 'User invitations have been added to the queue');
|
||||
? Yii::t('SpaceModule.base', 'User memberships have been added to the queue')
|
||||
: Yii::t('SpaceModule.base', 'User invitations have been added to the queue');
|
||||
} else {
|
||||
$success = Yii::t('SpaceModule.base', 'Users has been invited.');
|
||||
}
|
||||
@ -261,6 +263,10 @@ class MembershipController extends ContentContainerController
|
||||
*/
|
||||
public function actionMembersList()
|
||||
{
|
||||
if (!$this->canViewMembers()) {
|
||||
throw new HttpException(403);
|
||||
}
|
||||
|
||||
return $this->renderAjaxContent(UserListBox::widget([
|
||||
'query' => Membership::getSpaceMembersQuery($this->getSpace())->visible(),
|
||||
'title' => Yii::t('SpaceModule.manage', "<strong>Members</strong>"),
|
||||
@ -296,4 +302,14 @@ class MembershipController extends ContentContainerController
|
||||
return $this->redirect($this->request->getReferrer());
|
||||
}
|
||||
|
||||
private function canViewMembers(): bool
|
||||
{
|
||||
if ($this->space->getAdvancedSettings()->hideMembers) {
|
||||
$membership = $this->space->getMembership();
|
||||
|
||||
return $membership->isPrivileged();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +161,10 @@ class SpaceController extends ContentContainerController
|
||||
*/
|
||||
public function actionFollowerList()
|
||||
{
|
||||
if ($this->space->getAdvancedSettings()->hideFollowers) {
|
||||
throw new HttpException(403);
|
||||
}
|
||||
|
||||
$query = User::find();
|
||||
$query->leftJoin('user_follow', 'user.id=user_follow.user_id AND object_model=:userClass AND user_follow.object_id=:spaceId', [':userClass' => Space::class, ':spaceId' => $this->getSpace()->id]);
|
||||
$query->orderBy(['user_follow.id' => SORT_DESC]);
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m221117_214310_rename_setting
|
||||
*/
|
||||
class m221117_214310_rename_setting extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->update('contentcontainer_setting', [
|
||||
'name' => 'hideMembers'
|
||||
], ['name' => 'hideMembersSidebar', 'module_id' => 'space']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
echo "m221117_214310_rename_setting cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m221117_214310_rename_setting cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
145
protected/humhub/modules/space/models/AdvancedSettings.php
Normal file
145
protected/humhub/modules/space/models/AdvancedSettings.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2022 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\space\models;
|
||||
|
||||
use humhub\modules\space\components\UrlValidator;
|
||||
use humhub\modules\space\Module;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* Model class for Advanced Settings of a Space. These settings are mainly stored via the
|
||||
* Settings Manager as the Space Model.
|
||||
*
|
||||
* @since 1.13
|
||||
* @author Luke
|
||||
*/
|
||||
class AdvancedSettings extends Model
|
||||
{
|
||||
/**
|
||||
* @var Space
|
||||
*/
|
||||
public $space;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $url = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $indexUrl = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $indexGuestUrl = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $hideMembers = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $hideActivities = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $hideAbout = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $hideFollowers = false;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['indexUrl', 'indexGuestUrl'], 'string'],
|
||||
[['hideMembers', 'hideActivities', 'hideAbout', 'hideFollowers'], 'boolean'],
|
||||
['url', UrlValidator::class, 'space' => $this->space]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'url' => 'URL',
|
||||
'indexUrl' => Yii::t('SpaceModule.base', 'Homepage'),
|
||||
'indexGuestUrl' => Yii::t('SpaceModule.base', 'Homepage(Guests)'),
|
||||
'hideMembers' => Yii::t('SpaceModule.base', 'Hide Members'),
|
||||
'hideActivities' => Yii::t('SpaceModule.base', 'Hide Activity Sidebar Widget'),
|
||||
'hideAbout' => Yii::t('SpaceModule.base', 'Hide About Page'),
|
||||
'hideFollowers' => Yii::t('SpaceModule.base', 'Hide Followers'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function loadBySettings()
|
||||
{
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
|
||||
$settings = $this->space->getSettings();
|
||||
|
||||
$this->url = $this->space->url;
|
||||
$this->indexUrl = $settings->get('indexUrl', null);
|
||||
$this->indexGuestUrl = $settings->get('indexGuestUrl', null);
|
||||
|
||||
$this->hideMembers = $settings->get('hideMembers', $this->hideMembers);
|
||||
$this->hideAbout = $settings->get('hideAbout', $module->hideAboutPage);
|
||||
$this->hideActivities = $settings->get('hideActivities', $this->hideActivities);
|
||||
$this->hideFollowers = $settings->get('hideFollowers', $this->hideFollowers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function save(): bool
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$settings = $this->space->getSettings();
|
||||
|
||||
$this->space->url = $this->url;
|
||||
$this->space->save();
|
||||
|
||||
if (!empty($this->indexUrl)) {
|
||||
$settings->set('indexUrl', $this->indexUrl);
|
||||
} else {
|
||||
$settings->delete('indexUrl');
|
||||
}
|
||||
|
||||
if (!empty($this->indexGuestUrl)) {
|
||||
$settings->set('indexGuestUrl', $this->indexGuestUrl);
|
||||
} else {
|
||||
$settings->delete('indexGuestUrl');
|
||||
}
|
||||
|
||||
$settings->set('hideMembers', (bool)$this->hideMembers);
|
||||
$settings->set('hideAbout', (bool)$this->hideAbout);
|
||||
$settings->set('hideActivities', (bool)$this->hideActivities);
|
||||
$settings->set('hideFollowers', (bool)$this->hideFollowers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -105,14 +105,28 @@ class Membership extends ActiveRecord
|
||||
/**
|
||||
* Determines if this membership is a full accepted membership.
|
||||
*
|
||||
* @since v1.2.1
|
||||
* @return bool
|
||||
* @since v1.2.1
|
||||
*/
|
||||
public function isMember()
|
||||
{
|
||||
return $this->status == self::STATUS_MEMBER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.13
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrivileged(): bool
|
||||
{
|
||||
return ($this->isMember() &&
|
||||
in_array($this->group_id, [
|
||||
Space::USERGROUP_OWNER,
|
||||
Space::USERGROUP_ADMIN,
|
||||
Space::USERGROUP_MODERATOR
|
||||
]));
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne(User::class, ['id' => 'user_id']);
|
||||
@ -232,11 +246,11 @@ class Membership extends ActiveRecord
|
||||
/**
|
||||
* Returns Space for user space membership
|
||||
*
|
||||
* @since 1.0
|
||||
* @param \humhub\modules\user\models\User $user
|
||||
* @param boolean $memberOnly include only member status - no pending/invite states
|
||||
* @param boolean|null $withNotifications include only memberships with sendNotification setting
|
||||
* @return \yii\db\ActiveQuery for space model
|
||||
* @since 1.0
|
||||
*/
|
||||
public static function getUserSpaceQuery(User $user, $memberOnly = true, $withNotifications = null)
|
||||
{
|
||||
@ -280,9 +294,10 @@ class Membership extends ActiveRecord
|
||||
*/
|
||||
public static function findByUser(
|
||||
User $user = null,
|
||||
$membershipStatus = self::STATUS_MEMBER,
|
||||
$spaceStatus = Space::STATUS_ENABLED
|
||||
) {
|
||||
$membershipStatus = self::STATUS_MEMBER,
|
||||
$spaceStatus = Space::STATUS_ENABLED
|
||||
)
|
||||
{
|
||||
if (!$user) {
|
||||
$user = Yii::$app->user->getIdentity();
|
||||
}
|
||||
@ -312,11 +327,11 @@ class Membership extends ActiveRecord
|
||||
/**
|
||||
* Returns a user query for space memberships
|
||||
*
|
||||
* @since 1.1
|
||||
* @param Space $space
|
||||
* @param boolean $membersOnly Only return approved members
|
||||
* @param boolean|null $withNotifications include only memberships with sendNotification setting
|
||||
* @return \humhub\modules\user\components\ActiveQueryUser
|
||||
* @since 1.1
|
||||
*/
|
||||
public static function getSpaceMembersQuery(Space $space, $membersOnly = true, $withNotifications = null)
|
||||
{
|
||||
@ -353,18 +368,16 @@ class Membership extends ActiveRecord
|
||||
->innerJoin('space_membership sm', 'space.id = sm.space_id')
|
||||
->where('sm.user_id = :userId', [':userId' => $user->id])
|
||||
->indexBy('id')
|
||||
->andWhere('space.status = :spaceStatusEnabled', [':spaceStatusEnabled' => Space::STATUS_ENABLED]);
|
||||
->andWhere('space.status = :spaceStatusEnabled', [':spaceStatusEnabled' => Space::STATUS_ENABLED]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current logged in user is the related user of this membership record.
|
||||
*
|
||||
* @since 1.3.9
|
||||
* @return bool
|
||||
* @since 1.3.9
|
||||
*/
|
||||
public function isCurrentUser()
|
||||
public function isCurrentUser(): bool
|
||||
{
|
||||
return !Yii::$app->user->isGuest && Yii::$app->user->identity->id === $this->user_id;
|
||||
}
|
||||
|
||||
}
|
||||
}}
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
namespace humhub\modules\space\models;
|
||||
|
||||
use humhub\libs\ProfileImage;
|
||||
use humhub\modules\content\components\ContentContainerSettingsManager;
|
||||
use humhub\modules\search\interfaces\Searchable;
|
||||
use humhub\modules\search\events\SearchAddEvent;
|
||||
@ -98,6 +97,11 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
*/
|
||||
public $defaultRoute = '/space/space';
|
||||
|
||||
/**
|
||||
* @var AdvancedSettings|null
|
||||
*/
|
||||
private $_advancedSettings = null;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -120,13 +124,14 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
[['join_policy'], 'in', 'range' => [0, 1, 2]],
|
||||
[['visibility'], 'in', 'range' => [0, 1, 2]],
|
||||
[['visibility'], 'checkVisibility'],
|
||||
[['url'], 'unique', 'skipOnEmpty' => 'true'],
|
||||
[['guid', 'name'], 'string', 'max' => 45, 'min' => 2],
|
||||
[['url'], 'string', 'max' => Yii::$app->getModule('space')->maximumSpaceUrlLength, 'min' => Yii::$app->getModule('space')->minimumSpaceUrlLength],
|
||||
[['url'], UrlValidator::class],
|
||||
[['url'], UrlValidator::class, 'space' => $this],
|
||||
];
|
||||
|
||||
if (Yii::$app->getModule('space')->useUniqueSpaceNames) {
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
|
||||
if ($module->useUniqueSpaceNames) {
|
||||
$rules[] = [['name'], 'unique', 'targetClass' => static::class, 'when' => function ($model) {
|
||||
return $model->isAttributeChanged('name');
|
||||
}];
|
||||
@ -142,7 +147,7 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
{
|
||||
$scenarios = parent::scenarios();
|
||||
|
||||
$scenarios[static::SCENARIO_EDIT] = ['name', 'color', 'description', 'about', 'tagsField', 'blockedUsersField', 'join_policy', 'visibility', 'default_content_visibility', 'url'];
|
||||
$scenarios[static::SCENARIO_EDIT] = ['name', 'color', 'description', 'about', 'tagsField', 'blockedUsersField', 'join_policy', 'visibility', 'default_content_visibility'];
|
||||
$scenarios[static::SCENARIO_CREATE] = ['name', 'color', 'description', 'join_policy', 'visibility'];
|
||||
$scenarios[static::SCENARIO_SECURITY_SETTINGS] = ['default_content_visibility', 'join_policy', 'visibility'];
|
||||
|
||||
@ -174,7 +179,9 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function attributeHints()
|
||||
{
|
||||
return [
|
||||
@ -224,6 +231,21 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns advanced space settings
|
||||
*
|
||||
* @return AdvancedSettings
|
||||
*/
|
||||
public function getAdvancedSettings(): AdvancedSettings
|
||||
{
|
||||
if ($this->_advancedSettings === null) {
|
||||
$this->_advancedSettings = new AdvancedSettings(['space' => $this]);
|
||||
$this->_advancedSettings->loadBySettings();
|
||||
}
|
||||
|
||||
return $this->_advancedSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -265,10 +287,8 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
$this->url = UrlValidator::autogenerateUniqueSpaceUrl($this->name);
|
||||
}
|
||||
|
||||
if ($this->url == '') {
|
||||
if (empty($this->url)) {
|
||||
$this->url = new \yii\db\Expression('NULL');
|
||||
} else {
|
||||
$this->url = mb_strtolower($this->url);
|
||||
}
|
||||
|
||||
// Make sure visibility attribute is not empty
|
||||
@ -435,8 +455,8 @@ class Space extends ContentContainerActiveRecord implements Searchable
|
||||
* Used in edit scenario to check if the user really can create spaces
|
||||
* on this visibility.
|
||||
*
|
||||
* @param type $attribute
|
||||
* @param type $params
|
||||
* @param string $attribute
|
||||
* @param string $params
|
||||
*/
|
||||
public function checkVisibility($attribute, $params)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ use humhub\modules\content\widgets\richtext\RichText;
|
||||
use humhub\modules\space\components\UrlRule;
|
||||
use Yii;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\modules\manage\models\AdvancedSettingsSpace;
|
||||
use humhub\modules\space\models\AdvancedSettings;
|
||||
use humhub\modules\space\widgets\Menu;
|
||||
use humhub\modules\space\widgets\Chooser;
|
||||
use humhub\modules\space\modules\manage\components\Controller;
|
||||
@ -33,7 +33,8 @@ class DefaultController extends Controller
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getAccessRules() {
|
||||
protected function getAccessRules()
|
||||
{
|
||||
return [
|
||||
['login'],
|
||||
[ContentContainerControllerAccess::RULE_USER_GROUP_ONLY => [Space::USERGROUP_ADMIN], 'actions' => ['index', 'advanced']],
|
||||
@ -62,25 +63,25 @@ class DefaultController extends Controller
|
||||
|
||||
public function actionAdvanced()
|
||||
{
|
||||
$space = AdvancedSettingsSpace::findOne(['id' => $this->contentContainer->id]);
|
||||
$space->scenario = 'edit';
|
||||
$space->indexUrl = Yii::$app->getModule('space')->settings->space()->get('indexUrl');
|
||||
$space->indexGuestUrl = Yii::$app->getModule('space')->settings->space()->get('indexGuestUrl');
|
||||
$space->hideMembersSidebar = Yii::$app->getModule('space')->settings->space()->get('hideMembersSidebar');
|
||||
$model = $this->space->getAdvancedSettings();
|
||||
|
||||
if ($space->load(Yii::$app->request->post()) && $space->validate() && $space->save()) {
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
unset(UrlRule::$containerUrlMap[$this->contentContainer->guid]);
|
||||
$this->view->saved();
|
||||
unset(UrlRule::$containerUrlMap[$space->guid]);
|
||||
return $this->redirect($space->createUrl('advanced'));
|
||||
return $this->redirect($this->contentContainer->createUrl('advanced'));
|
||||
}
|
||||
|
||||
$indexModuleSelection = Menu::getAvailablePages();
|
||||
unset($indexModuleSelection[Url::to(['/space/home', 'container' => $space])]);
|
||||
unset($indexModuleSelection[Url::to(['/space/home', 'container' => $this->contentContainer])]);
|
||||
|
||||
// To avoid infinit redirects of actionIndex we remove the stream value and set an empty selection instead
|
||||
$indexModuleSelection = ['' => Yii::t('SpaceModule.manage', 'Stream (Default)')] + $indexModuleSelection;
|
||||
|
||||
return $this->render('advanced', ['model' => $space, 'indexModuleSelection' => $indexModuleSelection]);
|
||||
return $this->render('advanced', [
|
||||
'model' => $model,
|
||||
'space' => $this->contentContainer,
|
||||
'indexModuleSelection' => $indexModuleSelection
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +95,7 @@ class DefaultController extends Controller
|
||||
// Create Activity when the space in archived
|
||||
SpaceArchived::instance()->from(Yii::$app->user->getIdentity())->about($space->owner)->save();
|
||||
|
||||
return $this->asJson( [
|
||||
return $this->asJson([
|
||||
'success' => true,
|
||||
'space' => Chooser::getSpaceResult($space, true, ['isMember' => true])
|
||||
]);
|
||||
|
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\space\modules\manage\models;
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* AdvancedSettingsSpace
|
||||
*
|
||||
* @author Luke
|
||||
*/
|
||||
class AdvancedSettingsSpace extends Space
|
||||
{
|
||||
|
||||
/**
|
||||
* Contains the form value for indexUrl setting
|
||||
* @var string|null
|
||||
*/
|
||||
public $indexUrl = null;
|
||||
|
||||
/**
|
||||
* Contains the form value for indexGuestUrl setting
|
||||
* @var string|null
|
||||
*/
|
||||
public $indexGuestUrl = null;
|
||||
|
||||
/**
|
||||
* To hide Members sidebar in the stream page
|
||||
* @var bool
|
||||
*/
|
||||
public $hideMembersSidebar = null;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = parent::rules();
|
||||
$rules[] = [['indexUrl'], 'string'];
|
||||
$rules[] = [['indexGuestUrl'], 'string'];
|
||||
$rules[] = [['hideMembersSidebar'], 'integer'];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
$scenarios = parent::scenarios();
|
||||
$scenarios['edit'][] = 'indexUrl';
|
||||
$scenarios['edit'][] = 'indexGuestUrl';
|
||||
$scenarios['edit'][] = 'hideMembersSidebar';
|
||||
|
||||
return $scenarios;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
$labels = parent::attributeLabels();
|
||||
$labels['indexUrl'] = Yii::t('SpaceModule.base', 'Homepage');
|
||||
$labels['indexGuestUrl'] = Yii::t('SpaceModule.base', 'Homepage (Guests)');
|
||||
$labels['hideMembersSidebar'] = Yii::t('SpaceModule.base', 'Hide Members sidebar in the stream page.');
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
{
|
||||
if ($this->indexUrl != null) {
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->set('indexUrl', $this->indexUrl);
|
||||
} else {
|
||||
//Remove entry from db
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->delete('indexUrl');
|
||||
}
|
||||
|
||||
if ($this->indexGuestUrl != null) {
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->set('indexGuestUrl', $this->indexGuestUrl);
|
||||
} else {
|
||||
//Remove entry from db
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->delete('indexGuestUrl');
|
||||
}
|
||||
|
||||
if ($this->hideMembersSidebar != null) {
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->set('hideMembersSidebar', $this->hideMembersSidebar);
|
||||
} else {
|
||||
//Remove entry from db
|
||||
Yii::$app->getModule('space')->settings->contentContainer($this)->delete('hideMembersSidebar');
|
||||
}
|
||||
|
||||
return parent::afterSave($insert, $changedAttributes);
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\modules\manage\widgets\DefaultMenu;
|
||||
use humhub\widgets\Button;
|
||||
use humhub\modules\ui\form\widgets\ActiveForm;
|
||||
use yii\helpers\Url;
|
||||
|
||||
/* @var $this \humhub\modules\ui\view\components\View
|
||||
* @var $model \humhub\modules\space\modules\manage\models\AdvancedSettingsSpace
|
||||
* @var $model \humhub\modules\space\modules\manage\models\AdvancedSettings
|
||||
* @var $indexModuleSelection array
|
||||
* @var $space Space
|
||||
*/
|
||||
|
||||
?>
|
||||
@ -19,7 +21,7 @@ use yii\helpers\Url;
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= DefaultMenu::widget(['space' => $model]); ?>
|
||||
<?= DefaultMenu::widget(['space' => $space]); ?>
|
||||
|
||||
<div class="panel-body">
|
||||
|
||||
@ -27,12 +29,15 @@ use yii\helpers\Url;
|
||||
<?php if (Yii::$app->urlManager->enablePrettyUrl) : ?>
|
||||
<?= $form->field($model, 'url')->hint(Yii::t('SpaceModule.manage', 'e.g. example for {baseUrl}/s/example', ['baseUrl' => Url::base(true)])); ?>
|
||||
<?php endif; ?>
|
||||
<?= $form->field($model, 'hideMembersSidebar')->checkbox(); ?>
|
||||
<?= $form->field($model, 'hideMembers')->checkbox(); ?>
|
||||
<?= $form->field($model, 'hideAbout')->checkbox(); ?>
|
||||
<?= $form->field($model, 'hideActivities')->checkbox(); ?>
|
||||
<?= $form->field($model, 'hideFollowers')->checkbox(); ?>
|
||||
<?= $form->field($model, 'indexUrl')->dropDownList($indexModuleSelection)->hint(Yii::t('SpaceModule.manage', 'the default start page of this space for members')) ?>
|
||||
<?= $form->field($model, 'indexGuestUrl')->dropDownList($indexModuleSelection)->hint(Yii::t('SpaceModule.manage', 'the default start page of this space for visitors')) ?>
|
||||
|
||||
<?= Button::save()->submit() ?>
|
||||
<?= Button::danger(Yii::t('base', 'Delete'))->right()->link($model->createUrl('delete'))->visible($model->canDelete()) ?>
|
||||
<?= Button::danger(Yii::t('base', 'Delete'))->right()->link($space->createUrl('delete'))->visible($space->canDelete()) ?>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace space\acceptance;
|
||||
|
||||
use space\AcceptanceTester;
|
||||
|
||||
class AdvancedSettingsCest
|
||||
{
|
||||
public function testHideMembers(AcceptanceTester $I)
|
||||
{
|
||||
$I->amSpaceAdmin(false, 2);
|
||||
|
||||
$I->amOnPage('/s/space-2/home');
|
||||
$I->seeElement('#space-members-panel');
|
||||
|
||||
$I->amOnPage('/s/space-2/about');
|
||||
$I->seeElement('#space-members-panel');
|
||||
|
||||
$I->amOnPage('/s/space-2/space/manage/default/advanced');
|
||||
$I->see('Members', '.statistics');
|
||||
$I->checkOption('#advancedsettings-hidemembers');
|
||||
$I->submitForm('#spaceIndexForm', []);
|
||||
|
||||
$I->waitForText('Saved');
|
||||
$I->dontSee('Members', '.statistics');
|
||||
|
||||
$I->amOnPage('/s/space-2/home');
|
||||
$I->dontSeeElement('#space-members-panel');
|
||||
|
||||
$I->amOnPage('/s/space-2/about');
|
||||
$I->dontSeeElement('#space-members-panel');
|
||||
}
|
||||
|
||||
public function testHideActivities(AcceptanceTester $I)
|
||||
{
|
||||
$I->amSpaceAdmin(false, 2);
|
||||
|
||||
$I->amOnPage('/s/space-2/home');
|
||||
$I->seeElement('#panel-activities');
|
||||
|
||||
$I->amOnPage('/s/space-2/space/manage/default/advanced');
|
||||
$I->checkOption('#advancedsettings-hideactivities');
|
||||
$I->submitForm('#spaceIndexForm', []);
|
||||
|
||||
$I->waitForText('Saved');
|
||||
|
||||
$I->amOnPage('/s/space-2/home');
|
||||
$I->dontSeeElement('#panel-activities');
|
||||
}
|
||||
|
||||
public function testHideAbout(AcceptanceTester $I)
|
||||
{
|
||||
$I->amSpaceAdmin(false, 2);
|
||||
|
||||
$I->amOnPage('/s/space-2/space/manage/default/advanced');
|
||||
$I->see('About', '#space-main-menu');
|
||||
|
||||
$I->checkOption('#advancedsettings-hideabout');
|
||||
$I->submitForm('#spaceIndexForm', []);
|
||||
|
||||
$I->waitForText('Saved');
|
||||
|
||||
$I->dontSee('About', '#space-main-menu');
|
||||
}
|
||||
|
||||
public function testHideFollowers(AcceptanceTester $I)
|
||||
{
|
||||
$I->amSpaceAdmin(false, 2);
|
||||
|
||||
$I->amOnPage('/s/space-2/space/manage/default/advanced');
|
||||
$I->see('Followers', '.statistics');
|
||||
$I->checkOption('#advancedsettings-hidefollowers');
|
||||
$I->submitForm('#spaceIndexForm', []);
|
||||
|
||||
$I->waitForText('Saved');
|
||||
$I->dontSee('Followers', '.statistics');
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
use humhub\modules\activity\widgets\ActivityStreamViewer;
|
||||
use humhub\modules\content\widgets\WallCreateContentFormContainer;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\Module;
|
||||
use humhub\modules\space\modules\manage\widgets\PendingApprovals;
|
||||
use humhub\modules\space\widgets\Members;
|
||||
use humhub\modules\space\widgets\Sidebar;
|
||||
@ -24,6 +25,9 @@ if ($canCreateEntries) {
|
||||
} else {
|
||||
$emptyMessage = Yii::t('SpaceModule.base', '<b>You are not member of this space and there is no public content, yet!</b>');
|
||||
}
|
||||
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
?>
|
||||
|
||||
<?php if ($canCreateEntries && !$isSingleContentRequest) : ?>
|
||||
@ -41,12 +45,15 @@ if ($canCreateEntries) {
|
||||
|
||||
<?php
|
||||
$this->beginBlock('sidebar');
|
||||
$widgets = [
|
||||
[ActivityStreamViewer::class, ['contentContainer' => $space], ['sortOrder' => 10]],
|
||||
[PendingApprovals::class, ['space' => $space], ['sortOrder' => 20]]
|
||||
];
|
||||
$widgets = [];
|
||||
|
||||
if (!Yii::$app->getModule('space')->settings->contentContainer($space)->get('hideMembersSidebar')) {
|
||||
if (!$space->getAdvancedSettings()->hideActivities) {
|
||||
$widgets[] = [ActivityStreamViewer::class, ['contentContainer' => $space], ['sortOrder' => 10]];
|
||||
}
|
||||
|
||||
$widgets[] = [PendingApprovals::class, ['space' => $space], ['sortOrder' => 20]];
|
||||
|
||||
if (!$space->getAdvancedSettings()->hideMembers) {
|
||||
$widgets[] = [Members::class, ['space' => $space], ['sortOrder' => 30]];
|
||||
}
|
||||
?>
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace humhub\modules\space\widgets;
|
||||
|
||||
use humhub\modules\space\Module;
|
||||
use Yii;
|
||||
|
||||
class AboutPageSidebar extends Sidebar
|
||||
{
|
||||
/**
|
||||
@ -12,12 +15,20 @@ class AboutPageSidebar extends Sidebar
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
|
||||
$this->widgets = [];
|
||||
|
||||
if ($this->space->isMember())
|
||||
if ($this->space->isMember()) {
|
||||
$this->widgets[] = [MyMembership::class, ['space' => $this->space], ['sortOrder' => 10]];
|
||||
}
|
||||
|
||||
if (!$this->space->getAdvancedSettings()->hideMembers) {
|
||||
$this->widgets[] = [Members::class, ['space' => $this->space, 'orderByNewest' => true], ['sortOrder' => 20]];
|
||||
}
|
||||
|
||||
$this->widgets[] = [Members::class, ['space' => $this->space, 'orderByNewest' => true], ['sortOrder' => 20]];
|
||||
$this->widgets[] = [SpaceFollowers::class, ['space' => $this->space], ['sortOrder' => 25]];
|
||||
$this->widgets[] = [SpaceTags::class, ['space' => $this->space], ['sortOrder' => 30]];
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use humhub\modules\content\models\Content;
|
||||
use humhub\modules\post\models\Post;
|
||||
use humhub\modules\space\models\Membership;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\Module;
|
||||
use humhub\modules\ui\widgets\CounterSetItem;
|
||||
use humhub\modules\ui\widgets\CounterSet;
|
||||
use Yii;
|
||||
@ -42,17 +43,21 @@ class HeaderCounterSet extends CounterSet
|
||||
'value' => $postQuery->count()
|
||||
]);
|
||||
|
||||
$this->counters[] = new CounterSetItem([
|
||||
'label' => Yii::t('SpaceModule.base', 'Members'),
|
||||
'value' => Membership::getSpaceMembersQuery($this->space)->active()->visible()->count(),
|
||||
'url' => Yii::$app->user->isGuest ? null : '#',
|
||||
'linkOptions' => Yii::$app->user->isGuest ? [] : [
|
||||
'data-action-click' => 'ui.modal.load',
|
||||
'data-action-url' => Url::to(['/space/membership/members-list', 'container' => $this->space])
|
||||
]
|
||||
]);
|
||||
if (!$this->space->getAdvancedSettings()->hideMembers) {
|
||||
$this->counters[] = new CounterSetItem([
|
||||
'label' => Yii::t('SpaceModule.base', 'Members'),
|
||||
'value' => Membership::getSpaceMembersQuery($this->space)->active()->visible()->count(),
|
||||
'url' => Yii::$app->user->isGuest ? null : '#',
|
||||
'linkOptions' => Yii::$app->user->isGuest ? [] : [
|
||||
'data-action-click' => 'ui.modal.load',
|
||||
'data-action-url' => Url::to(['/space/membership/members-list', 'container' => $this->space])
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
if (!Yii::$app->getModule('space')->disableFollow) {
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
if (!$module->disableFollow && !$this->space->getAdvancedSettings()->hideFollowers) {
|
||||
$this->counters[] = new CounterSetItem([
|
||||
'label' => Yii::t('SpaceModule.base', 'Followers'),
|
||||
'value' => $this->space->getFollowersQuery()->count(),
|
||||
@ -66,5 +71,4 @@ class HeaderCounterSet extends CounterSet
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,10 +64,7 @@ class Menu extends LeftNavigation
|
||||
'isActive' => MenuLink::isActiveState('space', 'space', ['index', 'home']),
|
||||
]));
|
||||
|
||||
/** @var Module $module */
|
||||
$module = Yii::$app->getModule('space');
|
||||
|
||||
if (!$module->hideAboutPage) {
|
||||
if (!$this->space->getAdvancedSettings()->hideAbout) {
|
||||
$this->addAboutPage();
|
||||
}
|
||||
}
|
||||
@ -113,7 +110,9 @@ class Menu extends LeftNavigation
|
||||
*/
|
||||
public static function getDefaultPageUrl($space)
|
||||
{
|
||||
return static::getAvailablePageUrl($space, 'indexUrl');
|
||||
$indexUrl = $space->getAdvancedSettings()->indexUrl;
|
||||
return (!empty($indexUrl) && isset(static::getAvailablePages()[$indexUrl])) ?
|
||||
$indexUrl : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,30 +123,8 @@ class Menu extends LeftNavigation
|
||||
*/
|
||||
public static function getGuestsDefaultPageUrl($space)
|
||||
{
|
||||
return static::getAvailablePageUrl($space, 'indexGuestUrl');
|
||||
$indexUrl = $space->getAdvancedSettings()->indexGuestUrl;
|
||||
return (!empty($indexUrl) && isset(static::getAvailablePages()[$indexUrl])) ?
|
||||
$indexUrl : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get default Space page URL by setting name
|
||||
*
|
||||
* @param Space $space
|
||||
* @param string $pageSettingName
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getAvailablePageUrl(Space $space, string $pageSettingName): ?string
|
||||
{
|
||||
/* @var Module $spaceModule */
|
||||
$spaceModule = Yii::$app->getModule('space');
|
||||
|
||||
$indexUrl = $spaceModule->settings->contentContainer($space)->get($pageSettingName);
|
||||
if ($indexUrl === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$pages = static::getAvailablePages();
|
||||
|
||||
return isset($pages[$indexUrl]) ? $indexUrl : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user