SlideShare a Scribd company logo
1 of 69
Node access
  Jasper Knops
whoami
         2
<strong>
           3
<3
     4
5
6
wtf
      7
8
Why?


       9
Permissions


              10
Roles
 Permissions
user_access()

                11
Roles
 anonymous
authenticated
custom roles
                12
Permissions
view content
 add block
edit articles
delete users
                13
function
 user_access()
$string, $account

                    14
node_access()

2 basic implementation
        grants

                         15
view
   create
   update
   delete

5 operations
    list
               16
node.module
function node_access()
   $op, $node, $account



                          17
1



Check permission
user_access(‘bypass node access’);
user_access(‘access content’);



                                     18
2

    6 node.php
    hook_access($op, $node,
    $account)

    7 node.api.php
    hook_node_access($node,
    $op, $account)
                              19
MODULE_node_access() {
    return NODE_ACCESS_DENY;
    return NODE_ACCESS_IGNORE;
    return NODE_ACCESS_ALLOW;

}

                                 20
NODE_node_access() {
    case ‘create’:
     user_access(‘create TYPE content’);

}


                                           21
NODE_node_access() {
    case ‘update’:
     user_access(‘update any TYPE content’);
     user_access(‘update own TYPE content’);

}

                                               22
NODE_node_access() {
    case ‘delete’:
     user_access(’delete any TYPE content’);
     user_access(‘delete own TYPE content’);

}

                                               23
3



Check permission
user_access(‘view own unpublished
content’);



                                    24
4



       Grants?
    table {node_access}




                          25
5



          No grants?
user_access(‘view published content’);




                                         26
6




    return FALSE;


                    27
Wat hebben we vandaah heleerd?
                                 28
Permissions
   user_access
  node_access
hook_node_access
     grants?
                   29
So, what is that
granting all about?


                      30
{node_access}
                31
hook_node_access_records()
return {node_access} records
  doesn’t care if a node is published or not




                                               32
$grants[] = array(
     'realm' => 'example_author',
     'gid' => $node->uid,
     'grant_view' => 1,
     'grant_update' => 1,
     'grant_delete' => 1,
     'priority' => 0,
);


                                    33
Deny all
$grants[] = array(
     'realm' => 'all',
     'gid' => 0,
     'grant_view' => 0,
     'grant_update' => 0,
     'grant_delete' => 0,
     'priority' => 1,
);

                            34
hook_node_access_records_alter()
        &$grants, $node



                              35
node.module
node_access_acquire_grants()
           $node


                               36
hook_node_access_grants()
     return $grants;



                            37
$grants[‘example_author’] = array(
   $account->uid,
);




                                     38
domain.module
$grants[] = array(
     'realm' => 'domain_id',
     'gid' => $node->domain_id,
     'grant_view' => 1,
     'grant_update' => 0,
     'grant_delete' => 0,
     'priority' => 0,
);

                                  39
domain.module
$grants[‘domain_id’] = array(
  $current_domain->domain_id,
);


                                40
{node_access}

nid   gid       realm        view   update delete


 1    5     example_author    1       1      1



 1    2       domain_id       1       0      0


                                                    41
Wat hebben we vandaah heleerd?
                                 42
define records
    save records
return user records


                      43
Where?



         44
node.module
function node_access()
   $op, $node, $account
          view
         update
         delete

                          45
$query->addTag(‘node_access’)
             list



                            46
hook_query_TAG_alter(QueryAlt
    erableInterface $query)



                           47
hook_query_node_access_alter(
QueryAlterableInterface $query)



                             48
1


$query->getMetaData(‘account’);
$query->addMetaData(‘account’,
          $account);


                             49
2


    $query->getMetaData(‘op’);
    $query->addMetaData(‘op’,
            ‘delete’);


                                 50
3



    user_access('bypass node
            access');



                               51
4




    Grants?



              52
5




node_access_view_all_nodes()



                           53
6




    $query->join(‘node_access’);



                                   54
Disables node_access checks


                          55
{node_deny}



              56
My custom security widget
       It ‘s a field



                            57
Per space
 Company
allow / deny

               58
Function
allow / deny


               59
60
{content_space_index}



                        61
$node->nid = 4;
$node->space_id = 2;
$node->company_allow = 0;
$node->company = ‘Nascom’;
$node->company_allow = 1;
$node->function = ‘Developer’;
                                 62
nid   gid   realm   view   update   delete


4     2     index    1       0        0




                                             63
nid    gid       realm     view   update   delete


4     Nascom   2_company    1       0        0




                                                    64
nid      gid       realm     view   update   delete


4     Developer   function    ??      0        0




                                                      65
hook_node_access_records_alter
  hook_node_access_records
       hook_node_grants
      hook_node_access
    hook_node_grants_alter
 node_query_node_access_alter
hook_node_access_acknowledge
   hook_node_access_explain




                                 66
http://api.drupal.org/api/drupal/modules%21node
%21node.module/group/node_access/7
http://api.drupal.org/api/drupal/modules%21node
%21node.module/function/node_access/7
http://www.palantir.net/blog/controlling-nodes-drupal-7




                                                          67
Applause

           68
Feedback & follow-up:
http://drupalcampgent.be/feedback

More Related Content

What's hot

Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
Anton Kril
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentation
plindner
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldos
mfrancis
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 

What's hot (20)

Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumname
 
iBATIS
iBATISiBATIS
iBATIS
 
Top Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in DrupalTop Ten Reasons to Use EntityFieldQuery in Drupal
Top Ten Reasons to Use EntityFieldQuery in Drupal
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Final tagless and cats mtl
Final tagless and cats mtl Final tagless and cats mtl
Final tagless and cats mtl
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in Laravel
 
Drupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of UsageDrupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of Usage
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentation
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldos
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Mpg Dec07 Gian Lorenzetto
Mpg Dec07 Gian Lorenzetto Mpg Dec07 Gian Lorenzetto
Mpg Dec07 Gian Lorenzetto
 
SQLAlchemy Seminar
SQLAlchemy SeminarSQLAlchemy Seminar
SQLAlchemy Seminar
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android Architecture
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 

Similar to Drupalcamp gent - Node access

From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular Library
Bo-Yi Wu
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
Alexander Makarov
 

Similar to Drupalcamp gent - Node access (20)

ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Introduction to Codeigniter
Introduction to Codeigniter Introduction to Codeigniter
Introduction to Codeigniter
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
My Development Story
My Development StoryMy Development Story
My Development Story
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular Library
 
Cloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross BoucherCloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross Boucher
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
Zendcon 09
Zendcon 09Zendcon 09
Zendcon 09
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
Xdebug confoo11
Xdebug confoo11Xdebug confoo11
Xdebug confoo11
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Drupalcamp gent - Node access

Editor's Notes

  1. \n
  2. mussels\n
  3. 3 years drupal developer\n
  4. girlfriend\n
  5. nascom since 2009\n8 collegues\ndesigners, ux\n
  6. netlog\nperformance\nbackoffice\n
  7. \n
  8. level audience\nbest drupal developer\nhipsters\n
  9. why this subject\ncustom security widget\nspaces\n
  10. first concept\nuser_access\nroles\npermissions\n
  11. \n
  12. demo\nex: comments\n
  13. defined by modules\nimplemented by modules\ndemo\n
  14. fetch permissions\ncheck role current user\nuser 1\n
  15. second mechanism, actually two in one\nnode access function in node.module\npermissions\nhooks\ngrants : simple but hard to explain\n
  16. access to what??\nview/create/update/delete =&gt; node_access\nlist =&gt; grants\ncreate: node type\n
  17. use node_access() function\nlets go through the flow\n
  18. cfr permissions admin page\nuser_access return TRUE for user 1\n
  19. 6 - Only implemented by module of content type\n7 - Much much more flexible\nhook_node_access is triggered\n
  20. Implement hook_node_access\nargs($node, $op, $account)\nflexible but at runtime -&gt; performance\n3 return values\nFALSE will brake other modules\nex: age check\ncheck custom created permissions\nex: domain\n
  21. implementation of hook_node_access of node.module\nchecks permissions\n
  22. check permissions\ncheck if node is your own + check permissions\n
  23. same as update\n
  24. after hook_node_access \nanother permissions\ncheck if content is yours\n
  25. Are grants implemented?\nNot only for lists\nTop of the iceberg -&gt; table node_access\n
  26. check permission\n
  27. \n
  28. Permissions\nnode_access\nhook_node_access\ngrants?\n
  29. function user_access\nnode_access -&gt; operations\nNODE_hook_node_access\ntable {node_access}\n
  30. list operation\nviews\ngrants are records in table node_access\nfunction node_access\n\n
  31. Draait rond 1 tabel\n
  32. fill table with grants\n
  33. node_access_record example\nreturn as array\nrrelm\n3 operations\n\n
  34. deny all record\nnot written to database\n\n
  35. alter hook\nadjust grants of other modules\n
  36. called after save\ncall after custom action\nrecords are fetched and written to db\nReports &gt; Status reports &gt; Rebuild permissions\ndemo\n
  37. $account, $op\n
  38. array with realms as keys and gids as value\n
  39. example domain module\nrecords\nmultiple domain -&gt; multiple records\n
  40. example domain module\ngrants\n
  41. records written to database\n
  42. define records\nreturn records\nsave records\n
  43. 3 basic actions\ndefine pottekes and deksels\nwrite combinations\nget user deksel\n\n
  44. \n
  45. where do we use grants?\nnot for create\nfetch all records and return TRUE if found\n
  46. Grants for queries\ndynamic query with tag\n
  47. hook to alter queries\n
  48. subquery of node_access records\nrewrites query\n
  49. get operation\n
  50. get operation\n
  51. get operation\n
  52. get operation\n
  53. grant with nid 0\n
  54. Get user grants and join with node_access table\n
  55. View &gt; Advanced &gt; Other &gt; Query settings\ndemo\n
  56. subquery of node_access records\nrewrites query\n
  57. \n
  58. 2 components\n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. subquery of node_access records\nrewrites query\n
  67. \n
  68. \n
  69. \n