Merge branch 'v1.1-dev' of github.com:humhub/humhub into v1.1-dev

This commit is contained in:
Lucas Bartholemy 2016-05-04 15:01:04 +02:00
commit a6e70357a8
5 changed files with 82 additions and 44 deletions

View File

@ -1,5 +1,11 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\content;
use Yii;
@ -19,10 +25,16 @@ class Module extends \humhub\components\Module
/**
* @since 1.1
* @var boolean admin can see all content
* @var boolean global admin can see all content
*/
public $adminCanViewAllContent = false;
/**
* @since 1.1
* @var boolean global admin can edit/delete all content
*/
public $adminCanEditAllContent = true;
/**
* @since 1.1
* @var string Custom e-mail subject for hourly update mails - default: Latest news
@ -35,11 +47,14 @@ class Module extends \humhub\components\Module
*/
public $emailSubjectDailyUpdate = null;
/**
* @inheritdoc
*/
public function getName()
{
return Yii::t('ContentModule.base', 'Content');
}
/**
* @inheritdoc
*/
@ -54,15 +69,15 @@ class Module extends \humhub\components\Module
return [];
}
/**
* @inheritdoc
*/
public function getNotifications()
public function getNotifications()
{
return [
'humhub\modules\content\notifications\ContentCreated'
];
return [
'humhub\modules\content\notifications\ContentCreated'
];
}
}

View File

@ -53,7 +53,7 @@ class ContentController extends Controller
$contentObj = Content::get($model, $id);
if ($contentObj !== null && $contentObj->content->canDelete() && $contentObj->delete()) {
if ($contentObj !== null && $contentObj->content->canEdit() && $contentObj->delete()) {
$json = [
'success' => true,
'uniqueId' => $contentObj->getUniqueId(),

View File

@ -547,6 +547,7 @@ class Content extends \humhub\components\ActiveRecord
* Checks if user can edit this content
*
* @todo create possibility to define own canEdit in ContentActiveRecord
* @todo also check content containers canManage content permission
* @since 1.1
* @param User $user
* @return boolean can edit this content
@ -562,6 +563,11 @@ class Content extends \humhub\components\ActiveRecord
return true;
}
// Global Admin can edit/delete arbitrarily content
if (Yii::$app->getModule('content')->adminCanEditAllContent && Yii::$app->user->getIdentity()->isSystemAdmin()) {
return true;
}
return false;
}

View File

@ -2,7 +2,7 @@
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
@ -30,7 +30,7 @@ class DeleteLink extends \yii\base\Widget
*/
public function run()
{
if ($this->content->content->canDelete()) {
if ($this->content->content->canEdit()) {
return $this->render('deleteLink', array(
'model' => $this->content->content->object_model,
'id' => $this->content->content->object_id

View File

@ -68,13 +68,18 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
const USERGROUP_FRIEND = 'u_friend';
const USERGROUP_USER = 'u_user';
const USERGROUP_GUEST = 'u_guest';
/**
* A initial group for the user assigned while registration.
* @var type
*/
public $registrationGroupId = null;
/**
* @var boolean is system admin (cached)
*/
private $_isSystemAdmin = null;
/**
* @inheritdoc
*/
@ -106,25 +111,38 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
[['wall_id'], 'unique']
];
}
public function isSystemAdmin()
/**
* Checks if user is system administrator
*
* @param boolean $cached Used cached result if available
* @return boolean user is system admin
*/
public function isSystemAdmin($cached = true)
{
return $this->getGroups()->where(['is_admin_group' => '1'])->count() > 0;
if ($this->_isSystemAdmin === null || !$cached) {
$this->_isSystemAdmin = ($this->getGroups()->where(['is_admin_group' => '1'])->count() > 0);
}
return $this->_isSystemAdmin;
}
/**
* @inheritdoc
*/
public function __get($name)
{
if($name == 'super_admin') {
/**
* Replacement for old super_admin flag version
*/
if ($name == 'super_admin') {
/**
* Replacement for old super_admin flag version
*/
return $this->isSystemAdmin();
} else if ($name == 'profile') {
/**
* Ensure there is always a related Profile Model also when it's
* not really exists yet.
*/
/**
* Ensure there is always a related Profile Model also when it's
* not really exists yet.
*/
$profile = parent::__get('profile');
if (!$this->isRelationPopulated('profile') || $profile === null) {
$profile = new Profile();
@ -190,7 +208,6 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return static::findOne(['guid' => $token]);
}
/**
* @inheritdoc
@ -226,7 +243,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return $this->hasOne(Profile::className(), ['user_id' => 'id']);
}
/**
* Returns all GroupUser relations of this user as AcriveQuery
* @return type
@ -235,7 +252,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return $this->hasMany(GroupUser::className(), ['user_id' => 'id']);
}
/**
* Returns all Group relations of this user as AcriveQuery
* @return AcriveQuery
@ -244,7 +261,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return $this->hasMany(Group::className(), ['id' => 'group_id'])->via('groupUsers');
}
/**
* Checks if the user has at least one group assigned.
* @return boolean
@ -253,7 +270,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return $this->getGroups()->count() > 0;
}
/**
* Returns all GroupUser relations this user is a manager of as AcriveQuery.
* @return AcriveQuery
@ -262,7 +279,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
{
return $this->getGroupUsers()->where(['is_group_manager' => '1']);
}
/**
* Returns all Groups this user is a maanger of as AcriveQuery.
* @return AcriveQuery
@ -270,10 +287,10 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
public function getManagerGroups()
{
return $this->hasMany(Group::className(), ['id' => 'group_id'])->via('groupUsers', function($query) {
$query->andWhere(['is_group_manager' => '1']);
});
$query->andWhere(['is_group_manager' => '1']);
});
}
/**
* Returns all user this user is related as friend as AcriveQuery.
* Returns null if the friendship module is deactivated.
@ -281,12 +298,12 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
*/
public function getFriends()
{
if(Yii::$app->getModule('friendship')->getIsEnabled()) {
if (Yii::$app->getModule('friendship')->getIsEnabled()) {
return \humhub\modules\friendship\models\Friendship::getFriendsQuery($this);
}
return null;
}
public function isActive()
{
return $this->status === User::STATUS_ENABLED;
@ -412,13 +429,13 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
}
// Auto Assign User to the Group Space
/*$group = Group::findOne(['id' => $this->group_id]);
if ($group != null && $group->space_id != "") {
$space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
if ($space !== null) {
$space->addMember($this->id);
}
}*/
/* $group = Group::findOne(['id' => $this->group_id]);
if ($group != null && $group->space_id != "") {
$space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]);
if ($space !== null) {
$space->addMember($this->id);
}
} */
// Auto Add User to the default spaces
foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) {
@ -474,7 +491,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
if ($user === null) {
$user = Yii::$app->user->getIdentity();
}
if ($user !== null && Yii::$app->getModule('friendship')->getIsEnabled()) {
if (Friendship::getStateForUser($this, $user) == Friendship::STATE_FRIENDS) {
return true;
@ -584,7 +601,7 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
if ($this->isSystemAdmin()) {
return true;
}
return $this->getManagerGroups()->count() > 0;
}