Completed
Push — master ( d982bf...8c401a )
by vistart
24:10
created

SettingsAction::checkAccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 5
nc 2
nop 2
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\UnauthorizedManageProfileException;
16
use rhosocial\organization\rbac\permissions\ManageProfile;
17
use rhosocial\organization\web\organization\Module;
18
use Yii;
19
use yii\base\Action;
20
21
/**
22
 * Class SettingsAction
23
 * @package rhosocial\organization\web\organization\controllers\my
24
 * @version 1.0
25
 * @author vistart <[email protected]>
26
 */
27
class SettingsAction extends Action
28
{
29
    /**
30
     * Check access.
31
     * @param $org
32
     * @param $user
33
     * @return bool
34
     * @throws UnauthorizedManageProfileException
35
     */
36
    public static function checkAccess($org, $user)
37
    {
38
        MemberAction::checkAccess($org, $user);
39
        if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageProfile)->name, ['organization' => $org])) {
40
            throw new UnauthorizedManageProfileException();
41
        }
42
        return true;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function run($id)
49
    {
50
        $organization = Module::getOrganization($id);
51
        $user = Yii::$app->user->identity;
52
        static::checkAccess($organization, $user);
53
        return $this->controller->render('settings', ['organization' => $organization]);
54
    }
55
}
56