Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds beginnings of permissions interface.

Each module now has a foo_permissions() function which returns a list of permissions that module provides.
The core user code also has a user_role_list() function to return a list of all defined roles.
  • Loading branch information...
commit f868c6bd2476dd54c437bc10a2c70471c18afe9d 1 parent 46e7770
@elplatt authored
View
12 crm/include/core/core.inc.php
@@ -28,6 +28,18 @@ function core_revision () {
return 1;
}
+/**
+ * @return An array of the permissions provided by this module.
+ */
+function core_permissions () {
+ $permissions = array_merge(
+ user_permissions()
+ , module_permissions()
+ , array('report_view')
+ );
+ return $permissions;
+}
+
// Subsystems //////////////////////////////////////////////////////////////////
require_once('sys/init.inc.php'); // Pre-module initialization
View
1  crm/include/core/init.inc.php
@@ -25,5 +25,6 @@
*/
function core_init () {
module_init();
+ user_init();
page_init();
}
View
9 crm/include/core/sys/module.inc.php
@@ -20,6 +20,15 @@
*/
/**
+ * @return An array of the permissions provided by this module.
+ */
+function module_permissions () {
+ return array(
+ 'module_upgrade'
+ );
+}
+
+/**
* @return list of installed modules.
*/
function module_list () {
View
59 crm/include/core/sys/user.inc.php
@@ -21,6 +21,34 @@
*/
/**
+ * Array of all permissions.
+ */
+$user_permissions = array();
+
+/**
+ * Initialization code run after all modules are loaded.
+ */
+function user_init () {
+ global $user_permissions;
+
+ foreach (module_list() as $module) {
+ $func = $module . '_permissions';
+ if (function_exists($func)) {
+ $permissions = call_user_func($func);
+ $user_permissions = array_merge($user_permissions, $permissions);
+ }
+ }
+}
+
+/**
+ * @return a list of all permissions.
+ */
+function user_permission_list () {
+ global $user_permissions;
+ return $user_permissions;
+}
+
+/**
* @return the cid of the logged in user.
*/
function user_id () {
@@ -59,6 +87,37 @@ function user_get_user($cid = 0) {
}
/**
+ * @return An array of the permissions provided by this module.
+ */
+function user_permissions () {
+ return array(
+ 'user_add'
+ , 'user_edit'
+ , 'user_delete'
+ );
+}
+
+/**
+ * @return An array of role names.
+ */
+function user_role_list () {
+ $sql = "SHOW COLUMNS FROM `role`";
+ $res = mysql_query($sql);
+ if (!$res) { die(mysql_error()); }
+
+ $roles = array();
+ $row = mysql_fetch_assoc($res);
+ while ($row) {
+ if ($row['Field'] !== 'cid') {
+ $roles[] = $row['Field'];
+ }
+ $row = mysql_fetch_assoc($res);
+ }
+
+ return $roles;
+}
+
+/**
* Get role data for one or more users.
*
* @param $opts Options, possible keys are:
View
11 crm/include/key/key.inc.php
@@ -31,6 +31,17 @@ function key_revision () {
}
/**
+ * @return An array of the permissions provided by this module.
+ */
+function key_permissions () {
+ return array(
+ 'key_view'
+ , 'key_edit'
+ , 'key_delete'
+ );
+}
+
+/**
* Install or upgrade this module.
* @param $old_revision The last installed revision of this module, or 0 if the
* module has never been installed.
View
20 crm/include/member/member.inc.php
@@ -35,6 +35,26 @@ function member_stylesheets () {
return array('style.css');
}
+/**
+ * @return An array of the permissions provided by this module.
+ */
+function member_permissions () {
+ return array(
+ 'contact_view'
+ , 'contact_add'
+ , 'contact_edit'
+ , 'contact_delete'
+ , 'member_plan_edit'
+ , 'member_view'
+ , 'member_add'
+ , 'member_edit'
+ , 'member_delete'
+ , 'member_membership_view'
+ , 'member_membership_edit'
+ , 'roles_edit'
+ );
+}
+
// Installation functions //////////////////////////////////////////////////////
require_once('install.inc.php');
Please sign in to comment.
Something went wrong with that request. Please try again.