|
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\Member; |
|
17
|
|
|
use rhosocial\organization\rbac\permissions\ManageMember; |
|
18
|
|
|
use rhosocial\organization\web\organization\Module; |
|
19
|
|
|
use Yii; |
|
20
|
|
|
use yii\base\Action; |
|
21
|
|
|
use yii\web\BadRequestHttpException; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class UpdateMemberAction |
|
25
|
|
|
* @package rhosocial\organization\web\organization\controllers\my |
|
26
|
|
|
* @version 1.0 |
|
27
|
|
|
* @author vistart <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class UpdateMemberAction extends Action |
|
30
|
|
|
{ |
|
31
|
|
|
public $updateSuccessMessage; |
|
32
|
|
|
public $updateFailedMessage; |
|
33
|
|
|
|
|
34
|
|
|
protected function initMessages() |
|
35
|
|
|
{ |
|
36
|
|
|
if (!is_string($this->updateSuccessMessage)) { |
|
37
|
|
|
$this->updateSuccessMessage = Yii::t('user' ,'Updated.'); |
|
38
|
|
|
} |
|
39
|
|
|
if (!is_string($this->updateFailedMessage)) { |
|
40
|
|
|
$this->updateFailedMessage = Yii::t('user', 'Failed to Update.'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function init() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->initMessages(); |
|
47
|
|
|
parent::init(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Check access. |
|
52
|
|
|
* @param $org |
|
53
|
|
|
* @param $user |
|
54
|
|
|
* @return bool |
|
55
|
|
|
* @throws UnauthorizedManageMemberException |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function checkAccess($org, $user) |
|
58
|
|
|
{ |
|
59
|
|
|
MemberAction::checkAccess($org, $user); |
|
60
|
|
|
if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageMember)->name, ['organization' => $org])) { |
|
61
|
|
|
throw new UnauthorizedManageMemberException(); |
|
62
|
|
|
} |
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Update member. |
|
68
|
|
|
* @param $org string Organization ID. |
|
69
|
|
|
* @param $user string User ID. |
|
70
|
|
|
* @return string|\yii\web\Response |
|
71
|
|
|
*/ |
|
72
|
|
|
public function run($org, $user) |
|
73
|
|
|
{ |
|
74
|
|
|
$organization = Module::getOrganization($org); |
|
75
|
|
|
$member = $organization->getMember($user); |
|
76
|
|
|
static::checkAccess($organization, Yii::$app->user->identity); |
|
77
|
|
|
|
|
78
|
|
|
$member->scenario = Member::SCENARIO_ADMIN_UPDATE; |
|
79
|
|
|
if ($member->load(Yii::$app->request->post())) { |
|
80
|
|
|
if ($member->save()) { |
|
81
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); |
|
82
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->updateSuccessMessage); |
|
83
|
|
|
return $this->controller->redirect(['member', 'org' => $org]); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); |
|
86
|
|
|
Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $this->updateFailedMessage); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $this->controller->render('update-member', ['model' => $member]); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: