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)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
permissions in CiviCRM-native extensions
February 08, 2013, 11:24:39 am
I see that civix generates menu XML files with the access_arguments property for each menu item.

Being unfamiliar with non-Drupal CMSs, I wonder how (if at all) this property is supported in WordPress and Joomla! installations. 

Is there a way that my CiviCRM-native module extension can limit access to its various features to one set of users or another?

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

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: permissions in CiviCRM-native extensions
February 09, 2013, 10:45:44 am
I'm pretty sure that the XML file that is generated by civix is specific to how your module's pages integrate with the host civicrm path and doesn't really have any effect on the CMS menu systems so that your new settings.php/settings.tpl page resolves at http://example.com/civicrm/my-module/settings

Totten can provide more insight in this.
My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: permissions in CiviCRM-native extensions
February 18, 2013, 03:29:03 pm
In the current Joomla integration, one can manage the role-based access-control matrix by going to CiviCRM's "Administer => Users and Permissions => Access Control =>Joomla Access Control". I believe this builds on a native Joomla feature (much like we do in Drupal).

In WordPress, I believe the CMS doesn't standardize the access-control matrix. At one point, I think we hard-coded some policies (e.g. WP admins became Civi admins), but a contributor last year implemented a role-based access control matrix for use with WordPress.

http://civicrm.org/blogs/rajesh/wordpress-access-control

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 18, 2013, 03:48:13 pm
So, is there something analogous to hook_perm in a civicrm module, which will allow the developer to define permissions that would be assigned to users or roles?

That is, if I'm developing com.example.foo module, and I want site admins who're using my module to be able to assign permissions "add to foo", "delete from foo", and "administer foo" permissions separately, where would I define those permissions?
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 18, 2013, 04:15:40 pm
Joe Murray was going to look at adding something like hook_perm in 4.3, but I don't see it right now, so maybe that ball got dropped. It's patch-welcome, though. ;)

For some pointers to anyone interested in patching:
 - I *think* the core bit of code which manages Civi's list of permissions is CRM_Core_Permission::basicPermissions. To open up to extensions, this would probably need to invoke a hook near the end.
 - This should work out fairly intuitively under Drupal (i.e. hook_perm calls CRM_Core_Permission::basicPermissions), but I'm not sure how it works on the other CMS's.
 - If the list of permissions is cached in any DBs/files/serialized-structures, then we may need to do some kind of flush/reset operation whenever an extension is enabled or disabled. I don't know what those caches/DBs/etc would be under each CMS, but a good spot to kick that off might be CRM_Core_Invoke::rebuildMenuAndCaches().
 - The main work will probably be in testing each of the CMSs.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: permissions in CiviCRM-native extensions
February 19, 2013, 08:31:37 am

Note that in joomla we expose the permissioning strings etc via xml in the install scripts, i.e. we dont do this programmatically

assigning roles to permissions was also equally cumbersome and was not trivial (and also done in the installer)

The wordpress integration with permissions seems a lot more reasonable and similar to drupal

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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 19, 2013, 11:39:05 am
My Joomla and WP experience is very limited, but Lobo are you saying that defining permission in a hook would be difficult in Joomla, but not probably not such a challenge in WordPress?  If so, would it be acceptable for CiviCRM to support something like hook_civicrm_perm in Drupal and WP, but not in Joomla?
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: permissions in CiviCRM-native extensions
February 19, 2013, 12:00:41 pm

I think this is definitely quite doable and easy in WP and Drupal. We do a fair bit of permission management in Civi internally for WP

In joomla, we currently interact with it via xml files. I'll ask brian / other joomla developers, if there are ways we can make it easier and do it programmatically

yes, IMO doing it for drupal/wp to begin with is a good step forward

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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 19, 2013, 03:17:20 pm
OK, for now I've created a new issue http://issues.civicrm.org/jira/browse/CRM-11925, as a placeholder for possible development along these lines.
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

pdelbar

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 3
  • Web integrator, Joomla freak, CiviFan
    • delius.be
  • CiviCRM version: 4.2.6/7
  • CMS version: Joomla 2.5.7 / 3.0
  • MySQL version: 5.1
  • PHP version: 5.3
Re: permissions in CiviCRM-native extensions
February 20, 2013, 02:34:25 am
I think there is a decent programmatical approach for ACL mods in Joomla -- but I'm taking the issue up with a friend of mine who's an ACL expert. Could you summarize what the hook should do ?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: permissions in CiviCRM-native extensions
February 20, 2013, 08:17:19 am

we need 3 things from the CMS:

1. Ability to expose permissions to the end user (things like view contacts etc). In joomla this is done today in the install step via an xml file: access.xml

2. Ability to set a set of permissions for certain roles: i.e. anon user can "register for events, donate money and create a profile" etc. This is currently done via some non-trivial code and sql in script.civicrm.php

3. ability to check if a certain user has a certain permission. This is nice and clean in joomla :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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 20, 2013, 08:26:07 am
Tim's expectations are proving helpful in Drupal so far: Creating hook_civicrm_permission(), and then calling it near the end of  CRM_Core_Permission::basicPermissions() is working well.

I still need to see what happens on disable/uninstall of the module-extension, and set up a WP install for testing as well.

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

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: permissions in CiviCRM-native extensions
February 20, 2013, 09:39:49 am
to my knowledge, there's no easy way to dynamically define a new permission in joomla the way you can in drupal. joomla's event/trigger system is only somewhat analogous to drupal's hooks. where drupal has hooks that are designed to alter system config, the events/trigger system are strictly a response to a user action.

joomla assumes that ACL permissions will be defined by the extension and be "fixed" -- that is why they are defined in an extension xml file called during the installation.

that said -- I think the goal here (if I understand correctly) is to create a civicrm hook that is a wrapper to the respective CMS's methods for implementing a new permission. and while joomla doesn't really give you a simple way to do that because of it's structure/assumptions -- I'm sure it can be done.

I think what we would need to look at is:
/libraries/joomla/access/rules.php -- merge($actions)

I *think* that would allow us to define new permissions for the com_civicrm asset and merge them with the existing ones.

the problem is that in Joomla this ends up being just a database action. which I think means that if someone were to upgrade civicrm via the extension installer, the asset permissions would be reset to whatever is defined in the civicrm access.xml file. because we are triggering the inclusion of those permissions via the civicrm extension install hook, they would be lost (unless the extension is reinstalled).

there is a joomla trigger on extension install. so i suppose we could call it in our main joomla-civicrm plugin -- basically work it so that when civicrm is installed/upgraded, we search for any instances of our civicrm perm hook and make sure we re-merge any new permissions with the main extension perms. that could even just be part of the civicrm install script (no need to handle it in a plugin).

(sorry to ramble...)
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

pdelbar

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 3
  • Web integrator, Joomla freak, CiviFan
    • delius.be
  • CiviCRM version: 4.2.6/7
  • CMS version: Joomla 2.5.7 / 3.0
  • MySQL version: 5.1
  • PHP version: 5.3
Re: permissions in CiviCRM-native extensions
February 21, 2013, 12:24:27 pm
I went for help to my good Joomla buddy Sander Potjer (NL), who's kind of a Joomla ACL guru. What I learned comes down to this :

The XML file is used to show a list of permitted actions for components, while the actual check by JUser::authorize happens by looking at the assets table. Joomla core file libraries/joomla/access/access.php, method getActions shows how the XML is read. Take a look at check() method in this file to see how the assets table is used.

Conclusion : if a permission mod in Civi would result in an asset table update in Joomla, we would expose all Civi permissions to Joomla ACL in a clean fashion.

Tip: set up the standard permissions using sections, like in administrator/components/com_content/access.xml :

Code: [Select]
<?xml version="1.0" encoding="utf-8" ?>
<access component="com_content">
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
</section>
<section name="category">
<action name="core.create" title="JACTION_CREATE" description="COM_CATEGORIES_ACCESS_CREATE_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="COM_CATEGORIES_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_CATEGORIES_ACCESS_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="COM_CATEGORIES_ACCESS_EDITOWN_DESC" />
</section>
<section name="article">
<action name="core.delete" title="JACTION_DELETE" description="COM_CONTENT_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_CONTENT_ACCESS_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CONTENT_ACCESS_EDITSTATE_DESC" />
</section>
</access>

And push in the custom ones in the right section.

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 22, 2013, 04:10:48 pm
Hi All,

With help from totten and eileen I've worked out a solution for Drupal that should also allow folks to fill in the bits for WordPress and Joomla!. (I tried testing on WP but quickly gave up trying to understand the workflow for a site admin managing user permissions.)

I'd really like to get some feedback before committing the code, mainly because the feedback I've gotten so far has been so useful.  The proposed patch is here: http://pastie.org/6319401

Functionality:
1. New hook_civicrm_permission() allows module devs to define permissions that will be treated as CiviCRM permissions by the CMS.

2. Upon uninstalling the module, vestigial records of the permissions (e.g., in D7's role_permission table) are cleaned up, very similar to how Drupal module permissions are cleaned up when those are uninstalled. This is not supported in D6, which also doesn't do it for its own modules.

3. Upon rebuild of the CiviCRM menu and cache, the above cleanup step is performed. This ensures that when a module is upgraded, any permissions from the old version are cleaned out if they're not defined in the new version.  Again, this is not done in D6, which doesn't do it for its own modules.

Architecture:
A. The functionality in #2 is provided by the methods uninstallPermissions() and upgradePermissions() in CRM_Core_Permission_Base, ready to be overridden in the corresponding WP and Joomla classes, if it's relevant on those platforms.

B. In Drupal 7, the functionality of #3 is supported by prefixing the module name to the permission key. In Drupal 6 this is not relevant. For Joomla! and WP, separate class methods are available to handle this differently as needed, in CRM_Core_Permission_Base::getModulePermissions().

C. Drupal's module_implements() function, returning a list of modules that implement a given hook, is mimicked by the new non-static method moduleImplements() in CRM_Utils_Hook_Drupal.  Like-named methods exist in CRM_Utils_Hook_WordPress and CRM_Utils_Hook_Joomla, with basic functionality to be modified as needed for WP/Joomla installations.  This also led to some refactoring in CRM_Utils_Hook.

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

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.