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) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Ajax API Permissions
Pages: [1]

Author Topic: Ajax API Permissions  (Read 676 times)

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Ajax API Permissions
August 06, 2014, 12:12:33 pm
The user has permissions of access CiviCRM and access AJAX API and I've added

function dog_reference_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions){
       
    if($entity == 'Dog'){
        $params['check_permissions'] = false;
    }
}

to a custom module.

When the user causes an Ajax call to a custom extension api get, he gets the error "API permission check failed for Dog/get call; insufficient permission: require administer CiviCRM".

This works ok for an admin user.

The call is CRM.api('Dog', 'get', {'sequential': 1, 'type': 'all', 'dog_name':cj("#type_dog_name").val()})

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Re: Ajax API Permissions
August 06, 2014, 12:50:50 pm
The site is using Drupal 7.29 and CiviCRM 4.4.5.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Ajax API Permissions
August 07, 2014, 01:36:16 am
Is  dog_reference_civicrm_alterAPIPermissions ever called?

Instead of using check_permission (the check permission might be overrided later to force true?) , you should set the permission you want (access CiviCRM?)


function dog_reference_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions)
{
    $permissions['dog']['get'] = array('access CiviCRM');
    $permissions['dog']['delete'] = array('admininster CiviCRM');
    $permissions['dog']['create'] = array('add contacts');
//whatever.
}
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Re: Ajax API Permissions
August 07, 2014, 05:13:18 am
I tried the following and cleared cache before each try;

$permissions['Dog']['get'] = array('access CiviCRM');

and

$permissions['Dog']['get'] = array();

I still get the same error "API permission check failed for Dog/get call; insufficient permission: require administer CiviCRM"

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Re: Ajax API Permissions
August 07, 2014, 07:25:35 am
dog_reference_civicrm_alterAPIPermissions is called.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Ajax API Permissions
August 07, 2014, 09:46:19 am
lowercase on the entity name here (dog eats Dog)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Re: Ajax API Permissions
August 07, 2014, 12:12:42 pm
That was it. I ended up using $permissions['dog']['get'] = array('access AJAX API');

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Ajax API Permissions

This forum was archived on 2017-11-26.