mirror of
https://github.com/humhub/humhub.git
synced 2025-01-18 06:38:14 +01:00
Merge branch 'master' of github.com:humhub/humhub
This commit is contained in:
commit
da8c37619d
@ -238,7 +238,7 @@ class UserController extends Controller
|
||||
if ($doit == 2) {
|
||||
$this->forcePostRequest();
|
||||
|
||||
foreach (Membership::GetUserSpaces($user->id) as $space) {
|
||||
foreach (Membership::getUserSpaces($user->id) as $space) {
|
||||
if ($space->isSpaceOwner($user->id)) {
|
||||
$space->addMember(Yii::$app->user->id);
|
||||
$space->setSpaceOwner(Yii::$app->user->id);
|
||||
|
@ -35,7 +35,7 @@ $this->registerJsConfig('admin', [
|
||||
|
||||
<?= $form->field($model, 'dateInputDisplayFormat')->dropDownList([
|
||||
'' => Yii::t('AdminModule.views_setting_design', 'Auto format based on user language - Example: {example}', ['{example}' => Yii::$app->formatter->asDate(time(), 'short')]),
|
||||
'php:d/m/Y' => Yii::t('AdminModule.views_setting_design', 'Fixed format (mm/dd/yyyy) - Example: {example}', ['{example}' => Yii::$app->formatter->asDate(time(), 'php:d/m/Y')]),
|
||||
'php:d/m/Y' => Yii::t('AdminModule.views_setting_design', 'Fixed format (dd/mm/yyyy) - Example: {example}', ['{example}' => Yii::$app->formatter->asDate(time(), 'php:d/m/Y')]),
|
||||
]);
|
||||
?>
|
||||
<strong><?= Yii::t('AdminModule.views_setting_index', 'Wall entry layout'); ?></strong>
|
||||
|
@ -116,7 +116,7 @@ class WallCreateContentForm extends Widget
|
||||
{
|
||||
Yii::$app->response->format = 'json';
|
||||
|
||||
$visibility = Yii::$app->request->post('visibility');
|
||||
$visibility = Yii::$app->request->post('visibility', Content::VISIBILITY_PRIVATE);
|
||||
if ($visibility == Content::VISIBILITY_PUBLIC && !$contentContainer->permissionManager->can(new CreatePublicContent())) {
|
||||
$visibility = Content::VISIBILITY_PRIVATE;
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ class GroupUsers extends Widget
|
||||
{
|
||||
$users = $this->group->getUsers()->visible()->limit($this->maxUsers + 1)->joinWith('profile')->orderBy(['profile.lastname' => SORT_ASC])->all();
|
||||
|
||||
|
||||
if (count($users) === 0) {
|
||||
return Html::tag('small', Yii::t('DirectoryModule.base', 'This group has no members yet.'));
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use humhub\modules\content\models\Content;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\user\models\Follow;
|
||||
use humhub\modules\friendship\models\Friendship;
|
||||
use humhub\modules\space\models\Membership;
|
||||
|
||||
/**
|
||||
* Live module provides a live channel to the users browser.
|
||||
@ -85,7 +86,7 @@ class Module extends \humhub\components\Module
|
||||
$legitimation[Content::VISIBILITY_OWNER][] = $user->contentContainerRecord->id;
|
||||
|
||||
// Collect user space membership with private content visibility
|
||||
$spaces = \humhub\modules\space\models\Membership::GetUserSpaces($user->id);
|
||||
$spaces = Membership::getUserSpaces($user->id);
|
||||
foreach ($spaces as $space) {
|
||||
$legitimation[Content::VISIBILITY_PRIVATE][] = $space->contentContainerRecord->id;
|
||||
}
|
||||
|
@ -275,8 +275,8 @@ class ZendLuceneSearch extends Search
|
||||
$privateSpaceContentQuery->addSubquery(new QueryTerm(new Term(Space::className(), 'containerModel')), true);
|
||||
$privateSpacesListQuery = new MultiTerm();
|
||||
|
||||
foreach (Membership::GetUserSpaces() as $space) {
|
||||
$privateSpacesListQuery->addTerm(new Term($space->id, 'containerPk'));
|
||||
foreach (Membership::getUserSpaceIds() as $spaceId) {
|
||||
$privateSpacesListQuery->addTerm(new Term($spaceId, 'containerPk'));
|
||||
}
|
||||
|
||||
$privateSpaceContentQuery->addSubquery($privateSpacesListQuery, true);
|
||||
|
@ -44,7 +44,7 @@ class Events extends \yii\base\Object
|
||||
$user = $event->sender;
|
||||
|
||||
// Check if the user owns some spaces
|
||||
foreach (Membership::GetUserSpaces($user->id) as $space) {
|
||||
foreach (Membership::getUserSpaces($user->id) as $space) {
|
||||
if ($space->isSpaceOwner($user->id)) {
|
||||
throw new HttpException(500, Yii::t('SpaceModule.base', 'Could not delete user who is a space owner! Name of Space: {spaceName}', array('spaceName' => $space->name)));
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ class Membership extends \yii\db\ActiveRecord
|
||||
const STATUS_APPLICANT = 2;
|
||||
const STATUS_MEMBER = 3;
|
||||
|
||||
const USER_SPACES_CACHE_KEY = 'userSpaces_';
|
||||
const USER_SPACEIDS_CACHE_KEY = 'userSpaceIds_';
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -121,13 +125,15 @@ class Membership extends \yii\db\ActiveRecord
|
||||
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
Yii::$app->cache->delete('userSpaces_' . $this->user_id);
|
||||
Yii::$app->cache->delete(self::USER_SPACES_CACHE_KEY . $this->user_id);
|
||||
Yii::$app->cache->delete(self::USER_SPACEIDS_CACHE_KEY . $this->user_id);
|
||||
return parent::beforeSave($insert);
|
||||
}
|
||||
|
||||
public function beforeDelete()
|
||||
{
|
||||
Yii::$app->cache->delete('userSpaces_' . $this->user_id);
|
||||
Yii::$app->cache->delete(self::USER_SPACES_CACHE_KEY . $this->user_id);
|
||||
Yii::$app->cache->delete(self::USER_SPACEIDS_CACHE_KEY . $this->user_id);
|
||||
return parent::beforeDelete();
|
||||
}
|
||||
|
||||
@ -159,28 +165,18 @@ class Membership extends \yii\db\ActiveRecord
|
||||
* @param boolean $cached use cached result if available
|
||||
* @return Space[] an array of spaces
|
||||
*/
|
||||
public static function GetUserSpaces($userId = "", $cached = true)
|
||||
public static function getUserSpaces($userId = '', $cached = true)
|
||||
{
|
||||
if ($userId == "") {
|
||||
if ($userId === '') {
|
||||
$userId = Yii::$app->user->id;
|
||||
}
|
||||
|
||||
$cacheId = "userSpaces_" . $userId;
|
||||
$cacheId = self::USER_SPACES_CACHE_KEY . $userId;
|
||||
|
||||
$spaces = Yii::$app->cache->get($cacheId);
|
||||
if ($spaces === false || !$cached) {
|
||||
|
||||
$orderSetting = Yii::$app->getModule('space')->settings->get('spaceOrder');
|
||||
$orderBy = 'name ASC';
|
||||
if ($orderSetting != 0) {
|
||||
$orderBy = 'last_visit DESC';
|
||||
}
|
||||
|
||||
$query = self::find()->joinWith('space')->orderBy($orderBy);
|
||||
$query->where(['user_id' => $userId, 'space_membership.status' => self::STATUS_MEMBER]);
|
||||
|
||||
$spaces = [];
|
||||
foreach ($query->all() as $membership) {
|
||||
foreach (static::getMembershipQuery($userId)->all() as $membership) {
|
||||
$spaces[] = $membership->space;
|
||||
}
|
||||
Yii::$app->cache->set($cacheId, $spaces);
|
||||
@ -188,6 +184,42 @@ class Membership extends \yii\db\ActiveRecord
|
||||
return $spaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all spaces' ids of the given userId
|
||||
*
|
||||
* @param integer $userId
|
||||
* @since 1.2.5
|
||||
*/
|
||||
public static function getUserSpaceIds($userId = '')
|
||||
{
|
||||
if ($userId === '') {
|
||||
$userId = Yii::$app->user->id;
|
||||
}
|
||||
|
||||
$cacheId = self::USER_SPACEIDS_CACHE_KEY . $userId;
|
||||
|
||||
$spaceIds = Yii::$app->cache->get($cacheId);
|
||||
if ($spaceIds === false) {
|
||||
$spaceIds = static::getMembershipQuery($userId)->select('space_id')->column();
|
||||
Yii::$app->cache->set($cacheId, $spaceIds);
|
||||
}
|
||||
return $spaceIds;
|
||||
}
|
||||
|
||||
private static function getMembershipQuery($userId)
|
||||
{
|
||||
$orderSetting = Yii::$app->getModule('space')->settings->get('spaceOrder');
|
||||
$orderBy = 'name ASC';
|
||||
if ($orderSetting != 0) {
|
||||
$orderBy = 'last_visit DESC';
|
||||
}
|
||||
|
||||
$query = self::find()->joinWith('space')->orderBy($orderBy);
|
||||
$query->where(['user_id' => $userId, 'space_membership.status' => self::STATUS_MEMBER]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Space for user space membership
|
||||
*
|
||||
|
@ -70,7 +70,7 @@ class TourController extends \humhub\components\Controller
|
||||
$space = null;
|
||||
|
||||
// Loop over all spaces where the user is member
|
||||
foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
|
||||
foreach (\humhub\modules\space\models\Membership::getUserSpaces() as $space) {
|
||||
if ($space->isAdmin() && !$space->isArchived()) {
|
||||
// If user is admin on this space, it´s the perfect match
|
||||
break;
|
||||
|
@ -14,6 +14,7 @@ use humhub\modules\user\components\BaseAccountController;
|
||||
use humhub\modules\user\models\User;
|
||||
use humhub\modules\notification\models\forms\NotificationSettings;
|
||||
use humhub\modules\user\controllers\ImageController;
|
||||
use humhub\modules\space\models\Membership;
|
||||
|
||||
/**
|
||||
* AccountController provides all standard actions for the current logged in
|
||||
@ -270,7 +271,7 @@ class AccountController extends BaseAccountController
|
||||
throw new HttpException(500, 'Account deletion not allowed');
|
||||
}
|
||||
|
||||
foreach (\humhub\modules\space\models\Membership::GetUserSpaces() as $space) {
|
||||
foreach (Membership::getUserSpaces() as $space) {
|
||||
if ($space->isSpaceOwner($user->id)) {
|
||||
$isSpaceOwner = true;
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
|
||||
public function beforeDelete()
|
||||
{
|
||||
// We don't allow deletion of users who owns a space - validate that
|
||||
foreach (Membership::GetUserSpaces($this->id, false) as $space) {
|
||||
foreach (Membership::getUserSpaces($this->id, false) as $space) {
|
||||
if ($space->isSpaceOwner($this->id)) {
|
||||
throw new Exception('Tried to delete a user (' . $this->id . ') which is owner of a space (' . $space->id . ')!');
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ class Image extends Widget
|
||||
if ($this->showTooltip) {
|
||||
$this->imageOptions['data-toggle'] = 'tooltip';
|
||||
$this->imageOptions['data-placement'] = 'top';
|
||||
$this->imageOptions['data-html'] = 'true';
|
||||
$this->imageOptions['data-original-title'] = ($this->tooltipText) ? $this->tooltipText : Html::encode($this->user->displayName);
|
||||
Html::addCssClass($this->imageOptions, 'tt');
|
||||
}
|
||||
|
@ -243,8 +243,11 @@ abstract class BasePickerField extends InputWidget
|
||||
{
|
||||
if (!$this->selection && $this->model != null) {
|
||||
$attribute = $this->attribute;
|
||||
|
||||
$this->selection = $this->loadItems(Html::getAttributeValue($this->model, $attribute));
|
||||
if(strrpos($attribute, '[') !== false) {
|
||||
$this->selection = $this->loadItems(Html::getAttributeValue($this->model, $attribute));
|
||||
} else {
|
||||
$this->selection = $this->loadItems($this->model->$attribute);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->selection) {
|
||||
|
@ -118,7 +118,6 @@ humhub.module('ui.additions', function (module, require, $) {
|
||||
// Show tooltips on elements
|
||||
module.register('tooltip', '.tt', function ($match) {
|
||||
$match.tooltip({
|
||||
html: false,
|
||||
container: 'body'
|
||||
});
|
||||
|
||||
|
@ -372,8 +372,8 @@ humhub.module('ui.richtext', function(module, require, $) {
|
||||
},
|
||||
init: function(feature, options) {
|
||||
options.data = feature.emojis;
|
||||
options.insertTpl = "<img data-emoji-name=';${name};' class='atwho-emoji' with='18' height='18' src='" + module.config['emoji.url'] + "${name}.svg' />";
|
||||
options.displayTpl = "<li class='atwho-emoji-entry' data-value=';${name};'><img with='18' height='18' src='" + module.config['emoji.url'] + "${name}.svg' /></li>";
|
||||
options.insertTpl = "<img data-emoji-name=';${name};' class='atwho-emoji' width='18' height='18' src='" + module.config['emoji.url'] + "${name}.svg'>";
|
||||
options.displayTpl = "<li class='atwho-emoji-entry' data-value=';${name};'><img width='18' height='18' src='" + module.config['emoji.url'] + "${name}.svg'></li>";
|
||||
},
|
||||
parse: function($clone) {
|
||||
$clone.find('.atwho-emoji').each(function() {
|
||||
@ -487,4 +487,4 @@ humhub.module('ui.richtext', function(module, require, $) {
|
||||
module.export({
|
||||
Richtext: Richtext
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user