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 »
  • CiviVolunteer (Moderators: GinkgoFJG, Michael Z Daryabeygi) »
  • CiviVolunteer "assign volunteers" permission
Pages: [1] 2

Author Topic: CiviVolunteer "assign volunteers" permission  (Read 2365 times)

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
CiviVolunteer "assign volunteers" permission
January 19, 2014, 12:42:48 pm
I cannot get my Volunteer Coordinator set up correctly.
They are able to view the volunteer group, see events and even define volunteer needs and log volunteer hours.

The only thing that isn't functioning correctly is assign volunteers.
When they click on that button, the get the API permission check failed for volunteer_need/get call; missing permission: administer CiviCRM. error.

Do they really need to be able to administer civicrm or am I missing something?

Help please!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 01:14:37 pm
Sounds like the Volunteer extension needs to implement hook_alterAPIPermissions to declare correct permissions for its apis. "Administer CiviCRM" is the default.
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 01:42:10 pm
Thanks for the info.
Is this something I can handle or do I need someone who knows what they are doing? :)

I certainly can't be the first person to run into this.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 01:45:11 pm
If you want to submit a pull request for civivolunteer that would be cool. I think it's possible you might be the first to run into this, or at least the first to complain on the forum rather than doing a cheap workaround and giving Administer permissions.
Want help getting started with it?
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 02:10:14 pm
Tell me what to do and I'll gladly do it.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 02:16:09 pm
Have you done a PR before? First thing you need to do is checkout CiviVolunteer from github. So navigate to your extensions folder and do:
Code: [Select]
rm -R civivolunteer
git clone https://github.com/civicrm/civivolunteer.git
Note you don't need to reinstall civivolunteer or anything that basically just replaces the same code that was already there. But now you can commit changes to it.
With me so far? Let me know when you're ready for the next step.
« Last Edit: January 19, 2014, 05:16:10 pm by Coleman Watts »
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 03:46:25 pm
I haven't done a PR, but I've got my GitHub account set up am going to try the first step.

By the way, I'm on an IIS machine so bear with me.

Thanks for your assistance.
« Last Edit: January 19, 2014, 03:48:27 pm by pmosey »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 05:18:53 pm
Sorry mistyped the 2nd step above - just edited the post and fixed it. (adding git clone to the command, not just the url).
Once you get it cloned you can implement this hook in this file. Want more detail than that? Let me know.
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 19, 2014, 05:26:55 pm
I think I got the first step.

$ git clone https://github.com/civicrm/civivolunteer.git
Cloning into 'civivolunteer'...
remote: Reusing existing pack: 2853, done.
remote: Total 2853 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2853/2853), 596.22 KiB | 159.00 KiB/s, done.
Resolving deltas: 100% (978/978), done.
Checking connectivity... done.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 02:52:16 am
Thanks so much for leading me in the right direction.

So I need to add something like this in volunteer.php?

Code: [Select]
/**
 *  alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
 */
function volunteer_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
    // skip permission checks for volunteer_need/get calls
    // note: unsetting the below would require the default ‘administer CiviCRM’ permission
    $permissions['volunteer_need']['get'] = array();
    }
}

or just remove permission check for Volunteer Coordinators:

Code: [Select]
/**
 *  alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
 */
function volunteer_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
    // skip permission checks for volunteer_need/get calls for members of Volunteer Coordinators group
    // note: unsetting the below would require the default ‘administer CiviCRM’ permission
    if ($entity == 'volunteer_need' && $action == 'get' && $params['volunteer_coordinators_id'] == '16') {
    $params['check_permissions'] = 0;
    }
}
« Last Edit: January 20, 2014, 03:47:10 am by pmosey »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 10:02:39 am
That is indeed the right direction. Have you tested to see if that code does what you wanted it to do?
The first example is more correct than the 2nd (the 2nd being kind of hackish). In order to make it completely correct, let's add the right permissions instead of an empty array. Looking at the CiviVolunteer code, the permissions it checks are: access CiviEvent && edit all events.
So in your hook you would put:
Code: [Select]
$permissions['volunteer_need']['default'] = array('access CiviEvent', 'edit all events');Try that out. If it works, you're ready to submit your first Pull Request to GitHub :)
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 12:38:05 pm
Thanks for the tips.
Yeah, I got a bit lazy on the second bit of code.

Once I put your code in, I got another error about volunteer_assignment so I added that line as well.
After that, got an error that View All Activities needs to be granted, so checked that in Drupal permissions and it appears to be working.

The code that worked:
Code: [Select]
/**
 *  alterAPIPermissions() hook allows you to change the permissions checked when doing API 3 calls.
 */
function volunteer_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
    // skip permission checks for volunteer_need/get calls
    // note: unsetting the below would require the default ‘administer CiviCRM’ permission
  $permissions['volunteer_need']['default'] = array('access CiviEvent', 'edit all events');
  $permissions['volunteer_assignment']['default'] = array('access CiviEvent', 'edit all events');
}

Is there a cleaner way to do it?

Thanks again, I couldn't have doe it without you.
« Last Edit: January 20, 2014, 01:09:16 pm by pmosey »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 01:31:20 pm
Looks great. Only one last step: create the pull-request so that your code becomes part of CiviVolunteer.

A tiny bit of setup: if the git repo on your computer is a clone of civicrm/civivolunteer instead of pmosey/civivolunteer, just add your repo to the list of remotes:
Code: [Select]
git remote rename origin civi
git remote add pmosey https://github.com/pmosey/civivolunteer-1.git
If the reverse was true (you cloned your own fork and not the main one, do this instead:
Code: [Select]
git remote rename origin pmosey
git remote add civi https://github.com/civicrm/civivolunteer.git
Ok either way you should now have 2 remotes - civi and pmosey.

Now commit your change:
Code: [Select]
git commit -a -m "Add api permission hook"And push the change into your fork
Code: [Select]
git push pmosey masterNow click the pull request button on github to create your first PR :)
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 02:56:46 pm
Git is tougher to understand than the hooks!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: CiviVolunteer "assign volunteers" permission
January 20, 2014, 02:59:03 pm
Where are you stuck?
Try asking your question on the new CiviCRM help site.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions »
  • CiviVolunteer (Moderators: GinkgoFJG, Michael Z Daryabeygi) »
  • CiviVolunteer "assign volunteers" permission

This forum was archived on 2017-11-26.