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

# Conflicts:
#	protected/humhub/docs/CHANGELOG_DEV.md
This commit is contained in:
Lucas Bartholemy 2018-06-27 12:24:58 +02:00
commit d78e352848
10 changed files with 379 additions and 67 deletions

View File

@ -17,7 +17,8 @@ class Yii extends \yii\BaseYii
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @property-read \humhub\components\ModuleManager $moduleManager
* @property-read \humhub\components\i18n\I18N $i18n
* @property \humhub\components\mail\Mailer $mailer
* @property \humhub\modules\ui\view\components\View $view
* @property \humhub\components\SettingsManager $settings
@ -40,6 +41,7 @@ abstract class BaseApplication extends yii\base\Application
/**
* Class WebApplication
* Include only Web application related components here
* @property-read \humhub\modules\user\components\User $user
*/
class WebApplication extends \humhub\components\Application
{

View File

@ -4,8 +4,6 @@ HumHub Change Log - v1.3-dev Branch
1.3.0-beta.1 (Not released yet)
--------------------------------
> Warning: Please read the [Update Notes](https://github.com/humhub/humhub/tree/v1.3-dev/protected/humhub/docs/guide/admin/updating-130.md) before updating!
- Enh: Added file search indexing
- Enh: Updated composer.json (acs-ferreira)
- Chg: Switched from Composer FXP plugin to Asset Packagist repository
@ -60,3 +58,4 @@ HumHub Change Log - v1.3-dev Branch
- Chg: Moved OpenSans font to core assets
- Chg: Renamed information cronjob section to Background jobs and added queue status
- Chg: MySQL queue is now the default job queuing driver
- Enh: Add steps to using Facebook Oauth (@Felli)

View File

@ -23,9 +23,16 @@ Note: Make sure to use lower case in the field.
Facebook
--------
In order to use Facebook OAuth you must register your application at <https://developers.facebook.com/apps>.
In order to use Facebook OAuth you must register your application at <https://developers.facebook.com/apps> then follow the below instructions.
Add the following block to your configuration (protected/config/common.php):
- In your app settings under **Basic** set your **Site URL**.
- Under **Settings > Advanced > Domain Manager** add any sub-domains used by the app.
- Under **Facebook Login > Client OAuth Settings > Valid OAuth Redirect URIs** place your `https://domain/path-to-humhub/user/auth/external?authclient=facebook` URL.
> https://domain/path-to-humhub/user/auth/external?authclient=facebook (With clean urls)
> http://domain/path-to-humhub/index.php?r=user%2Fauth%2Fexternal&authclient=facebook (Without clean urls)
- Make sure **Client OAuth Login** & **Web OAuth Login** are both enabled!
- Add the following block to your configuration (protected/config/common.php):
```php
return [

View File

@ -8,19 +8,21 @@
namespace humhub\modules\admin\controllers;
use Yii;
use yii\web\HttpException;
use yii\db\Query;
use humhub\components\Response;
use humhub\modules\admin\components\Controller;
use humhub\modules\user\models\Group;
use humhub\modules\user\models\GroupUser;
use humhub\modules\user\models\forms\EditGroupForm;
use humhub\modules\user\models\UserPicker;
use humhub\modules\user\models\User;
use humhub\modules\admin\models\forms\AddGroupMemberForm;
use humhub\modules\admin\permissions\ManageGroups;
use humhub\modules\admin\models\GroupSearch;
use humhub\modules\admin\models\UserSearch;
use humhub\modules\admin\notifications\ExcludeGroupNotification;
use humhub\modules\admin\permissions\ManageGroups;
use humhub\modules\user\models\forms\EditGroupForm;
use humhub\modules\user\models\Group;
use humhub\modules\user\models\GroupUser;
use humhub\modules\user\models\User;
use humhub\modules\user\models\UserPicker;
use Yii;
use yii\db\Query;
use yii\web\HttpException;
/**
* Group Administration Controller
@ -49,7 +51,7 @@ class GroupController extends Controller
public function getAccessRules()
{
return [
['permissions' => ManageGroups::className()]
['permissions' => ManageGroups::class],
];
}
@ -63,7 +65,7 @@ class GroupController extends Controller
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
'searchModel' => $searchModel,
]);
}
@ -87,7 +89,7 @@ class GroupController extends Controller
if ($wasNew) {
return $this->redirect([
'/admin/group/manage-group-users',
'id' => $group->id
'id' => $group->id,
]);
}
}
@ -96,7 +98,7 @@ class GroupController extends Controller
'group' => $group,
'showDeleteButton' => (!$group->isNewRecord && !$group->is_admin_group),
'isCreateForm' => $group->isNewRecord,
'isManagerApprovalSetting' => Yii::$app->getModule('user')->settings->get('auth.needApproval')
'isManagerApprovalSetting' => Yii::$app->getModule('user')->settings->get('auth.needApproval'),
]);
}
@ -107,11 +109,13 @@ class GroupController extends Controller
// Save changed permission states
if (!$group->isNewRecord && Yii::$app->request->post('dropDownColumnSubmit')) {
Yii::$app->response->format = 'json';
$permission = Yii::$app->user->permissionManager->getById(Yii::$app->request->post('permissionId'), Yii::$app->request->post('moduleId'));
$permission = Yii::$app->user->permissionManager->getById(Yii::$app->request->post('permissionId'),
Yii::$app->request->post('moduleId'));
if ($permission === null) {
throw new HttpException(500, 'Could not find permission!');
}
Yii::$app->user->permissionManager->setGroupState($group->id, $permission, Yii::$app->request->post('state'));
Yii::$app->user->permissionManager->setGroupState($group->id, $permission,
Yii::$app->request->post('state'));
return [];
}
@ -129,24 +133,31 @@ class GroupController extends Controller
'searchModel' => $searchModel,
'group' => $group,
'addGroupMemberForm' => new AddGroupMemberForm(),
'isManagerApprovalSetting' => Yii::$app->getModule('user')->settings->get('auth.needApproval')
'isManagerApprovalSetting' => Yii::$app->getModule('user')->settings->get('auth.needApproval'),
]);
}
public function actionRemoveGroupUser()
{
$this->forcePostRequest();
$group = Group::findOne(['id' => Yii::$app->request->get('id')]);
$group->removeUser(Yii::$app->request->get('userId'));
$request = Yii::$app->request;
$group = Group::findOne(['id' => $request->get('id')]);
if(Yii::$app->request->isAjax) {
if ($group->removeUser($request->get('userId'))) {
ExcludeGroupNotification::instance()
->about($group)
->from(Yii::$app->user->identity)
->send(User::findOne(['id' => $request->get('userId')]));
}
if ($request->isAjax) {
Yii::$app->response->format = 'json';
return ['success' => true];
}
return $this->redirect([
'/admin/group/manage-group-users',
'id' => $group->id
'id' => $group->id,
]);
}
@ -160,7 +171,7 @@ class GroupController extends Controller
$this->forcePostRequest();
$group = Group::findOne(['id' => Yii::$app->request->get('id')]);
if ($group == null) {
if ($group === null) {
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
}
@ -174,27 +185,36 @@ class GroupController extends Controller
public function actionEditManagerRole()
{
Yii::$app->response->format = 'json';
Yii::$app->response->format = Response::FORMAT_JSON;
$this->forcePostRequest();
$group = Group::findOne(Yii::$app->request->post('id'));
$value = Yii::$app->request->post('value');
if ($group == null) {
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!'));
} else if ($value == null) {
throw new HttpException(400, Yii::t('AdminModule.controllers_GroupController', 'No value found!'));
$group = Group::findOne(Yii::$app->request->post('id'));
if ($group === null) {
throw new HttpException(
404,
Yii::t('AdminModule.controllers_GroupController', 'Group not found!')
);
}
$value = Yii::$app->request->post('value');
if ($value === null) {
throw new HttpException(
400,
Yii::t('AdminModule.controllers_GroupController', 'No value found!')
);
}
$groupUser = $group->getGroupUser(User::findOne(Yii::$app->request->post('userId')));
if ($groupUser == null) {
throw new HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group user not found!'));
if ($groupUser === null) {
throw new HttpException(
404,
Yii::t('AdminModule.controllers_GroupController', 'Group user not found!')
);
}
$groupUser->is_group_manager = ($value) ? true : false;
$groupUser->save();
$groupUser->is_group_manager = (bool)$value;
return ['success' => true];
return ['success' => $groupUser->save()];
}
public function actionAddMembers()
@ -207,7 +227,7 @@ class GroupController extends Controller
return $this->redirect([
'/admin/group/manage-group-users',
'id' => $form->groupId
'id' => $form->groupId,
]);
}
@ -218,8 +238,11 @@ class GroupController extends Controller
$keyword = Yii::$app->request->get('keyword');
$group = Group::findOne(Yii::$app->request->get('id'));
$subQuery = (new Query())->select('*')->from(GroupUser::tableName(). ' g')->where([
'and', 'g.user_id=user.id', ['g.group_id' => $group->id]]);
$subQuery = (new Query())->select('*')->from(GroupUser::tableName() . ' g')->where([
'and',
'g.user_id=user.id',
['g.group_id' => $group->id],
]);
$query = User::find()->where(['not exists', $subQuery]);
@ -228,7 +251,8 @@ class GroupController extends Controller
'query' => $query,
'fillUser' => true,
'fillUserQuery' => $group->getUsers(),
'disabledText' => Yii::t('AdminModule.controllers_GroupController', 'User is already a member of this group.')
'disabledText' => Yii::t('AdminModule.controllers_GroupController',
'User is already a member of this group.'),
]);
return $result;
@ -245,7 +269,7 @@ class GroupController extends Controller
'query' => $group->getUsers(),
'keyword' => $keyword,
'fillQuery' => User::find(),
'disableFillUser' => false
'disableFillUser' => false,
]);
}

View File

@ -0,0 +1,70 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\admin\notifications;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\user\models\Group;
use yii\helpers\Html;
use yii\helpers\Url;
/**
* It occurs when a member from the group is excluded
*
* @property Group $source
* @since 1.3
*/
class ExcludeGroupNotification extends BaseNotification
{
/**
* @inheritdoc
*/
public $moduleId = 'admin';
/**
* @inheritdoc
*/
public function getUrl()
{
return Url::to(['/directory/directory/groups']);
}
/**
* @inheritdoc
*/
public function category()
{
return new AdminNotificationCategory;
}
/**
* @inheritdoc
*/
public function getMailSubject()
{
return \Yii::t(
'AdminModule.notification',
'Notify from {appName}. You were removed from the group.',
['appName' => \Yii::$app->name]
);
}
/**
* @inheritdoc
*/
public function html()
{
return \Yii::t(
'AdminModule.notification',
'{displayName} removed you from group {groupName}',
[
'{displayName}' => Html::tag('strong', Html::encode($this->originator->getDisplayName())),
'{groupName}' => Html::tag('strong', Html::encode($this->source->name)),
]
);
}
}

View File

@ -0,0 +1,69 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\admin\notifications;
use humhub\modules\notification\components\BaseNotification;
use humhub\modules\user\models\Group;
use yii\helpers\Html;
use yii\helpers\Url;
/**
* It occurs when a member from the group is included
* @property Group $source
* @since 1.3
*/
class IncludeGroupNotification extends BaseNotification
{
/**
* @inheritdoc
*/
public $moduleId = 'admin';
/**
* @inheritdoc
*/
public function getUrl()
{
return Url::to(['/directory/directory/groups']);
}
/**
* @inheritdoc
*/
public function category()
{
return new AdminNotificationCategory;
}
/**
* @inheritdoc
*/
public function getMailSubject()
{
return \Yii::t(
'AdminModule.notification',
'Notify from {appName}. You were added to the group.',
['appName' => \Yii::$app->name]
);
}
/**
* @inheritdoc
*/
public function html()
{
return \Yii::t(
'AdminModule.notification',
'{displayName} added you to group {groupName}',
[
'{displayName}' => Html::tag('strong', Html::encode($this->originator->getDisplayName())),
'{groupName}' => Html::tag('strong', Html::encode($this->source->name)),
]
);
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
/* @var $this \humhub\components\View */
/* @var $viewable humhub\modules\user\notifications\Followed */
/* @var $url string */
/* @var $date string */
/* @var $isNew boolean */
/* @var $isNew boolean */
/* @var $originator \humhub\modules\user\models\User */
/* @var $source yii\db\ActiveRecord */
/* @var $contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
/* @var $space humhub\modules\space\models\Space */
/* @var $record \humhub\modules\notification\models\Notification */
/* @var $html string */
/* @var $text string */
?>
<?php $this->beginContent('@notification/views/layouts/mail.php', $_params_); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td style="font-size: 14px; line-height: 22px; font-family:Open Sans,Arial,Tahoma, Helvetica, sans-serif; color:#555555; font-weight:300; text-align:center;">
<?= $viewable->html(); ?>
</td>
</tr>
<tr>
<td height="20"></td>
</tr>
<tr>
<td>
<?=
\humhub\widgets\mails\MailButtonList::widget([
'buttons' => [
humhub\widgets\mails\MailButton::widget([
'url' => $url,
'text' => Yii::t('SpaceModule.notifications_mails',
'View Online'),
]),
],
]);
?>
</td>
</tr>
</table>
<?php $this->endContent();

View File

@ -0,0 +1,49 @@
<?php
namespace tests\codeception\unit\modules\space;
use humhub\modules\admin\notifications\ExcludeGroupNotification;
use humhub\modules\admin\notifications\IncludeGroupNotification;
use humhub\modules\admin\notifications\php;
use humhub\modules\user\models\Group;
use humhub\modules\user\models\User;
use tests\codeception\_support\HumHubDbTestCase;
class GroupsChangesTest extends HumHubDbTestCase
{
/**
* @var \UnitTester
*/
protected $tester;
public function testAddUserToGroupNotify()
{
/** @var Group $group */
$group = Group::findOne(['id' => 1]);
$notify = IncludeGroupNotification::instance();
$notify
->about($group)
->from(User::findOne(['id' => 1]))
->send(User::findOne(['id' => 2]));
$this->assertSentEmail(1);
$this->assertEqualsLastEmailSubject($notify->getMailSubject());
}
public function testRemoveUserToGroupNotify()
{
$group = Group::findOne(['id' => 1]);
$notify = ExcludeGroupNotification::instance();
$notify
->about($group)
->from(User::findOne(['id' => 1]))
->send(User::findOne(['id' => 2]));
$this->assertSentEmail(1);
$this->assertEqualsLastEmailSubject($notify->getMailSubject());
}
}

View File

@ -17,7 +17,7 @@ use yii\db\Expression;
/**
* Description of User
*
* @property \humhub\modules\user\models\User|null $identity
* @author luke
*/
class User extends \yii\web\User
@ -183,7 +183,7 @@ class User extends \yii\web\User
/**
* Checks if the system configuration allows access for guests
*
*
* @return boolean is guest access enabled and allowed
*/
public static function isGuestAccessEnabled()

View File

@ -8,9 +8,12 @@
namespace humhub\modules\user\models;
use Yii;
use humhub\components\ActiveRecord;
use humhub\modules\admin\notifications\ExcludeGroupNotification;
use humhub\modules\admin\notifications\IncludeGroupNotification;
use humhub\modules\directory\widgets\GroupUsers;
use humhub\modules\space\models\Space;
use Yii;
/**
* This is the model class for table "group".
@ -26,6 +29,11 @@ use humhub\modules\space\models\Space;
* @property integer $show_at_registration
* @property string $updated_at
* @property integer $updated_by
*
* @property User[] $manager
* @property Space|null $defaultSpace
* @property Space|null $space
* @property GroupUsers[] groupUsers
*/
class Group extends ActiveRecord
{
@ -48,7 +56,7 @@ class Group extends ActiveRecord
return [
[['space_id', 'sort_order'], 'integer'],
[['description'], 'string'],
[['name'], 'string', 'max' => 45]
[['name'], 'string', 'max' => 45],
];
}
@ -74,6 +82,9 @@ class Group extends ActiveRecord
];
}
/**
* @return null|Space
*/
public function getDefaultSpace()
{
return Space::findOne(['id' => $this->space_id]);
@ -90,7 +101,7 @@ class Group extends ActiveRecord
/**
* Returns the admin group.
* @return type
* @return Group
*/
public static function getAdminGroup()
{
@ -109,14 +120,14 @@ class Group extends ActiveRecord
/**
* Returns all user which are defined as manager in this group as ActiveQuery.
* @return ActiveQuery
* @return \yii\db\ActiveQuery
*/
public function getManager()
{
return $this->hasMany(User::className(), ['id' => 'user_id'])
->via('groupUsers', function($query) {
$query->where(['is_group_manager' => '1']);
});
->via('groupUsers', function ($query) {
$query->where(['is_group_manager' => '1']);
});
}
/**
@ -130,7 +141,8 @@ class Group extends ActiveRecord
/**
* Returns the GroupUser relation for a given user.
* @return boolean
* @param User|string $user
* @return GroupUser|null
*/
public function getGroupUser($user)
{
@ -140,7 +152,7 @@ class Group extends ActiveRecord
/**
* Returns all GroupUser relations for this group as ActiveQuery.
* @return ActiveQuery
* @return \yii\db\ActiveQuery
*/
public function getGroupUsers()
{
@ -150,13 +162,13 @@ class Group extends ActiveRecord
/**
* Returns all member user of this group as ActiveQuery
*
* @return ActiveQuery
* @return \humhub\modules\content\components\ActiveQueryContent
*/
public function getUsers()
{
$query = User::find();
$query->leftJoin('group_user', 'group_user.user_id=user.id AND group_user.group_id=:groupId', [
':groupId' => $this->id
':groupId' => $this->id,
]);
$query->andWhere(['IS NOT', 'group_user.id', new \yii\db\Expression('NULL')]);
$query->multiple = true;
@ -172,12 +184,20 @@ class Group extends ActiveRecord
return $this->getUsers()->count() > 0;
}
/**
* @param $user
* @return bool
*/
public function isManager($user)
{
$userId = ($user instanceof User) ? $user->id : $user;
return $this->getGroupUsers()->where(['user_id' => $userId, 'is_group_manager' => true])->count() > 0;
}
/**
* @param $user
* @return bool
*/
public function isMember($user)
{
return $this->getGroupUser($user) != null;
@ -187,7 +207,7 @@ class Group extends ActiveRecord
* Adds a user to the group. This function will skip if the user is already
* a member of the group.
* @param User $user user id or user model
* @param type $isManager
* @param bool $isManager
*/
public function addUser($user, $isManager = false)
{
@ -203,21 +223,32 @@ class Group extends ActiveRecord
$newGroupUser->created_at = new \yii\db\Expression('NOW()');
$newGroupUser->created_by = Yii::$app->user->id;
$newGroupUser->is_group_manager = $isManager;
$newGroupUser->save();
if ($newGroupUser->save() && !Yii::$app->user->isGuest) {
IncludeGroupNotification::instance()
->about($this)
->from(Yii::$app->user->identity)
->send(User::findOne(['id' => $userId]));
}
}
/**
* Removes a user from the group.
* @param type $user userId or user model
* @param User|string $user userId or user model
* @return bool
*/
public function removeUser($user)
{
$groupUser = $this->getGroupUser($user);
if ($groupUser != null) {
$groupUser->delete();
if ($groupUser === null) {
return false;
}
return $groupUser->delete();
}
/**
* @return \yii\db\ActiveQuery
*/
public function getSpace()
{
return $this->hasOne(Space::className(), ['id' => 'space_id']);
@ -228,11 +259,14 @@ class Group extends ActiveRecord
* This should be done after a new user is created and approval is required.
*
* @todo Create message template, move message into translation
* @param User $user
* @return true|void
*/
public static function notifyAdminsForUserApproval($user)
{
// No admin approval required
if ($user->status != User::STATUS_NEED_APPROVAL || !Yii::$app->getModule('user')->settings->get('auth.needApproval', 'user')) {
if ($user->status != User::STATUS_NEED_APPROVAL ||
!Yii::$app->getModule('user')->settings->get('auth.needApproval', 'user')) {
return;
}
@ -247,9 +281,12 @@ class Group extends ActiveRecord
Yii::$app->i18n->setUserLocale($manager);
$html = Yii::t('UserModule.adminUserApprovalMail', 'Hello {displayName},', ['displayName' => $manager->displayName]) . "<br><br>\n\n" .
Yii::t('UserModule.adminUserApprovalMail', 'a new user {displayName} needs approval.', ['displayName' => $user->displayName]) . "<br><br>\n\n" .
Yii::t('UserModule.adminUserApprovalMail', 'Please click on the link below to view request:') . "<br>\n\n" .
$html = Yii::t('UserModule.adminUserApprovalMail', 'Hello {displayName},',
['displayName' => $manager->displayName]) . "<br><br>\n\n" .
Yii::t('UserModule.adminUserApprovalMail', 'a new user {displayName} needs approval.',
['displayName' => $user->displayName]) . "<br><br>\n\n" .
Yii::t('UserModule.adminUserApprovalMail', 'Please click on the link below to view request:') .
"<br>\n\n" .
\yii\helpers\Html::a($approvalUrl, $approvalUrl) . "<br/> <br/>\n";
$mail = Yii::$app->mailer->compose(['html' => '@humhub/views/mail/TextOnly'], [
@ -289,9 +326,15 @@ class Group extends ActiveRecord
return $groups;
}
/**
* @return array|\yii\db\ActiveRecord[]
*/
public static function getDirectoryGroups()
{
return self::find()->where(['show_at_directory' => '1'])->orderBy(['sort_order' => SORT_ASC, 'name' => SORT_ASC])->all();
return self::find()->where(['show_at_directory' => '1'])->orderBy([
'sort_order' => SORT_ASC,
'name' => SORT_ASC,
])->all();
}
}