original_string: public function actionPermission($user, $operation, $permission)
      {
          $user = $this->getUser($user);
          $permission = Yii::$app->authManager->getPermission($permission);
          if ($operation == 'assign') {
              try {
                  $assignment = Yii::$app->authManager->assign($permission, $user);
              } catch (\yii\db\IntegrityException $ex) {
                  echo "Failed to assign `" . $permission->name . "`.\n";
                  echo "Maybe the permission has been assigned.\n";
                  return static::EXIT_CODE_ERROR;
              }
              if ($assignment) {
                  echo "`$permission->name`" . " assigned to User (" . $user->getID() . ") successfully.\n";
              } else {
                  echo "Failed to assign `" . $permission->name . "`.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          if ($operation == 'revoke') {
              $assignment = Yii::$app->authManager->revoke($permission, $user);
              if ($assignment) {
                  echo "`$permission->name`" . " revoked from User (" . $user->getID() . ").\n";
              } else {
                  echo "Failed to revoke `" . $permission->name . "`.\n";
                  echo "Maybe the permission has not been assigned yet.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          echo "Unrecognized operation: $operation.\n";
          echo "The accepted operations are `assign` and `revoke`.\n";
          return static::EXIT_CODE_ERROR;
      }
code: public function actionPermission($user, $operation, $permission)
      {
          $user = $this->getUser($user);
          $permission = Yii::$app->authManager->getPermission($permission);
          if ($operation == 'assign') {
              try {
                  $assignment = Yii::$app->authManager->assign($permission, $user);
              } catch (\yii\db\IntegrityException $ex) {
                  echo "Failed to assign `" . $permission->name . "`.\n";
                  echo "Maybe the permission has been assigned.\n";
                  return static::EXIT_CODE_ERROR;
              }
              if ($assignment) {
                  echo "`$permission->name`" . " assigned to User (" . $user->getID() . ") successfully.\n";
              } else {
                  echo "Failed to assign `" . $permission->name . "`.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          if ($operation == 'revoke') {
              $assignment = Yii::$app->authManager->revoke($permission, $user);
              if ($assignment) {
                  echo "`$permission->name`" . " revoked from User (" . $user->getID() . ").\n";
              } else {
                  echo "Failed to revoke `" . $permission->name . "`.\n";
                  echo "Maybe the permission has not been assigned yet.\n";
              }
              return static::EXIT_CODE_NORMAL;
          }
          echo "Unrecognized operation: $operation.\n";
          echo "The accepted operations are `assign` and `revoke`.\n";
          return static::EXIT_CODE_ERROR;
      }
code_tokens: public function actionPermission ( $ user , $ operation , $ permission ) { $ user = $ this -> getUser ( $ user ) ; $ permission = Yii :: $ app -> authManager -> getPermission ( $ permission ) ; if ( $ operation == 'assign' ) { try { $ assignment = Yii :: $ app -> authManager -> assign ( $ permission , $ user ) ; } catch ( \ yii \ db \ IntegrityException $ ex ) { echo "Failed to assign `" . $ permission -> name . "`.\n" ; echo "Maybe the permission has been assigned.\n" ; return static :: EXIT_CODE_ERROR ; } if ( $ assignment ) { echo "`$permission->name`" . " assigned to User (" . $ user -> getID ( ) . ") successfully.\n" ; } else { echo "Failed to assign `" . $ permission -> name . "`.\n" ; } return static :: EXIT_CODE_NORMAL ; } if ( $ operation == 'revoke' ) { $ assignment = Yii :: $ app -> authManager -> revoke ( $ permission , $ user ) ; if ( $ assignment ) { echo "`$permission->name`" . " revoked from User (" . $ user -> getID ( ) . ").\n" ; } else { echo "Failed to revoke `" . $ permission -> name . "`.\n" ; echo "Maybe the permission has not been assigned yet.\n" ; } return static :: EXIT_CODE_NORMAL ; } echo "Unrecognized operation: $operation.\n" ; echo "The accepted operations are `assign` and `revoke`.\n" ; return static :: EXIT_CODE_ERROR ; }
docstring: Assign a permission to user or revoke a permission.
  @param User|string|integer $user User ID.
  @param string $operation Only `assign` and `revoke` are acceptable.
  @param string $permission Permission name.
  @return int
docstring_tokens: Assign a permission to user or revoke a permission .