Answers.Body: <p>I may be misreading this, but it sounds like you're saying that you've got a new permission, and the user with the role that has the permission granted is working just fine.  However, you're saying that Drupal user ID 1 is being treated as if it has the permission, even though it doesn't have any role with that permission.</p>
  
  <p>If so, this is totally normal.  Drupal user ID 1 gets all permissions, even when using <code>CRM_Core_Permission::check('SpecialPermissions')</code>.  You should be able to confirm by creating another user without that permission and seeing that <code>CRM_Core_Permission::check('SpecialPermissions')</code> returns false.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-27T19:55:11.560Z
Answers.Text: Good to know, thanks; a bit unusual behaviour from a drupal user 1 point of view though.
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-26T20:11:26.907Z
Answers.LastActivityDate: 2016-01-26T20:11:26.907Z
Answers.UserDisplayName: Andie Hunt
Body: <p>How should custom permissions created by hook_civicrm_permission be properly  checked? </p>
  
  <p>Have defined custom permission like this:  </p>
  
  <pre><code>function mymodulename_civicrm_permission(&amp;$permissions) {
      $prefix = ts('SpecialPermissions') . ': '; // name of extension or module
      $permissions['SpecialPermissions'] = $prefix . ts('SpecialPermissions');
  }
  </code></pre>
  
  <p>and checking it later on, same module, hook_civicrm_buildForm,  have tried every option listed below:</p>
  
  <pre><code>* if (CRM_Core_Permission::check('SpecialPermissions')) {
  * if (CRM_Core_Permission::check('Drupal: SpecialPermissions')) {
  * if (CRM_Core_Permission::check('CiviCRM: SpecialPermissions')) {
  * if (CRM_Core_Permission::check('cms: SpecialPermissions')) {
  </code></pre>
  
  <p>Code looks like exactly according to specs from:
   * <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission</a>
   * <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Permission+Reference" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Permission+Reference</a></p>
  
  <p>However, both test user with a corresponded permission AND Drupal user 1 (UID=1) are being affected, even when Drupal User 1 doesn't have role with custom permissions attached. Not sure if it is by design or something wrong with my implementation of this? Please advice.</p>
  
Tags: <api><permissions><developer><hooks>
Title: hook_civicrm_permission in a drupal module
ThreadText: # hook_civicrm_permission in a drupal module
  
  (Asked by: username_0 on 2016-01-26)
  
  How should custom permissions created by hook_civicrm_permission be properly  checked? 
  Have defined custom permission like this:  
  function mymodulename_civicrm_permission(&$permissions) {
      $prefix = ts('SpecialPermissions') . ': '; // name of extension or module
      $permissions['SpecialPermissions'] = $prefix . ts('SpecialPermissions');
  }
  
  and checking it later on, same module, hook_civicrm_buildForm,  have tried every option listed below:
  * if (CRM_Core_Permission::check('SpecialPermissions')) {
  * if (CRM_Core_Permission::check('Drupal: SpecialPermissions')) {
  * if (CRM_Core_Permission::check('CiviCRM: SpecialPermissions')) {
  * if (CRM_Core_Permission::check('cms: SpecialPermissions')) {
  
  Code looks like exactly according to specs from:
   * http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission
   * http://wiki.civicrm.org/confluence/display/CRMDOC/Permission+Reference
  However, both test user with a corresponded permission AND Drupal user 1 (UID=1) are being affected, even when Drupal User 1 doesn't have role with custom permissions attached. Not sure if it is by design or something wrong with my implementation of this? Please advice.
  
  **Tags:** api, permissions, developer, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-26. Score: 1 | Accepted answer
  
  I may be misreading this, but it sounds like you're saying that you've got a new permission, and the user with the role that has the permission granted is working just fine. However, you're saying that Drupal user ID 1 is being treated as if it has the permission, even though it doesn't have any role with that permission.
  
  If so, this is totally normal. Drupal user ID 1 gets all permissions, even when using `CRM_Core_Permission::check('SpecialPermissions')`. You should be able to confirm by creating another user without that permission and seeing that `CRM_Core_Permission::check('SpecialPermissions')` returns false.
  
  > **Comments:**
  > **username_0**: Good to know, thanks; a bit unusual behaviour from a drupal user 1 point of view though.  
  
  ---
  
  