File: /home/aliazzsr/api.crm.vqode.com/controllers/RoleController.php
<?php
namespace app\controllers;
use app\components\BaseActiveController;
use app\models\enums\PermissionEnum;
class RoleController extends BaseActiveController
{
public $modelClass = 'app\models\core\Role';
protected static $permissionRequired = PermissionEnum::USERS;
protected static $actionPermissionMap = [
'index' => 'read',
'view' => 'read',
'validate' => 'read',
'permissions' => 'update',
'options' => 'read',
'create' => 'create',
'update' => 'update',
'delete' => 'delete',
];
public function actions()
{
$actions = parent::actions();
$actions['permissions'] = [
'class' => 'app\components\actions\PermissionsAction',
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkAccess'],
];
return $actions;
}
}
/**
* @SWG\Get(
* path="/roles",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Finds Role records existing.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Response(response=200, description="Successful operation.",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Role"))
* ),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Get(
* path="/roles/{id}",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Returns a single Role record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="ID", in="path", name="id", required=true, type="integer"),
* @SWG\Response(response=200, description="Successful operation.", @SWG\Schema(ref="#/definitions/Role")),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Get(
* path="/roles/{id}/permissions",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Returns an array of role permissions.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Role identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Response(response=200, description="Successful operation.", @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/CrudPermission"))),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Put(
* path="/roles/{id}/permissions",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Updates role permissions.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Role identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Parameter(description="Permissions to set.", name="body", required=true, in="body",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/CrudPermission"))),
* @SWG\Response(response=200, description="Successful operation.", @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/CrudPermission"))),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Post(
* path="/roles",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Creates a new Role record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(
* ref="#/definitions/Role", required={"name"}
* )),
* @SWG\Response(response=201, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Put(
* path="/roles/{id}",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Updates an existed Role record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="ID", in="path", name="id", required=true, type="integer"),
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(
* ref="#/definitions/Role")),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Delete(
* path="/roles/{id}",
* tags={"Role"},
* security={{"bearer":{}}},
* summary="Deletes a Role record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="ID", in="path", name="id", required=true, type="integer"),
* @SWG\Response(response=204, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*/
/**
* @SWG\Definition(
* definition="CrudPermission",
* type="object",
* description="CrudPermission model",
* allOf={
* @SWG\Schema(
* @SWG\Property(property="name", type="string", example="References"),
* @SWG\Property(property="create", type="boolean", example=true),
* @SWG\Property(property="read", type="boolean", example=true),
* @SWG\Property(property="update", type="boolean", example=true),
* @SWG\Property(property="delete", type="boolean", example=false)
* )
* }
* )
*/