Skip to content

Commit

Permalink
ACL 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Dec 6, 2020
1 parent 4a4437e commit ba051b6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Global
.composer
composer.lock
package-lock.json
vendor/
node_modules/
dist/

# Flextype Site Specific
var/

# OS Generated
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# phpstorm
.idea/*
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.5.0"></a>
# [1.5.0](https://github.com/flextype-plugins/acl) (2020-12-06)

### Features

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

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

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Sergey Romanenko
Copyright (c) 2021 Sergey Romanenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions app/Models/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Flextype\Plugin\Acl\Models;

use Flextype\Component\Session\Session;

use function array_intersect;
use function array_map;
use function explode;
Expand All @@ -36,7 +36,7 @@ public function __construct()
*/
public function isUserLoggedIn() : bool
{
if (Session::exists('user_logged_in')) {
if (flextype('session')->has('user_logged_in')) {
return true;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public function isUserLoggedInUuidIn(string $uuids) : bool
*/
public function getUserLoggedInEmail() : string
{
return Session::exists('user_email') ? Session::get('user_email') : '';
return flextype('session')->has('user_email') ? flextype('session')->get('user_email') : '';
}

/**
Expand All @@ -121,7 +121,7 @@ public function getUserLoggedInEmail() : string
*/
public function getUserLoggedInRoles() : string
{
return Session::exists('user_roles') ? Session::get('user_roles') : '';
return flextype('session')->has('user_roles') ? flextype('session')->get('user_roles') : '';
}

/**
Expand All @@ -133,7 +133,7 @@ public function getUserLoggedInRoles() : string
*/
public function getUserLoggedInUuid() : string
{
return Session::exists('user_uuid') ? Session::get('user_uuid') : '';
return flextype('session')->has('user_uuid') ? flextype('session')->get('user_uuid') : '';
}

/**
Expand All @@ -145,7 +145,7 @@ public function getUserLoggedInUuid() : string
*/
public function setUserLoggedIn(bool $logged_in)
{
Session::set('user_logged_in', $logged_in);
flextype('session')->set('user_logged_in', $logged_in);
}

/**
Expand All @@ -157,7 +157,7 @@ public function setUserLoggedIn(bool $logged_in)
*/
public function setUserLoggedInUuid(string $uuid)
{
Session::set('user_uuid', $uuid);
flextype('session')->set('user_uuid', $uuid);
}

/**
Expand All @@ -169,7 +169,7 @@ public function setUserLoggedInUuid(string $uuid)
*/
public function setUserLoggedInEmail(string $email)
{
Session::set('user_email', $email);
flextype('session')->set('user_email', $email);
}

/**
Expand All @@ -181,6 +181,6 @@ public function setUserLoggedInEmail(string $email)
*/
public function setUserLoggedInRoles(string $roles)
{
Session::set('user_roles', $roles);
flextype('session')->set('user_roles', $roles);
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},
"require": {
"php": ">=7.3.0",
"ext-json": "*"
"ext-json": "*",
"flextype-components/arrays" : "3.0.1",
"flextype-components/filesystem": "2.0.8"
},
"config": {
"apcu-autoloader": true,
Expand Down
10 changes: 5 additions & 5 deletions entries_acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

namespace Flextype\Plugin\Acl;

use Flextype\Component\Session\Session;


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

// Get current entry
$entry = flextype('entries')->entry;
$entry = flextype('entries')->getStorage('fetch.data');

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

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

// Set ACL rules based on accounts roles
if (isset($entry['acl']['accounts']['roles'])) {
if (!flextype('acl')->isUserLoggedInRolesIn($entry['acl']['accounts']['roles'])) {
flextype('entries')->entry = [];
flextype('entries')->setStorage('fetch.data', []);
}
}
});
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ACL
version: 1.4.0
version: 1.5.0
description: ACL plugin for Flextype.
icon: fas fa-users-cog
author:
Expand All @@ -11,5 +11,5 @@ bugs: https://github.com/flextype-plugins/acl/issues
license: MIT

dependencies:
flextype: 0.9.11
flextype: 0.9.12
twig: '>=1.0.0'

0 comments on commit ba051b6

Please sign in to comment.