Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 25, 2020
2 parents db99591 + 45559b3 commit 4a4437e
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 167 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.4.0"></a>
# [1.4.0](https://github.com/flextype-plugins/acl) (2020-08-25)

### Features

* **core** update code base for new Flextype 0.9.11

<a name="1.3.0"></a>
# [1.3.0](https://github.com/flextype-plugins/acl) (2020-08-19)

Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">ACL Plugin for <a href="http://flextype.org/">Flextype</a></h1>

<p align="center">
<a href="https://github.com/flextype-plugins/acl/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/acl.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/github/downloads/flextype-plugins/acl/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.10-green.svg" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
<a href="https://github.com/flextype-plugins/acl/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/acl.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/acl"><img src="https://img.shields.io/github/downloads/flextype-plugins/acl/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.11-green.svg" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
</p>

## Features
Expand All @@ -15,7 +15,7 @@ The following dependencies need to be downloaded and installed for ACL Plugin.

| Item | Version | Download |
|---|---|---|
| [flextype](https://github.com/flextype/flextype) | 0.9.10 | [download](https://github.com/flextype/flextype/releases) |
| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [download](https://github.com/flextype/flextype/releases) |
| [site](https://github.com/flextype-plugins/site) | >=1.0.0 | [download](https://github.com/flextype-plugins/site/releases) |
| [twig](https://github.com/flextype-plugins/twig) | >=1.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |

Expand Down Expand Up @@ -56,9 +56,9 @@ The following dependencies need to be downloaded and installed for ACL Plugin.

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserLoggedInMiddleware(['container' => $flextype,
->add(new AclIsUserLoggedInMiddleware([
'redirect' => 'another.route.name']));
```

Expand All @@ -74,9 +74,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclAccountsIsUserLoggedInRolesInMiddleware(['container' => $flextype,
->add(new AclAccountsIsUserLoggedInRolesInMiddleware([
'roles' => 'admin, moderator'
'redirect' => 'another.route.name']));
```
Expand All @@ -93,9 +93,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserLoggedInEmailsInMiddleware(['container' => $flextype,
->add(new AclIsUserLoggedInEmailsInMiddleware([
'emails' => 'jack@flextype.org, jack@flextype.org'
'redirect' => 'another.route.name']));
```
Expand All @@ -112,9 +112,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserLoggedInUuidInMiddleware(['container' => $flextype,
->add(new AclIsUserLoggedInUuidInMiddleware([
'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2'
'redirect' => 'another.route.name']));
```
Expand All @@ -129,9 +129,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserNotLoggedInMiddleware(['container' => $flextype,
->add(new AclIsUserNotLoggedInMiddleware([
'redirect' => 'another.route.name']));
```

Expand All @@ -147,9 +147,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware(['container' => $flextype,
->add(new AclAccountsIsUserLoggedInRolesNotInMiddleware([
'roles' => 'admin, moderator'
'redirect' => 'another.route.name']));
```
Expand All @@ -166,9 +166,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserLoggedInEmailsNotInMiddleware(['container' => $flextype,
->add(new AclIsUserLoggedInEmailsNotInMiddleware([
'emails' => 'jack@flextype.org, sam@flextype.org'
'redirect' => 'another.route.name']));
```
Expand All @@ -185,9 +185,9 @@ $flextype->get('/my-route', 'MyController:method()')

#### Example
```
$flextype->get('/my-route', 'MyController:method()')
flextype()->get('/my-route', 'MyController:method()')
->setName('my.route.name')
->add(new AclIsUserLoggedInUuidNotInMiddleware(['container' => $flextype,
->add(new AclIsUserLoggedInUuidNotInMiddleware([
'uuids' => 'ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2'
'redirect' => 'another.route.name']));
```
Expand Down Expand Up @@ -513,54 +513,54 @@ You may restrict access for specific users to your specific code in the PHP.
#### Run private code for logged in users

```php
if ($flextype->container('acl')->isUserLoggedIn()) {
if (flextype('acl')->isUserLoggedIn()) {
// Private code here..
}
```

#### Run private content for users with roles: admin and student

```php
if ($flextype->container('acl')->isUserLoggedInRolesIn('admin, student')) {
if (flextype('acl')->isUserLoggedInRolesIn('admin, student')) {
// Private code here..
}
```

#### Run private code for users with uuids ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2 and d549af27-79a0-44f2-b9b1-e82b47bf87e2

```php
if ($flextype->container('acl')->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') {
if (flextype('acl')->isUserLoggedInUuidIn('ea7432a3-b2d5-4b04-b31d-1c5acc7a55e2, d549af27-79a0-44f2-b9b1-e82b47bf87e2') {
// Private content here..
}
```

#### Run private code for users with emails jack@flextype.org, sam@flextype.org

```php
if ($flextype->container('acl')->isUserLoggedInEmailIn('jack@flextype.org, sam@flextype.org')) {
if (flextype('acl')->isUserLoggedInEmailIn('jack@flextype.org, sam@flextype.org')) {
// Private content here..
}
```

#### Show logged in email

```php
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
```

#### Show logged in uuid

```php
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid();
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
echo 'your uuid: ' . flextype('acl')->getUserLoggedInUuid();
```

#### Show logged in roles

```php
echo 'Hello ' . $flextype->container('acl')->getUserLoggedInEmail();
echo 'your uuid: ' . $flextype->container('acl')->getUserLoggedInUuid();
echo 'and your roles: ' . $flextype->container('acl')->getUserLoggedInRoles();
echo 'Hello ' . flextype('acl')->getUserLoggedInEmail();
echo 'your uuid: ' . flextype('acl')->getUserLoggedInUuid();
echo 'and your roles: ' . flextype('acl')->getUserLoggedInRoles();
```

## LICENSE
Expand Down
13 changes: 4 additions & 9 deletions app/Models/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@

class Acl
{
/**
* Flextype Application
*/
protected $flextype;

/**
* __construct
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}
public function __construct()
{

}

/**
* Check is user logged in
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"issues": "https://github.com/flextype-plugins/acl/issues"
},
"require": {
"php": ">=7.2.5",
"php": ">=7.3.0",
"ext-json": "*"
},
"config": {
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform": {
"php": "7.2.5"
"php": "7.3.0"
}
},
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
/**
* Add ACL Model to Flextype container
*/
$flextype->container()['acl'] = static function () use ($flextype) {
return new Acl($flextype);
flextype()->container()['acl'] = static function () {
return new Acl();
};

/**
* Add ACL Twig Extension to Flextype container
*/
$flextype->container('twig')->addExtension(new AclTwigExtension($flextype));
flextype('twig')->addExtension(new AclTwigExtension());
16 changes: 8 additions & 8 deletions entries_acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

use Flextype\Component\Session\Session;

$flextype->container('emitter')->addListener('onEntryAfterInitialized', function() use ($flextype) {
flextype('emitter')->addListener('onEntryAfterInitialized', function() {

// Get current entry
$entry = $flextype->container('entries')->entry;
$entry = flextype('entries')->entry;

// Set ACL rules based on accounts uuids
if (isset($entry['acl']['accounts']['uuids'])) {
if (!$flextype->container('acl')->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) {
$flextype->container('entries')->entry = [];
if (!flextype('acl')->isUserLoggedInUuidsIn($entry['acl']['accounts']['uuids'])) {
flextype('entries')->entry = [];
}
}

// Set ACL rules based on accounts emails
if (isset($entry['acl']['accounts']['emails'])) {
if (!$flextype->container('acl')->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) {
$flextype->container('entries')->entry = [];
if (!flextype('acl')->isUserLoggedInEmailsIn($entry['acl']['accounts']['emails'])) {
flextype('entries')->entry = [];
}
}

// Set ACL rules based on accounts roles
if (isset($entry['acl']['accounts']['roles'])) {
if (!$flextype->container('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) {
$flextype->container('entries')->entry = [];
if (!flextype('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) {
flextype('entries')->entry = [];
}
}
});
13 changes: 4 additions & 9 deletions middlewares/AclIsUserLoggedInEmailInMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

class AclIsUserLoggedInEmailInMiddleware
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Middleware Settings
*/
Expand All @@ -27,9 +22,9 @@ class AclIsUserLoggedInEmailInMiddleware
/**
* __construct
*/
public function __construct($flextype, $settings)
public function __construct($settings)
{
$this->flextype = $flextype;

$this->settings = $settings;
}

Expand All @@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
*/
public function __invoke(Request $request, Response $response, callable $next) : Response
{
if ($this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
if (flextype('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
$response = $next($request, $response);
} else {
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
}

return $response;
Expand Down
13 changes: 4 additions & 9 deletions middlewares/AclIsUserLoggedInEmailNotInMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

class AclIsUserLoggedInEmailNotInMiddleware
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Middleware Settings
*/
Expand All @@ -27,9 +22,9 @@ class AclIsUserLoggedInEmailNotInMiddleware
/**
* __construct
*/
public function __construct($flextype, $settings)
public function __construct($settings)
{
$this->flextype = $flextype;

$this->settings = $settings;
}

Expand All @@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
*/
public function __invoke(Request $request, Response $response, callable $next) : Response
{
if (!$this->flextype->container('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
if (!flextype('acl')->isUserLoggedInEmailIn($this->settings['emails'])) {
$response = $next($request, $response);
} else {
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
}

return $response;
Expand Down
13 changes: 4 additions & 9 deletions middlewares/AclIsUserLoggedInMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

class AclIsUserLoggedInMiddleware
{
/**
* Flextype Application
*/
protected $flextype;

/**
* Middleware Settings
*/
Expand All @@ -27,9 +22,9 @@ class AclIsUserLoggedInMiddleware
/**
* __construct
*/
public function __construct($flextype, $settings)
public function __construct($settings)
{
$this->flextype = $flextype;

$this->settings = $settings;
}

Expand All @@ -42,10 +37,10 @@ public function __construct($flextype, $settings)
*/
public function __invoke(Request $request, Response $response, callable $next) : Response
{
if ($this->flextype->container('acl')->isUserLoggedIn()) {
if (flextype('acl')->isUserLoggedIn()) {
$response = $next($request, $response);
} else {
$response = $response->withRedirect($this->flextype->container('router')->pathFor($this->settings['redirect']));
$response = $response->withRedirect(flextype('router')->pathFor($this->settings['redirect']));
}

return $response;
Expand Down
Loading

0 comments on commit 4a4437e

Please sign in to comment.