Passed
Push — master ( fd0cb1...02c72e )
by vistart
05:12
created

RevokeAction::run()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 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\user\controllers\organization;
14
15
use rhosocial\organization\exceptions\RevokePreventedException;
16
use rhosocial\organization\web\user\controllers\OrganizationController;
17
use Yii;
18
use yii\base\Action;
19
use yii\base\InvalidParamException;
20
use yii\web\BadRequestHttpException;
21
use yii\web\ServerErrorHttpException;
22
23
/**
24
 * @version 1.0
25
 * @author vistart <[email protected]>
26
 */
27
class RevokeAction extends Action
28
{
29
    /**
30
     * Revoke organization or department.
31
     * @param string|integer $id
32
     * @throws ServerErrorHttpException
33
     */
34
    public function run($id)
35
    {
36
        try {
37
            Yii::$app->user->identity->revokeOrganization($id, true);
38
        } catch (InvalidParamException $ex) {
39
            throw new BadRequestHttpException(Yii::t('organization', $ex->getMessage()));
40
        } catch (RevokePreventedException $ex) {
41
            throw new BadRequestHttpException(Yii::t('organization', $ex->getMessage()));
42
        } catch (\Exception $ex) {
43
            throw new ServerErrorHttpException($ex->getMessage());
44
        }
45
        Yii::$app->session->setFlash(OrganizationController::SESSION_KEY_RESULT, OrganizationController::RESULT_SUCCESS);
46
        Yii::$app->session->setFlash(OrganizationController::SESSION_KEY_MESSAGE, "($id) " . $this->controller->organizationRevokeSuccessMessage);
47
        return $this->controller->redirect(['list']);
48
    }
49
}
50