1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
8
|
|
|
* @link https://vistart.me/ |
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
10
|
|
|
* @license https://vistart.me/license/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace rhosocial\organization\web\organization\controllers\my; |
14
|
|
|
|
15
|
|
|
use rhosocial\organization\exceptions\UnauthorizedManageMemberException; |
16
|
|
|
use rhosocial\organization\web\organization\Module; |
17
|
|
|
use rhosocial\organization\Organization; |
18
|
|
|
use rhosocial\organization\rbac\permissions\ManageMember; |
19
|
|
|
use rhosocial\user\User; |
20
|
|
|
use rhosocial\user\UserProfileSearch; |
21
|
|
|
use Yii; |
22
|
|
|
use yii\base\Action; |
23
|
|
|
use yii\web\ServerErrorHttpException; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* |
27
|
|
|
* @version 1.0 |
28
|
|
|
* @author vistart <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class AddMemberAction extends Action |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Check access. |
34
|
|
|
* @param Organization $org |
35
|
|
|
* @param User $user |
36
|
|
|
* @return boolean |
37
|
|
|
* @throws UnauthorizedManageMemberException |
38
|
|
|
*/ |
39
|
|
|
public static function checkAccess($org, $user) |
40
|
|
|
{ |
41
|
|
|
MemberAction::checkAccess($org, $user); |
42
|
|
|
if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageMember)->name, ['organization' => $org])) { |
43
|
|
|
throw new UnauthorizedManageMemberException(); |
44
|
|
|
} |
45
|
|
|
return true; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function run($org, $user = null) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$organization = Module::getOrganization($org); |
51
|
|
|
$user = Yii::$app->user->identity; |
52
|
|
|
static::checkAccess($organization, $user); |
53
|
|
|
if (!class_exists($this->controller->userProfileSearchClass)) { |
54
|
|
|
throw new ServerErrorHttpException('Unknown User Profile View.'); |
55
|
|
|
} |
56
|
|
|
$class = $this->controller->userProfileSearchClass; |
57
|
|
|
$searchModel = new $class(); |
58
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->post()); |
59
|
|
|
return $this->controller->render('add-member', ['org' => $org, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.