Permalink
Browse files

Use JSON format for groups and permissions inside database

  • Loading branch information...
redaxmedia committed Aug 1, 2018
1 parent ab57779 commit 5216ab8c825e106a0d2c711fa582b43839b4dd49
@@ -139,13 +139,13 @@ protected function _sanitizePost() : array
'name' => $this->_request->getPost('name'),
'alias' => $aliasFilter->sanitize($this->_request->getPost('alias')),
'description' => $this->_request->getPost('description'),
'categories' => implode(', ', (array)$this->_request->getPost('categories')),
'articles' => implode(', ', (array)$this->_request->getPost('articles')),
'extras' => implode(', ', (array)$this->_request->getPost('extras')),
'comments' => implode(', ', (array)$this->_request->getPost('comments')),
'groups' => implode(', ', (array)$this->_request->getPost('groups')),
'users' => implode(', ', (array)$this->_request->getPost('users')),
'modules' => implode(', ', (array)$this->_request->getPost('modules')),
'categories' => json_encode($this->_request->getPost('categories')),
'articles' => json_encode($this->_request->getPost('articles')),
'extras' => json_encode($this->_request->getPost('extras')),
'comments' => json_encode($this->_request->getPost('comments')),
'groups' => json_encode($this->_request->getPost('groups')),
'users' => json_encode($this->_request->getPost('users')),
'modules' => json_encode($this->_request->getPost('modules')),
'settings' => $this->_request->getPost('settings'),
'filter' => $specialFilter->sanitize($this->_request->getPost('filter')),
'status' => $specialFilter->sanitize($this->_request->getPost('status'))
@@ -139,7 +139,7 @@ protected function _sanitizePost() : array
'email' => $emailFilter->sanitize($this->_request->getPost('email')),
'language' => $specialFilter->sanitize($this->_request->getPost('language')),
'status' => $specialFilter->sanitize($this->_request->getPost('status')),
'groups' => implode(', ', (array)$this->_request->getPost('groups'))
'groups' => json_encode($this->_request->getPost('groups'))
];
}
@@ -162,7 +162,7 @@ public function render(int $groupId = null) : string
'for' => 'categories'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->categories),
(array)json_decode($group->categories),
[
'id' => 'categories',
'name' => 'categories[]',
@@ -175,7 +175,7 @@ public function render(int $groupId = null) : string
'for' => 'articles'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->articles),
(array)json_decode($group->articles),
[
'id' => 'articles',
'name' => 'articles[]',
@@ -188,7 +188,7 @@ public function render(int $groupId = null) : string
'for' => 'extras'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->extras),
(array)json_decode($group->extras),
[
'id' => 'extras',
'name' => 'extras[]',
@@ -201,7 +201,7 @@ public function render(int $groupId = null) : string
'for' => 'comments'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->comments),
(array)json_decode($group->comments),
[
'id' => 'comments',
'name' => 'comments[]',
@@ -214,7 +214,7 @@ public function render(int $groupId = null) : string
'for' => 'groups'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->groups),
(array)json_decode($group->groups),
[
'id' => 'groups',
'name' => 'groups[]',
@@ -227,7 +227,7 @@ public function render(int $groupId = null) : string
'for' => 'users'
])
->select($helperOption->getPermissionArray(),
explode(',', $group->users),
(array)json_decode($group->users),
[
'id' => 'users',
'name' => 'users[]',
@@ -240,7 +240,7 @@ public function render(int $groupId = null) : string
'for' => 'modules'
])
->select($helperOption->getPermissionArray('modules'),
explode(',', $group->modules),
(array)json_decode($group->modules),
[
'id' => 'modules',
'name' => 'modules[]',
@@ -241,7 +241,7 @@ public function render(int $userId = null) : string
'for' => 'groups'
])
->select($helperOption->getAccessArray('groups'),
explode(',', $user->groups),
(array)json_decode($user->groups),
[
'id' => 'groups',
'name' => 'groups[]',
@@ -207,7 +207,7 @@ protected function _renderGroup(string $groups = null) : string
{
$output = null;
$groupModel = new Admin\Model\Group();
$groupArray = array_map('intval', explode(',', $groups));
$groupArray = (array)json_decode($groups);
/* html element */
View
@@ -203,7 +203,7 @@ public function login(int $userId = null) : int
if ($user->user && $user->password)
{
$groupArray = array_map('intval', explode(',', $user->groups));
$groupArray = (array)json_decode($user->groups);
$group = Db::forTablePrefix('groups')
->whereIdIn($groupArray)
->where('status', 1)
@@ -223,7 +223,7 @@ public function login(int $userId = null) : int
{
foreach ($value as $keySub => $valueSub)
{
$valueArray = array_map('intval', explode(',', $valueSub));
$valueArray = (array)json_decode($valueSub);
$this->setPermission($keySub, $valueArray);
}
}
@@ -114,11 +114,10 @@ protected function _clear(array $optionArray = [])
{
$directory = $this->prompt('directory', $optionArray);
$extension = $this->prompt('extension', $optionArray);
$bundle = array_filter(explode(',', $optionArray['bundle']));
if (is_dir($directory))
{
$cacheFilesystem = new Filesystem\Cache();
return is_object($cacheFilesystem->init($directory, $extension)->clear($bundle));
return is_object($cacheFilesystem->init($directory, $extension)->clear($optionArray['bundle']));
}
return false;
}
View
@@ -300,13 +300,13 @@ public function insertGroups()
'name' => 'Administrators',
'alias' => 'administrators',
'description' => 'Unlimited access',
'categories' => '1, 2, 3',
'articles' => '1, 2, 3',
'extras' => '1, 2, 3',
'comments' => '1, 2, 3',
'groups' => '1, 2, 3',
'users' => '1, 2, 3',
'modules' => '1, 2, 3',
'categories' => '[1,2,3]',
'articles' => '[1,2,3]',
'extras' => '[1,2,3]',
'comments' => '[1,2,3]',
'groups' => '[1,2,3]',
'users' => '[1,2,3]',
'modules' => '[1,2,3]',
'settings' => 1,
'filter' => 0
])
@@ -343,7 +343,7 @@ public function insertUsers(array $optionArray = [])
'password' => $passwordHash->getHash(),
'email' => $optionArray['adminEmail'],
'description' => 'God admin',
'groups' => '1'
'groups' => '[1]'
])
->save();
}
View
@@ -46,7 +46,7 @@ public function getObject()
public function getArray() : array
{
return json_decode(json_encode($this->_dataObject ? $this->_dataObject : []), true);
return json_decode(json_encode((array)$this->_dataObject), true);
}
/**
@@ -20,15 +20,15 @@ class Access implements ValidatorInterface
* @since 4.0.0
*
* @param string $access content related access
* @param string|bool $groups groups of the user
* @param string $groups groups of the user
*
* @return bool
*/
public function validate($access = null, $groups = null) : bool
public function validate(string $access = null, string $groups = null) : bool
{
$accessArray = explode(',', $access);
$groupArray = explode(',', $groups);
$accessArray = (array)json_decode($access);
$groupArray = (array)json_decode($groups);
return !$access || in_array(1, $groupArray) || array_intersect($accessArray, $groupArray);
}
}
@@ -46,7 +46,7 @@ public function setUp()
[
'name' => 'User One',
'user' => 'user-one',
'groups' => '1',
'groups' => '[1]',
'last' => 1483261800
])
->save();
View
@@ -51,13 +51,13 @@ public function setUp()
'name' => 'Group One',
'alias' => 'group-one',
'description' => 'Unlimited access',
'categories' => '1, 2, 3',
'articles' => '1, 2, 3',
'extras' => '1, 2, 3',
'comments' => '1, 2, 3',
'groups' => '1, 2, 3',
'users' => '1, 2, 3',
'modules' => '1, 2, 3',
'categories' => '[1,2,3]',
'articles' => '[1,2,3]',
'extras' => '[1,2,3]',
'comments' => '[1,2,3]',
'groups' => '[1,2,3]',
'users' => '[1,2,3]',
'modules' => '[1,2,3]',
'settings' => 1,
'filter' => 0
])
@@ -204,4 +204,4 @@ public function testGetFilter(string $groups = null, bool $expect = null)
$this->assertEquals($expect, $actual);
}
}
}
@@ -234,7 +234,7 @@
"modulesUninstall": false,
"settingsEdit": false,
"myId": false,
"myGroups": 1
"myGroups": "[1]"
},
{},
"<ul class=\"rs-admin-fn-dropdown rs-admin-list-panel\"><li class=\"rs-admin-item-panel\"><input id=\"Redaxscript\\Admin\\View\\Helper\\Panel\\Notification\" class=\"rs-admin-fn-status-panel\" type=\"radio\" name=\"Redaxscript\\Admin\\View\\Helper\\Panel\\Panel\" checked=\"checked\" /><label class=\"rs-admin-fn-toggle-panel rs-admin-label-panel rs-admin-label-panel-notification\" for=\"Redaxscript\\Admin\\View\\Helper\\Panel\\Notification\">Notification<sup class=\"rs-admin-sup-panel-notification rs-admin-is-success rs-admin-is-warning rs-admin-is-error rs-admin-is-info\">4</sup></label><ul class=\"rs-admin-fn-content-panel rs-admin-list-panel-children rs-admin-list-notification\"><li class=\"rs-admin-item-notification rs-admin-item-note rs-admin-is-success\"><h3 class=\"rs-admin-title-notification\">Test Dummy</h3><a class=\"rs-admin-link-notification\" href=\"http://localhost\" target=\"_blank\">Success</a></li><li class=\"rs-admin-item-notification rs-admin-item-note rs-admin-is-warning\"><h3 class=\"rs-admin-title-notification\">Test Dummy</h3><span class=\"rs-admin-text-notification\">Warning</span></li><li class=\"rs-admin-item-notification rs-admin-item-note rs-admin-is-error\"><h3 class=\"rs-admin-title-notification\">Test Dummy</h3><span class=\"rs-admin-text-notification\">Error</span></li><li class=\"rs-admin-item-notification rs-admin-item-note rs-admin-is-info\"><h3 class=\"rs-admin-title-notification\">Test Dummy</h3><span class=\"rs-admin-text-notification\">Info</span></li></ul></li><li class=\"rs-admin-item-panel rs-admin-item-panel-logout\"><a href=\"logout\" class=\"rs-admin-link-panel rs-admin-link-panel-logout\">Logout</a></li></ul>"
@@ -4,15 +4,15 @@
true
],
[
"2",
"[2]",
true
],
[
"1",
"[1]",
false
],
[
"1, 2",
"[1, 2]",
false
]
]
]
Oops, something went wrong.

0 comments on commit 5216ab8

Please sign in to comment.