From 90efc4173df478220f61445c8d787466ad511c3d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Feb 2015 21:37:20 -0800 Subject: [PATCH] CRM_Core_Resources - Add API to export permission info --- CRM/Core/Resources.php | 23 +++++++++++++++++++++++ js/Common.js | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index fae2d0b2c3..b46698fac7 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -148,6 +148,29 @@ class CRM_Core_Resources { ); } + /** + * Export permission data to the client to enable smarter GUIs. + * + * Note: Application security stems from the server's enforcement + * of the security logic (e.g. in the API permissions). There's no way + * the client can use this info to make the app more secure; however, + * it can produce a better-tuned (non-broken) UI. + * + * @param array $permNames + * List of permission names to check/export. + * @return CRM_Core_Resources + */ + public function addPermissions($permNames) { + $permNames = (array) $permNames; + $perms = array(); + foreach ($permNames as $permName) { + $perms[$permName] = CRM_Core_Permission::check($permName); + } + return $this->addSetting(array( + 'permissions' => $perms, + )); + } + /** * Add a JavaScript file to the current page using