Merge branch 'master' of github.com:humhub/humhub

This commit is contained in:
Lucas Bartholemy 2017-10-03 19:32:19 +02:00
commit 268fdde5de
20 changed files with 43 additions and 299 deletions

View File

@ -13,6 +13,7 @@ use humhub\components\behaviors\AccessControl;
use Yii;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\web\ForbiddenHttpException;
/**
* Base Controller
@ -169,7 +170,7 @@ class Controller extends \yii\web\Controller
*/
protected function forbidden()
{
throw new \yii\web\ForbiddenHttpException(Yii::t('error', 'You are not allowed to perform this action.'));
throw new ForbiddenHttpException(Yii::t('error', 'You are not allowed to perform this action.'));
}
/**
@ -273,12 +274,11 @@ class Controller extends \yii\web\Controller
* This is required for some modules in pjax mode.
*
* @since 1.2
* @param type $url
*/
public function setJsViewStatus()
{
$modluleId = (Yii::$app->controller->module) ? Yii::$app->controller->module->id : '';
$this->view->registerJs('humhub.modules.ui.view.setState("' . $modluleId . '", "' . Yii::$app->controller->id . '", "' . Yii::$app->controller->action->id . '");', \yii\web\View::POS_BEGIN);
$moduleId = (Yii::$app->controller->module) ? Yii::$app->controller->module->id : '';
$this->view->registerJs('humhub.modules.ui.view.setState("' . $moduleId . '", "' . Yii::$app->controller->id . '", "' . Yii::$app->controller->action->id . '");', \yii\web\View::POS_BEGIN);
if (Yii::$app->request->isPjax) {
\humhub\widgets\TopMenu::setViewState();

View File

@ -98,7 +98,7 @@ abstract class SocialActivity extends \yii\base\Object implements rendering\View
/**
* Builder function for the originator.
*
* @param type $originator
* @param User $originator
* @return \humhub\components\SocialActivity
*/
public function from($originator)

View File

@ -64,7 +64,7 @@ abstract class ActionAccessValidator extends AccessValidator
}
/**
* Filters our rules not related to the current validator and action.
* Filters out rules not related to the current validator and action.
*
* @param array|null $rules
* @return array

View File

@ -41,7 +41,7 @@ class PermissionAccessValidator extends ActionAccessValidator
/**
* Checks if the user has the given $permission.
*
* @param string|string[]|BasePermission $permission
* @param string|string[]| \humhub\libs\BasePermission $permission
* @param array $params
* @param array $rule
* @return bool true if the given $permission is granted

View File

@ -71,7 +71,7 @@ class Controller extends \humhub\components\Controller
// Use by default ManageModule permission, if method is not overwritten by custom module
if ($this->module->id != 'admin') {
return [
['permissions' => \humhub\modules\admin\permissions\ManageModules::className()]
['permission' => \humhub\modules\admin\permissions\ManageModules::className()]
];
}

View File

@ -1,38 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
/**
* Created by PhpStorm.
* User: buddha
* Date: 19.09.2017
* Time: 16:29
*/
namespace humhub\modules\mobile;
use Yii;
use yii\helpers\Url;
class Events extends \yii\base\Object
{
/**
* @param $event
*/
public static function onAccountMenuInit($event)
{
$event->sender->addItem([
'label' => Yii::t('MobileModule.base', 'Devices'),
'id' => 'directory',
'icon' => '<i class="fa fa-mobile-phone"></i>',
'url' => Url::to(['/mobile/settings']),
'sortOrder' => 500,
'isActive' => Yii::$app->controller->module === 'mobile',
]);
}
}

View File

@ -1,79 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
namespace humhub\modules\mobile;
use Yii;
use humhub\modules\user\models\User;
use humhub\modules\space\models\Space;
/**
* Mobile Module
*/
class Module extends \humhub\components\Module
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'humhub\modules\mobile\controllers';
/**
* @inheritdoc
*/
public $defaultRoute = 'index';
/**
* @inheritdoc
*/
public $isCoreModule = true;
/**
* @inheritdoc
*/
public $resourcesPath = 'resources';
/**
* @inheritdoc
*/
public function getName()
{
return Yii::t('MobileModule.base', 'Mobile');
}
/**
* @inheritdoc
*/
public function getPermissions($contentContainer = null)
{
// E.g: Permission if user is allowed to access with mobile app?
if ($contentContainer instanceof Space) {
return [];
} elseif ($contentContainer instanceof User) {
return [];
}
return [];
}
/**
* @inheritdoc
*/
public function getNotifications()
{
// E.g: A new device was registered to your account, if this is not your device,...
if (Yii::$app->user->isAdmin()) {
return [];
}
return [];
}
}

View File

@ -1,33 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
/**
* Created by PhpStorm.
* User: buddha
* Date: 19.09.2017
* Time: 16:00
*/
namespace humhub\modules\mobile\assets;
use yii\web\AssetBundle;
class MobileAsset extends AssetBundle
{
public $publishOptions = [
'forceCopy' => true
];
public $sourcePath = '@mobile/resources';
public $css = [];
public $js = [
'js/humhub.mobile.js'
];
}

View File

@ -1,20 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
use humhub\modules\mobile\Events;
use humhub\modules\user\widgets\AccountMenu;
return [
'id' => 'mobile',
'class' => \humhub\modules\mobile\Module::className(),
'isCoreModule' => true,
'events' => [
['class' => AccountMenu::class, 'event' => AccountMenu::EVENT_INIT, 'callback' => [Events::class, 'onAccountMenuInit']],
],
];

View File

@ -1,28 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
/**
* Created by PhpStorm.
* User: buddha
* Date: 19.09.2017
* Time: 16:04
*/
namespace humhub\modules\mobile\controllers;
use humhub\modules\user\components\BaseAccountController;
class SettingsController extends BaseAccountController
{
public function actionIndex()
{
return $this->render('device', []);
}
}

View File

@ -1,9 +0,0 @@
{
"id": "mobile",
"name": "Mobile",
"description": "Mobile Core",
"keywords": [
"mobile"
],
"version": "1.0"
}

View File

@ -1,16 +0,0 @@
humhub.module('mobile', function (module, require, $) {
var init = function() {
};
var close = function(evt) {
module.closed = true;
};
module.export({
init: init,
close: close,
closed: false
});
});

View File

@ -1,35 +0,0 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
\humhub\modules\mobile\assets\MobileAsset::register($this);
?>
<div class="panel-heading">
<?= Yii::t('MobileModule.settings', '<strong>Device</strong> settings'); ?>
</div>
<div class="panel-body">
<?= \humhub\widgets\Button::primary('Close')->action('mobile.close') ?>
<div class="table-responsive">
<table class="table">
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<?php foreach (Yii::$app->request->headers as $key => $value) : ?>
<tr>
<td><?= $key ?></td>
<td><?= $value[0] ?></td>
</tr>
<?php endforeach ?>
</table>
</div>
</div>

View File

@ -8,6 +8,7 @@
namespace humhub\modules\notification\components;
use humhub\components\SocialActivity;
use Yii;
use yii\helpers\Url;
use yii\bootstrap\Html;
@ -30,7 +31,7 @@ use humhub\modules\notification\targets\WebTarget;
*
* @author luke
*/
abstract class BaseNotification extends \humhub\components\SocialActivity
abstract class BaseNotification extends SocialActivity
{
/**
@ -227,7 +228,7 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
public function about($source)
{
if (!$source) {
return;
return $this;
}
parent::about($source);
$this->record->space_id = $this->getSpaceId();
@ -240,7 +241,7 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
public function from($originator)
{
if (!$originator) {
return;
return $this;
}
$this->originator = $originator;
$this->record->originator_user_id = $originator->id;
@ -395,7 +396,7 @@ abstract class BaseNotification extends \humhub\components\SocialActivity
/**
* Should be overwritten by subclasses for a html representation of the notification.
* @return type
* @return string
*/
public function html()
{

View File

@ -32,7 +32,7 @@ abstract class BaseTarget extends \yii\base\Object
/**
* Holds the title of this instance.
* @var type
* @var string
*/
public $title;

View File

@ -27,7 +27,7 @@ class MailTarget extends BaseTarget
/**
* Enable this target by default.
* @var type
* @var boolean
*/
public $defaultSetting = true;

View File

@ -14,6 +14,7 @@ use humhub\modules\activity\models\Activity;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "user_follow".
@ -177,8 +178,8 @@ class Follow extends \yii\db\ActiveRecord
* If $withNotifications is set only follower with the given send_notifications setting are returned.
*
* @param \yii\db\ActiveRecord $target
* @param type $withNotifications
* @return type
* @param boolean $withNotifications
* @return ActiveQuery
*/
public static function getFollowersQuery(\yii\db\ActiveRecord $target, $withNotifications = null)
{

View File

@ -1,4 +1,4 @@
<?php //[STAMP] f9ed9aa7fd682776d6da0937c3035ef3
<?php //[STAMP] b7022a07eb89fcf11fbefbc08b0b59b6
namespace _generated;
// This class was automatically generated by build task

View File

@ -44,7 +44,7 @@
),
'params' =>
array (
'config_created_at' => 1504018611,
'config_created_at' => 1506096506,
'horImageScrollOnMobile' => NULL,
),
); ?>

View File

@ -153,7 +153,7 @@ class ControllerAccessTest extends HumHubDbTestCase
]]);
$this->assertFalse($controllerAccess->run());
$this->assertEquals(401, $controllerAccess->code );
$this->assertEquals(401, $controllerAccess->code);
$this->assertEquals('Your user account is inactive, please login with an active account or contact a network administrator.', $controllerAccess->reason);
// UnnapprovedUser
@ -165,7 +165,7 @@ class ControllerAccessTest extends HumHubDbTestCase
]]);
$this->assertFalse($controllerAccess->run());
$this->assertEquals(401, $controllerAccess->code );
$this->assertEquals(401, $controllerAccess->code);
$this->assertEquals('Your user account has not been approved yet, please try again later or contact a network administrator.', $controllerAccess->reason);
}
@ -217,7 +217,7 @@ class ControllerAccessTest extends HumHubDbTestCase
// Guest has no permission
$accessCheck = new ControllerAccess([
'rules' => [
['permissions' => [AccessTestPermission1::class]]
['permission' => [AccessTestPermission1::class]]
],
'action' => 'testAction'
]);
@ -228,7 +228,7 @@ class ControllerAccessTest extends HumHubDbTestCase
$this->becomeUser('User1');
$accessCheck = new ControllerAccess([
'rules' => [
['permissions' => [AccessTestPermission2::class]]
['permission' => [AccessTestPermission2::class]]
],
'action' => 'testAction'
]);
@ -236,20 +236,20 @@ class ControllerAccessTest extends HumHubDbTestCase
// Permission2 included
$accessCheck->rules = [
['permissions' => [AccessTestPermission1::class, AccessTestPermission2::class]]
['permission' => [AccessTestPermission1::class, AccessTestPermission2::class]]
];
$this->assertTrue($accessCheck->run());
// In strict mode both permission have to be granted
$accessCheck->rules = [
['permissions' => [AccessTestPermission1::class, AccessTestPermission2::class], 'strict' => true]
['permission' => [AccessTestPermission1::class, AccessTestPermission2::class], 'strict' => true]
];
$this->assertFalse($accessCheck->run());
// Check two permission rules one non action related and one global valid one. The non action related should be ignored
// Check two permission rules one action related and one global valid one. The non action related should be ignored
$accessCheck->rules = [
['permissions' => [AccessTestPermission2::class], 'actions' => 'otherPermission'],
['permissions' => [AccessTestPermission1::class, AccessTestPermission2::class]]
['permission' => [AccessTestPermission2::class], 'actions' => 'otherPermission'],
['permission' => [AccessTestPermission1::class, AccessTestPermission2::class]]
];
$this->assertTrue($accessCheck->run());
@ -257,23 +257,23 @@ class ControllerAccessTest extends HumHubDbTestCase
// Check non strict behaviour of permissoin rule with one not allowed global rule which is overwritten by action related
// This check passes, since only one of them has to pass.
$accessCheck->rules = [
['permissions' => [AccessTestPermission2::class]],
['permissions' => [AccessTestPermission1::class], 'actions' => 'testAction']
['permission' => [AccessTestPermission2::class]],
['permission' => [AccessTestPermission1::class], 'actions' => 'testAction']
];
$this->assertTrue($accessCheck->run());
// Check string permission definition
$accessCheck->rules = [
['permissions' => AccessTestPermission1::class]
['permission' => AccessTestPermission1::class]
];
$this->assertTrue($accessCheck->run());
// Check permission rule in combination with adminOnly
$accessCheck->rules = [
[ControllerAccess::RULE_ADMIN_ONLY],
['permissions' => [AccessTestPermission2::class], 'actions' => 'otherPermission'],
['permissions' => [AccessTestPermission1::class, AccessTestPermission2::class]]
['permission' => [AccessTestPermission2::class], 'actions' => 'otherPermission'],
['permission' => [AccessTestPermission1::class, AccessTestPermission2::class]]
];
$this->assertFalse($accessCheck->run());
}
@ -331,19 +331,19 @@ class ControllerAccessTest extends HumHubDbTestCase
// Global permission rule
$accessCheck->rules = [
['permissions' => [AccessTestPermission1::class]]
['permission' => [AccessTestPermission1::class]]
];
$this->assertFalse($accessCheck->run());
// Non action related permission rule
$accessCheck->rules = [
['permissions' => AccessTestPermission1::class, 'actions' => ['otherTestAction']]
['permission' => AccessTestPermission1::class, 'actions' => ['otherTestAction']]
];
$this->assertTrue($accessCheck->run());
// Matching action related permission setting
$accessCheck->rules = [
['permissions' => [AccessTestPermission1::class], 'actions' => ['otherTestAction', 'testAction']]
['permission' => [AccessTestPermission1::class], 'actions' => ['otherTestAction', 'testAction']]
];
$this->assertFalse($accessCheck->run());
@ -361,7 +361,7 @@ class ControllerAccessTest extends HumHubDbTestCase
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'rules' => []]);
$this->assertFalse($controllerAccess->run());
$this->assertEquals(401, $controllerAccess->code );
$this->assertEquals(401, $controllerAccess->code);
$this->assertEquals('Your user account is inactive, please login with an active account or contact a network administrator.', $controllerAccess->reason);
// UnnapprovedUser
@ -370,7 +370,7 @@ class ControllerAccessTest extends HumHubDbTestCase
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'rules' => []]);
$this->assertFalse($controllerAccess->run());
$this->assertEquals(401, $controllerAccess->code );
$this->assertEquals(401, $controllerAccess->code);
$this->assertEquals('Your user account has not been approved yet, please try again later or contact a network administrator.', $controllerAccess->reason);
}
@ -410,7 +410,7 @@ class ControllerAccessTest extends HumHubDbTestCase
$this->assertEquals(404, $controllerAccess->code);
$this->assertEquals('Not you again!', $controllerAccess->reason);
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
['validateTestRule', 'return' => true]
]]);
@ -422,7 +422,7 @@ class ControllerAccessTest extends HumHubDbTestCase
public function validateTestRule($rule, $access)
{
$this->assertEquals($access->owner, $this);
if(!$rule['return']) {
if (!$rule['return']) {
$access->code = 404;
$access->reason = 'Not you again!';
return false;
@ -433,7 +433,7 @@ class ControllerAccessTest extends HumHubDbTestCase
public function testCustomClassRule()
{
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
[TestActionValidator::class, 'return' => false]
]]);
@ -441,7 +441,7 @@ class ControllerAccessTest extends HumHubDbTestCase
$this->assertEquals(404, $controllerAccess->code);
$this->assertEquals('Not you again!', $controllerAccess->reason);
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
$controllerAccess = new ControllerAccess(['action' => 'testAction', 'owner' => $this, 'rules' => [
[TestActionValidator::class, 'return' => true]
]]);