Setup permission data

@param $route

@return array
480896
private function getPermissionData($route)
    {
        $description = '';
        $chunks = explode('\\', $route['controller']);
        $module = strtolower(end($chunks));
        $module = str_replace('controller', '', $module);

        $messages = [
            'index'   => 'List all :modules',
            'create'  => 'Create :modules',
            'show'    => 'Preview :module',
            'edit'    => 'Update :modules',
            'destroy' => 'Delete :modules'
        ];
        $pattern = [
            '#:module#',
            '#:modules#'
        ];
        $replacement = [
            $module,
            str_plural($module)
        ];

        if (array_key_exists($route['action'], $messages)) {
            $description = preg_replace($pattern, $replacement, $messages[$route['action']]);
        }

        return [
            'resource'    => $route['resource'],
            'controller'  => $route['controller'],
            'method'      => $route['action'],
            'description' => $description,
        ];
    }
471372
public function permissions($model = NULL) {

        if(!$this->Auth->user()){
            $this->Flash->error(__('Please sign in'));
            $this->redirect(['action' => 'index']);
        }
        
        $this->model = $model;

        // Saving permissions
        if ($this->request->is('post') || $this->request->is('put')) {
            $perms = isset($this->request->data['Perms']) ? $this->request->data['Perms'] : array();
            foreach ($perms as $aco => $aros) {
                $action = str_replace(":", "/", $aco);
                foreach ($aros as $node => $perm) {
                    list($model, $id) = explode(':', $node);
                    $node = array('model' => $model, 'foreign_key' => $id);
                    if ($perm == 'allow') {
                        $this->Acl->allow($node, $action);
                    } elseif ($perm == 'inherit') {
                        $this->Acl->inherit($node, $action);
                    } elseif ($perm == 'deny') {
                        $this->Acl->deny($node, $action);
                    }
                }
            }
        }

        if (!$model || !in_array($model, Configure::read('AclManager.aros'))) {
            $m = Configure::read('AclManager.aros');
            $model = $m[0];
        }

        $Aro = $this->{$model};
        $arosRes = $this->paginate($Aro->alias());
        $aros = $this->_parseAros($arosRes);
        $permKeys = $this->_getKeys();

        /**
         * Build permissions info
         */
        $acosRes = $this->Acl->Aco->find('all', ['order' => 'lft ASC'])->contain(['Aros'])->toArray();
        $this->acos = $acos = $this->_parseAcos($acosRes);

        $perms = array();
        $parents = array();
        foreach ($acos as $key => $data) {
            $aco = & $acos[$key];
            $aco = array('Aco' => $data['Aco'], 'Aro' => $data['Aro'], 'Action' => array());
            $id = $aco['Aco']['id'];

            // Generate path
            if ($aco['Aco']['parent_id'] && isset($parents[$aco['Aco']['parent_id']])) {
                $parents[$id] = $parents[$aco['Aco']['parent_id']] . '/' . $aco['Aco']['alias'];
            } else {
                $parents[$id] = $aco['Aco']['alias'];
            }

            $aco['Action'] = $parents[$id];

            // Fetching permissions per ARO
            $acoNode = $aco['Action'];

            foreach ($aros as $aro) {
                $aroId = $aro[$Aro->alias()]['id'];
                $evaluate = $this->_evaluate_permissions($permKeys, array('id' => $aroId, 'alias' => $Aro->alias()), $aco, $key);
                $perms[str_replace('/', ':', $acoNode)][$Aro->alias() . ":" . $aroId . '-inherit'] = $evaluate['inherited'];
                $perms[str_replace('/', ':', $acoNode)][$Aro->alias() . ":" . $aroId] = $evaluate['allowed'];
            }
        }
        
        $this->request->data = array('Perms' => $perms);
        $this->set('model', $model);
        $this->set('manage', Configure::read('AclManager.aros'));
        $this->set('hideDenied', Configure::read('AclManager.hideDenied'));
        $this->set('aroAlias', $Aro->alias());
        $this->set('aroDisplayField', $Aro->displayField());
        $this->set(compact('acos', 'aros'));
    }
916731
public function getPermissionsAction(Request $request)
    {
        $data = [];
        $group = $request->attributes->get('group');
        $aclManager = $this->getContainer()->get('security.acl_manager');

        foreach ($this->getApplication()->getBundles() as $bundle) {

            if ($bundle->isEnabled() && true === array_key_exists('admin_entry_point', $bundle->getProperty())) {

                $data[] = [
                    'uid' => $bundle->getId(),
                    'label' => $bundle->getProperty()['name'],
                    'class' => $bundle->getType(),
                    'rights' => $aclManager->getPermissions($bundle->getType(), $group)
                ];
            }
        }

        return $this->createJsonResponse($data, 200);
    }
631445
public function rules()
    {

        $name = $this->route()->getName();
        $tbl = ( str_contains($name, 'role') ) ? 'roles' : 'permissions';

       return [
            'name' => 'required|unique:'.$tbl.'|max:255|min:4',
            'slug' => 'required|unique:'.$tbl.'|max:255|min:4',
        ];

    }
524781
public function getPermissionsAction(Request $request)
    {
        $group = $request->attributes->get('group');
        $aclManager = $this->getContainer()->get('security.acl_manager');
        $parentClass = 'BackBee\ClassContent\AbstractClassContent';

        $categories['parent'] = [
            'class' => $parentClass,
            'rights' => $aclManager->getPermissions($parentClass, $group)
        ];

        $allClassContentClassNames = $this->getClassContentManager()->getAllClassContentClassnames();

        foreach ($this->getCategoryManager()->getCategories() as $id => $category) {

            foreach($category->getBlocks() as $key => $block){

                $className = AbstractClassContent::getClassnameByContentType($block->type);
                $block->rights = $aclManager->getPermissions($className, $group);
                $block->type = $className;

                $allClassContentClassNames = array_diff($allClassContentClassNames, [$className]);
            }

            if(false === empty($category->getBlocks())) {

                $categories['objects'][] = array_merge(['id' => $id], $category->jsonSerialize());
            }
        }

        $otherCategory = new Category('Other');

        foreach ($allClassContentClassNames as $class) {

            $content = new $class();

            if(false === $content->isElementContent()){

                if(null === $content->getProperty('name')){

                    $content->setProperty('name', $content->getContentType());
                }

                $otherCategory->addBlock($content);
            }
        }

        $categories['objects'][] = array_merge(['id' => 'other'], $otherCategory->jsonSerialize());

        return $this->createJsonResponse($categories, 200);
    }
616806
private function getRolesPermissions()
    {
        return [
            [
                'name'        => 'Roles - List all roles',
                'description' => 'Allow to list all roles.',
                'slug'        => RolesPolicy::PERMISSION_LIST,
            ],
            [
                'name'        => 'Roles - View a role',
                'description' => 'Allow to view the role\'s details.',
                'slug'        => RolesPolicy::PERMISSION_SHOW,
            ],
            [
                'name'        => 'Roles - Add/Create a role',
                'description' => 'Allow to create a new role.',
                'slug'        => RolesPolicy::PERMISSION_CREATE,
            ],
            [
                'name'        => 'Roles - Edit/Update a role',
                'description' => 'Allow to update a role.',
                'slug'        => RolesPolicy::PERMISSION_UPDATE,
            ],
            [
                'name'        => 'Roles - Delete a role',
                'description' => 'Allow to delete a role.',
                'slug'        => RolesPolicy::PERMISSION_DELETE,
            ],
        ];
    }
1362240
public function permissions_obj($model = null) {
    $model = $model ? $model : new Permission;
    $objs = [];
    $permissions = $this->resource->permissions;
    if (!empty($permissions)) {
      foreach ($permissions as $permission => $status) {
        $objs[] = (!$model::wherePermission($permission)->get()->isEmpty()) ? $model::wherePermission($permission)->first() : null;
      }
    }
    return $objs;
  }
982124
protected function getRouteInformation(Route $route)
    {
        list($controller, $action) = explode("@", $route->getActionName());

        return [
            'host' => $route->domain(),
            'method' => implode('|', $route->methods()),
            'uri' => $route->uri(),
            'name' => $route->getName(),
            'controller' => $controller,
            'action' => $action,
            'resource' => $route->getActionName(),
            'middleware' => Collection::make($this->getMiddleware($route))
        ];
    }
246509
public function map(Route $route)
    {
        $this->routes[$route->init()->getRule()] = $route;

        return $this;
    }
898947
private function getAllMappedPermissions(): array
    {
        $mappedPermissions = [];
        foreach (Craft::$app->userPermissions->getAllPermissions() as $permissions) {
            $mappedPermissions = array_merge($mappedPermissions, $this->getMappedPermissions($permissions));
        }

        return $mappedPermissions;
    }
1188241
private function mapRoute2Content($route)
    {
        // Look it up in the index
        list($keyIndex, $content) = $this->mapRoute2Index($route);
        $filtered = $this->loadFileContentPhaseOne($keyIndex);

        return [$keyIndex, $content, $filtered];
    }
394003
public function rules()
    {
        $permission = Permission::find($this->route()->parameters['permission']);
        $permissionId = $permission->id;

        $rules = Permission::$rules;
        $rules['name'] = 'required|unique:z_permissions,name,' . $permissionId;
        return $rules;
    }
1110610
private function applyGroupSettings(Route $route) : Route
    {
        $route->setRawPath($this->getGroupPath() . $route->getRawPath());
        $route->setRawHost($this->getGroupHost() . $route->getRawHost());

        if (!$route->usesCallable()) {
            $route->setControllerName($this->getGroupControllerNamespace() . $route->getControllerName());
        }

        $route->setSecure($this->groupIsSecure() || $route->isSecure());
        // The route's variable regexes take precedence over group regexes
        $route->setVarRegexes(array_merge($this->getVarRegexes(), $route->getVarRegexes()));
        $groupMiddleware = $this->getGroupMiddleware();

        if (count($groupMiddleware) > 0) {
            $route->addMiddleware($groupMiddleware, true);
        }

        return $route;
    }
460133
public static function permissions(): array
    {
        $aPermissions = parent::permissions();

        $aPermissions['object:browse']  = 'Can browse existing objects';
        $aPermissions['object:create']  = 'Can create new objects';
        $aPermissions['object:delete']  = 'Can delete existing objects';
        $aPermissions['object:restore'] = 'Can restore deleted objects';
        $aPermissions['object:purge']   = 'Can purge deleted objects';
        $aPermissions['bucket:create']  = 'Can create new buckets';

        return $aPermissions;
    }
1206281
public function get_item_permissions_check( $request ) {

		if ( $request['id'] === get_network()->site_id ) {
			return false;
		}

		$allowed = false;

		switch_to_blog( $request['id'] );

		if ( 1 === absint( get_option( 'blog_public' ) ) ) {
			$allowed = true;
		}

		restore_current_blog();

		return $allowed;
	}
412683
private function getCategoriesPermissions()
    {
        return [
            [
                'name'        => 'Categories - List all categories',
                'description' => 'Allow to list all categories.',
                'slug'        => CategoriesPolicy::PERMISSION_LIST,
            ],
            [
                'name'        => 'Categories - View a category',
                'description' => 'Allow to display a category.',
                'slug'        => CategoriesPolicy::PERMISSION_SHOW,
            ],
            [
                'name'        => 'Categories - Create a category',
                'description' => 'Allow to create a category.',
                'slug'        => CategoriesPolicy::PERMISSION_CREATE,
            ],
            [
                'name'        => 'Categories - Update a category',
                'description' => 'Allow to update a category.',
                'slug'        => CategoriesPolicy::PERMISSION_UPDATE,
            ],
            [
                'name'        => 'Categories - Delete a category',
                'description' => 'Allow to delete a category.',
                'slug'        => CategoriesPolicy::PERMISSION_DELETE,
            ],
        ];
    }
170249
public function generatedPermissionFields(Collection $permissionsRaw): array
    {
        foreach ($permissionsRaw as $group => $items) {
            $fields[] = Label::make($group)
                ->title($group);

            foreach (collect($items)->chunk(3) as $chunks) {
                $fields[] = Field::group(function () use ($chunks) {
                    foreach ($chunks as $permission) {
                        $permissions[] = CheckBox::make('permissions.'.base64_encode($permission['slug']))
                            ->placeholder($permission['description'])
                            ->value((int) $permission['active']);
                    }

                    return $permissions ?? [];
                });
            }

            $fields[] = Label::make('close');
        }

        return $fields ?? [];
    }