Skip to content

Commit

Permalink
Merge pull request #78 from visto9259/4.x
Browse files Browse the repository at this point in the history
Merged documentation from master
  • Loading branch information
visto9259 authored May 23, 2024
2 parents 960c07f + 4886825 commit 2f75b3e
Show file tree
Hide file tree
Showing 133 changed files with 10,216 additions and 1,285 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Deploy to GitHub Pages

defaults:
run:
shell: bash
working-directory: ./docs

on:
push:
branches:
- 'master'
paths:
- 'docs/**'
workflow_dispatch:


jobs:
deploy:
name: Build and Deploy to GitHub Pages
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./docs
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
cache-dependency-path: docs/yarn.lock
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Build output to publish to the `gh-pages` branch:
publish_dir: ./docs/build
# The following lines assign commit authorship to the official
# GH-Actions bot for deploys to `gh-pages` branch:
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
# The GH actions bot is used by default if you didn't specify the two fields.
# You can swap them out with your own user credentials.
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
32 changes: 32 additions & 0 deletions .github/workflows/test-deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build GitHub Pages on PRs No Deploy

defaults:
run:
shell: bash
working-directory: ./docs

on:
push:
paths:
- 'docs/**'
pull_request:
paths:
- 'docs/**'
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

jobs:
test-deploy:
name: Build GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
cache-dependency-path: docs/yarn.lock
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
run: yarn build
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# LmcRbacMvc

[![Build](https://github.com/visto9259/LmcRbacMvc/actions/workflows/build_test.yml/badge.svg)](https://github.com/visto9259/LmcRbacMvc/actions/workflows/build_test.yml)
[![Version](https://poser.pugx.org/lm-commons/lmc-rbac-mvc/version)](//packagist.org/packages/lm-commons/lmc-rbac-mvc)
[![Total Downloads](https://poser.pugx.org/lm-commons/lmc-rbac-mvc/downloads)](//packagist.org/packages/lm-commons/lmc-rbac-mvc)
[![License](https://poser.pugx.org/lm-commons/lmc-rbac-mvc/license)](//packagist.org/packages/lm-commons/lmc-rbac-mvc)
[![Build](https://github.com/lm-commons/LmcRbacMvc/actions/workflows/build_test.yml/badge.svg)](https://github.com/lm-commons/LmcRbacMvc/actions/workflows/build_test.yml)
<!-- ![Gitter](https://badges.gitter.im/LM-Commons/community.svg)](https://gitter.im/LM-Commons/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -->
[![Coverage Status](https://coveralls.io/repos/github/LM-Commons/LmcRbacMvc/badge.svg?branch=master)](https://coveralls.io/github/LM-Commons/LmcRbacMvc?branch=master)
<!-- [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/LM-Commons/LmcRbacMvc/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/LM-Commons/LmcRbacMvc/?branch=master) -->
![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Flm-commons%2Flmcrbacmvc%2Fproperties%2Fvalues&query=%24%5B%3A1%5D.value&label=Maintenance%20Status)
[![Static Badge](https://img.shields.io/badge/Chat_on-Slack-blue)](https://join.slack.com/t/lm-commons/shared_invite/zt-2gankt2wj-FTS45hp1W~JEj1tWvDsUHQ)

Role-based access control module to provide additional features on top of Laminas\Permissions\Rbac
Role-based access control module to provide additional features on top of Zend\Permissions\Rbac

## Requirements

Expand Down Expand Up @@ -46,11 +46,12 @@ the `lmc_rbac.global.php.dist` file to your `config/autoload` folder.

## Documentation

The official documentation is available in the [/docs](/docs) folder.
The official documentation is available [here](https://lm-commons.github.io/LmcRbacMvc).

You can also find some Doctrine entities in the [/data](/data) folder that will help you to more quickly take advantage
of LmcRbac.

## Support

- File issues at https://github.com/LM-Commons/LmcRbacMvc/issues.
- Ask questions in the [LM-Commons Slack](https://join.slack.com/t/lm-commons/shared_invite/zt-2gankt2wj-FTS45hp1W~JEj1tWvDsUHQ) chat.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"laminas/laminas-i18n": "^2.7",
"laminas/laminas-serializer": "^2.2",
"laminas/laminas-view": "^2.12",
"phpunit/phpunit": "9.5.21",
"phpunit/phpunit": "10.5.11",
"squizlabs/php_codesniffer": "^3.5.5",
"php-coveralls/php-coveralls": "^2.2",
"phpspec/prophecy-phpunit": "^2.0",
Expand All @@ -71,6 +71,11 @@
"LmcRbacMvcTest\\": "tests"
}
},
"extra": {
"laminas": {
"module": "LmcRbacMvc"
}
},
"scripts": {
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Functional",
Expand Down
7 changes: 6 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
'LmcRbacMvc\Guards' => \LmcRbacMvc\Factory\GuardsFactory::class,

/* Factories that map to a class */
\Rbac\Rbac::class => \LmcRbacMvc\Factory\RbacFactory::class,
\LmcRbacMvc\Assertion\AssertionPluginManager::class => \LmcRbacMvc\Factory\AssertionPluginManagerFactory::class,
// TODO Remove RbacCollector once it is moved to a separate library
\LmcRbacMvc\Collector\RbacCollector::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\LmcRbacMvc\Guard\GuardPluginManager::class => \LmcRbacMvc\Factory\GuardPluginManagerFactory::class,
\LmcRbacMvc\Identity\AuthenticationIdentityProvider::class => \LmcRbacMvc\Factory\AuthenticationIdentityProviderFactory::class,
Expand Down Expand Up @@ -64,6 +64,10 @@
]
],

/*
* Developer tools are now provided by the companion module LmcRbacMvcDevTools
* You can still use the config below but you are encouraged to use the new module
*
'laminas-developer-tools' => [
'profiler' => [
'collectors' => [
Expand All @@ -76,6 +80,7 @@
],
],
],
*/

'lmc_rbac' => [
// Guard plugin manager
Expand Down
85 changes: 45 additions & 40 deletions data/FlatRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@
* and is licensed under the MIT license.
*/


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Laminas\Permissions\Rbac\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
use Rbac\Role\RoleInterface;
use LmcRbac\Permission\PermissionInterface;

/**
* There is no specific implementation of a flot role.
* A flot role is a simple utilization of the Laminas\Permission\Rbac\Role without children
*/


/**
* @ORM\Entity
* @ORM\Table(name="roles")
* @ORM\Table(name="flat_roles")
*/
class FlatRole implements RoleInterface
{
Expand All @@ -32,83 +39,81 @@ class FlatRole implements RoleInterface
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\GeneratedValue
*/
protected $id;
private ?int $id;

/**
* @var string|null
*
* @ORM\Column(type="string", length=48, unique=true)
* @ORM\Column(type="string", length=32, unique=true)
*/
protected $name;
protected ?string $name;

/**
* @var PermissionInterface[]|\Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER", cascade={"persist"})
* @var Collection
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", cascade={"persist"}, fetch="EAGER")
*/
protected $permissions;
protected Collection $permissions;

/**
* Init the Doctrine collection
*/
public function __construct()
public function __construct($name)
{
$this->name = (string) $name;
$this->permissions = new ArrayCollection();
}

/**
* Get the role identifier
*
* @return int
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}

/**
* Set the role name
* Add a permission
*
* @param string $name
* @param string $name
* @return void
*/
public function setName($name)
public function addPermission(string $name):void
{
$this->name = (string) $name;
$permission = new \LmcRbacMvcTest\Asset\Permission($name);

$this->permissions[$name] = $permission;
}

/**
* Get the role name
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* {@inheritDoc}
*/
public function addPermission($permission)
public function hasPermission(string $name): bool
{
if (is_string($permission)) {
$permission = new Permission($permission);
}
return isset($this->permissions[$name]);
}

$this->permissions[(string) $permission] = $permission;
public function addChild(RoleInterface $child): void
{
// Do nothing
}

/**
* {@inheritDoc}
*/
public function hasPermission($permission)
public function getChildren(): iterable
{
// This can be a performance problem if your role has a lot of permissions. Please refer
// to the cookbook to an elegant way to solve this issue
return [];
}

return isset($this->permissions[(string) $permission]);
public function addParent(RoleInterface $parent): void
{
// Do nothing
}

public function getParents(): iterable
{
return [];
}
}
33 changes: 20 additions & 13 deletions data/Permission.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@
* and is licensed under the MIT license.
*/


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use LmcRbac\Permission\PermissionInterface;

/**
* @ORM\Entity
* @ORM\Table(name="permissions")
*/
class Permission implements PermissionInterface
class Permission
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
private ?int $id;

/**
* @var string|null
*
* @ORM\Column(type="string", length=128, unique=true)
* @ORM\Column(type="string", length=32, unique=true)
*/
protected $name;
private ?string $name;

/**
* Constructor
Expand All @@ -52,18 +49,28 @@ class Permission implements PermissionInterface
/**
* Get the permission identifier
*
* @return int
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}

/**
* {@inheritDoc}
* Get the permission name
*
* @return string|null
*/
public function __toString()
public function getName(): ?string
{
return $this->name;
}

/**
*
*/
public function __toString(): string
{
return $this->getName();
}
}
2 changes: 1 addition & 1 deletion data/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
These files are only provided as-in, and are not part of LmcRbac. They provide you some basic Doctrine ORM
These files are only provided as-in, and are not part of LmcRbacMvc. They provide you some basic Doctrine ORM
entities that you can use as a starting point.

## Flat role or hierarchical role?
Expand Down
Loading

0 comments on commit 2f75b3e

Please sign in to comment.