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

SettingsAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 29
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkAccess() 0 8 2
A run() 0 7 1
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