CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • permissions in CiviCRM-native extensions
Pages: 1 [2]

Author Topic: permissions in CiviCRM-native extensions  (Read 4389 times)

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: permissions in CiviCRM-native extensions
February 26, 2013, 01:06:40 am
I like how it delegates uninstallPermissions() and upgradePermissions() to each CMS class, and the D7 implementations seem good.

Rewriting long permission-names in D7 (e.g. the "$module|" . md5($key)) also seems clever. (Aside: Does that work intuitively with CRM_Core_Permission::check?)

There is some difficulty in the getModulePermissions($module) and commonModuleImplements():
 * Based on the D7 impl of getModulePermissions, I get the impression that this should work with both Civi ext-modules and CMS modules.
 * Well, kind-of: removePermissions() will be called for Civi ext-modules but not Drupal modules.
 * The technique cannot be adapted to Joomla plugins. The problem is that the central registry for Joomla plugins (JDispatcher/JPluginHelper) doesn't expose that information. One could create a "work-a-like" that instantiates plugins much like JDispatcher/JPluginHelper, but it'll deviate slightly from standards (e.g. any $this->foo variables will misbehave).
 * If a developer edits a module and completely removes the hook (but doesn't uninstall the module), then the upgradePermissions() tool won't run.

Fortunately, I think we can sidestep most of this. The CMS's already provide their own ways to declare permissions. If you're writing a Drupal module or Joomla plugin, then you don't need hook_civicrm_permissions. You can use the CMS's convention. We only need hook_civicrm_permissions for Civi ext-modules.

You might change the implementation of CRM_Core_Config::cleanupPermisisons to run upgradePermissions() for *every* native extension (and only native extensions), regardless of whether they currently implement the hook. You might get a list of these by calling one of:

CRM_Extension_System::singleton()->getMapper()->getModules()
CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles()

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: permissions in CiviCRM-native extensions
February 27, 2013, 01:22:20 pm
Re-reading my Joomla comment, it seems a bit badly worded. The point is this -- I don't think it's possible to support the getModulePermissions($module) and commonModuleImplements() design for Joomla plugins. For better or worse, Joomla doesn't provide a way to trigger events (or invoke hooks) on individual plugins, and it doesn't provide a way to walk through the list of plugin objects. That functionality is hidden (by design) inside JDispatcher.

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: permissions in CiviCRM-native extensions
February 27, 2013, 04:32:20 pm
Thanks for the help totten, this is great input.

I've implemented your suggestion to clean up permissions for all and only CiviCRM native extensions on menu rebuild. Great point.

I've also refactored the moduleImplements() and getModulePermissions() stuff so that it doesn't affect Joomla. Glad you spotted that.

I suppose I'll go ahead and commit. Feel free to ping me if it needs more attention.

Thanks!

- Allen
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: permissions in CiviCRM-native extensions
February 27, 2013, 09:58:46 pm
Cool! Will do.

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • permissions in CiviCRM-native extensions

This forum was archived on 2017-11-26.