Blame view

console/controllers/CommentRulesController.php 2.11 KB
b82db04a   Yarik   test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  <?php
      namespace console\controllers;
  
      use common\components\rules\CommentOwnRule;
      use yii\console\Controller;
      use yii\rbac\Permission;
  
      class CommentRulesController extends Controller
      {
          public function actionCreate() {
              $auth = \Yii::$app->getAuthManager();
              $commentownrule = new CommentOwnRule();
              $auth->add($commentownrule);
              $auth->add(new Permission([
                  'name' => 'Update own comment',
                  'ruleName' => $commentownrule->name,
                  'description' => 'Can update own comment',
              ]));
              $auth->add(new Permission([
                  'name' => 'Delete own comment',
                  'ruleName' => $commentownrule->name,
                  'description' => 'Can delete own comment',
              ]));
              return 'Success';
          }
  
          public function actionUpdate()
          {
              $auth = \Yii::$app->getAuthManager();
              $commentownrule = new CommentOwnRule();
              $auth->add(new Permission([
                  'name' => \rmrevin\yii\module\Comments\Permission::CREATE,
                  'description' => 'Can create own comments',
              ]));
              $auth->add(new Permission([
                  'name' => \rmrevin\yii\module\Comments\Permission::UPDATE,
                  'description' => 'Can update all comments',
              ]));
              $auth->add(new Permission([
                  'name' => \rmrevin\yii\module\Comments\Permission::UPDATE_OWN,
                  'ruleName' => $commentownrule->name,
                  'description' => 'Can update own comments',
              ]));
              $auth->add(new Permission([
                  'name' => \rmrevin\yii\module\Comments\Permission::DELETE,
                  'description' => 'Can delete all comments',
              ]));
              $auth->add(new Permission([
                  'name' => \rmrevin\yii\module\Comments\Permission::DELETE_OWN,
                  'ruleName' => $commentownrule->name,
                  'description' => 'Can delete own comments',
              ]));
              echo 'ok';
              return 'ok';
          }
      }