From aeb373365faf6a4d32817a043f76b7a5b27e22ab Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 12 Dec 2011 11:37:00 -0500 Subject: [PATCH] Added permissions_category table which replaces 'role' or 'permission' type for permissions. Categories can now be completely customized, also added ability to expand/collapse categories displayed, using jQuery --- SQL/2011-12-12-PermissionCategory.sql | 17 +++++++++++ .../NDB_Form_user_accounts.class.inc | 6 ++-- php/libraries/UserPermissions.class.inc | 4 +-- smarty/templates/form_edit_user.tpl | 30 ++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 SQL/2011-12-12-PermissionCategory.sql diff --git a/SQL/2011-12-12-PermissionCategory.sql b/SQL/2011-12-12-PermissionCategory.sql new file mode 100644 index 00000000000..4f7cd7f7d93 --- /dev/null +++ b/SQL/2011-12-12-PermissionCategory.sql @@ -0,0 +1,17 @@ +CREATE TABLE permissions_category ( + ID int(10) not null AUTO_INCREMENT, + Description varchar(255) not null, + PRIMARY KEY(`ID`) +); + +REPLACE INTO permissions_category VALUES (1, 'Roles'); +REPLACE INTO permissions_category VALUES (2, 'Permission'); + + +ALTER TABLE permissions ADD COLUMN categoryID int(10) REFERENCES permissions_category(ID); + +UPDATE permissions SET categoryID=1 WHERE type='role'; +UPDATE permissions SET categoryID=2 WHERE type='permission'; + +-- You should run this once you're sure everything works. +-- ALTER TABLE permissions DROP COLUMN type; diff --git a/php/libraries/NDB_Form_user_accounts.class.inc b/php/libraries/NDB_Form_user_accounts.class.inc index 10cc1e39f9f..1bd15f7525a 100644 --- a/php/libraries/NDB_Form_user_accounts.class.inc +++ b/php/libraries/NDB_Form_user_accounts.class.inc @@ -347,9 +347,11 @@ class NDB_Form_user_accounts extends NDB_Form foreach ($perms as $row) { if($row['type'] != $lastRole) { $lastRole = $row['type']; - $group[] = $this->form->createElement('static', null, null, ''.ucwords($row['type']).''); + $group[] = $this->form->createElement('static', null, null, '' . + "

".ucwords($row['type']).'

' + . "
"); } - $group[] = $this->form->createElement('advcheckbox', 'permID['.$row['permID'].']', null, $row['description']); + $group[] = $this->form->createElement('advcheckbox', 'permID['.$row['permID'].']', null, $row['description'], "class=\"perm_$lastRole\""); } $this->form->addGroup($group, 'PermID_Group', 'Permissions', "
\n", FALSE); unset($group); diff --git a/php/libraries/UserPermissions.class.inc b/php/libraries/UserPermissions.class.inc index bf1858764af..a178cba808a 100644 --- a/php/libraries/UserPermissions.class.inc +++ b/php/libraries/UserPermissions.class.inc @@ -239,7 +239,7 @@ class UserPermissions return PEAR::raiseError("Could not connect to database: ".$DB->getMessage()); } - $query = "SELECT permissions.permID, code, description, type FROM permissions, user_perm_rel WHERE permissions.permID = user_perm_rel.permID AND userID = '$this->userID' ORDER BY type, description"; + $query = "SELECT p.permID, p.code, p.description, pc.Description as type FROM permissions p JOIN user_perm_rel up ON (p.permID=up.PermID) LEFT JOIN permissions_category pc ON (pc.ID=p.categoryID) WHERE up.userID = '$this->userID' ORDER BY p.categoryID, p.description"; $DB->select($query, $results); if (PEAR::isError($results)) { return PEAR::raiseError("DB Error: ".$results->getMessage()); @@ -248,4 +248,4 @@ class UserPermissions return $results; } } -?> \ No newline at end of file +?> diff --git a/smarty/templates/form_edit_user.tpl b/smarty/templates/form_edit_user.tpl index 17882773fd0..ce7fda1df56 100644 --- a/smarty/templates/form_edit_user.tpl +++ b/smarty/templates/form_edit_user.tpl @@ -1,4 +1,32 @@
+{literal} + +{/literal}
@@ -121,7 +149,7 @@ - +
Permissions{$form.PermID_Group.html}
{$form.PermID_Group.html}