www.drupaleurope.org Drupal + Technology TRACK SUPPORTED BY - - PowerPoint PPT Presentation

drupaleurope org drupal technology
SMART_READER_LITE
LIVE PREVIEW

www.drupaleurope.org Drupal + Technology TRACK SUPPORTED BY - - PowerPoint PPT Presentation

www.drupaleurope.org Drupal + Technology TRACK SUPPORTED BY 17/3/2018 Entity access for lists A crucially missing piece of the puzzle Kristiaan Van den Eynde Kristiaan Van den Eynde Senior Drupal developer @Magentix Kristiaan Van den Eynde


slide-1
SLIDE 1

www.drupaleurope.org

slide-2
SLIDE 2

Drupal + Technology

17/3/2018

TRACK SUPPORTED BY

slide-3
SLIDE 3

A crucially missing piece of the puzzle

Entity access for lists

Kristiaan Van den Eynde

slide-4
SLIDE 4

Kristiaan Van den Eynde

Senior Drupal developer @Magentix

slide-5
SLIDE 5

Kristiaan Van den Eynde

Work at Factorial GmbH in Hamburg Live near Antwerp, Belgium Group module maintainer Happily married, recently a dad Highly sensitive person

slide-6
SLIDE 6

Definition of list access

slide-7
SLIDE 7

Definition of list access

Checks access before entities are loaded

slide-8
SLIDE 8

Definition of list access

Checks access before entities are loaded Takes caching into account

slide-9
SLIDE 9

Definition of list access

Checks access before entities are loaded Takes caching into account Supported by Views

slide-10
SLIDE 10

Someone in the audience

But we already have that, so what's the big deal?

“ “

slide-11
SLIDE 11

Current implementation

The node grants system

slide-12
SLIDE 12

What is the node grants system?

slide-13
SLIDE 13

What is the node grants system?

Saves business logic to the database upon node manipulation

slide-14
SLIDE 14

What is the node grants system?

Saves business logic to the database upon node manipulation Alters queries tagged with node_access to check for access against this saved business logic

slide-15
SLIDE 15

What is the node grants system?

Saves business logic to the database upon node manipulation Alters queries tagged with node_access to check for access against this saved business logic Also used as fallback if regular access checks are indecisive

slide-16
SLIDE 16

What is the node grants system?

Saves business logic to the database upon node manipulation Alters queries tagged with node_access to check for access against this saved business logic Also used as fallback if regular access checks are indecisive Bad metaphor: Locks and keys

slide-17
SLIDE 17

What is the node grants system?

Saves business logic to the database upon node manipulation Alters queries tagged with node_access to check for access against this saved business logic Also used as fallback if regular access checks are indecisive Bad metaphor: Locks and keys Better metaphor: Bouncers at a night club

slide-18
SLIDE 18

What's wrong with node grants?

slide-19
SLIDE 19

What's wrong with node grants?

Only work for "content" (aka nodes)

slide-20
SLIDE 20

What's wrong with node grants?

Only work for "content" (aka nodes) Only work for view, update and delete actions

slide-21
SLIDE 21

What's wrong with node grants?

Only work for "content" (aka nodes) Only work for view, update and delete actions As a result does not scale well for other entities

slide-22
SLIDE 22

What's wrong with node grants?

Only work for "content" (aka nodes) Only work for view, update and delete actions As a result does not scale well for other entities Might try and store extremely complex access logic in the DB

slide-23
SLIDE 23

Can it be fixed?

slide-24
SLIDE 24

Can it be fixed?

Not really, the concept is past its due date Would either require a new column on existing table or one table per entity type, both are far from ideal Would require a new column per supported operation, which again would lead to unwieldy (and buggy) code

slide-25
SLIDE 25

Intermezzo

Possible approaches

slide-26
SLIDE 26

Keep altering queries

Pros and cons

slide-27
SLIDE 27

Pro: We already have ENTITY_TYPE_access query tags Pros and cons

Keep altering queries

slide-28
SLIDE 28

Pro: We already have ENTITY_TYPE_access query tags Pro: People are already used to this approach Pros and cons

Keep altering queries

slide-29
SLIDE 29

Pro: We already have ENTITY_TYPE_access query tags Pro: People are already used to this approach Con: Complicated use cases may find themselves limited by SQL Pros and cons

Keep altering queries

slide-30
SLIDE 30

Scalable pagination

Access checks in code

slide-31
SLIDE 31

Proposed by catch early 2017 Based on a Four Kitchens blog post from 2009 https://www.fourkitchens.com/blog/article/anticipage-scalable- pagination-especially-acls/

Scalable pagination

Access checks in code

slide-32
SLIDE 32

Scalable pagination explained

slide-33
SLIDE 33

Scalable pagination explained

You ask for more results than you need and pull them through your access logic

slide-34
SLIDE 34

Scalable pagination explained

You ask for more results than you need and pull them through your access logic If you do not have enough results, go back to the database for more

slide-35
SLIDE 35

Scalable pagination explained

You ask for more results than you need and pull them through your access logic If you do not have enough results, go back to the database for more Keep track of the first and last item and use them for paging

slide-36
SLIDE 36

Scalable pagination explained

You ask for more results than you need and pull them through your access logic If you do not have enough results, go back to the database for more Keep track of the first and last item and use them for paging Works best on sites where most content is accessible to everyone

slide-37
SLIDE 37

Scalable pagination

Pros and cons

slide-38
SLIDE 38

Pro: Same access logic for both individual entities and entity lists

Scalable pagination

Pros and cons

slide-39
SLIDE 39

Pro: Same access logic for both individual entities and entity lists Pro: No "content drift" due to Reddit-style pagers (next/previous)

Scalable pagination

Pros and cons

slide-40
SLIDE 40

Pro: Same access logic for both individual entities and entity lists Pro: No "content drift" due to Reddit-style pagers (next/previous) Con: Poor performance on sites with more complex access set-ups

Scalable pagination

Pros and cons

slide-41
SLIDE 41

Pro: Same access logic for both individual entities and entity lists Pro: No "content drift" due to Reddit-style pagers (next/previous) Con: Poor performance on sites with more complex access set-ups Con: No indication of amount of possible results

Scalable pagination

Pros and cons

slide-42
SLIDE 42

Pro: Same access logic for both individual entities and entity lists Pro: No "content drift" due to Reddit-style pagers (next/previous) Con: Poor performance on sites with more complex access set-ups Con: No indication of amount of possible results Con: People are not familiar with this approach

Scalable pagination

Pros and cons

slide-43
SLIDE 43

Someone else in the audience

You don't seem to be a fan of scalable pagination

“ “

slide-44
SLIDE 44

Query altering: Part Deux

slide-45
SLIDE 45

A summary of previous work

slide-46
SLIDE 46

A summary of previous work

Extend the entity access system with a new grants API (and deprecate the query-alter-based node grants API)
 https://www.drupal.org/project/drupal/issues/777578

slide-47
SLIDE 47

A summary of previous work

Extend the entity access system with a new grants API (and deprecate the query-alter-based node grants API)
 https://www.drupal.org/project/drupal/issues/777578 Entity access policies
 https://www.drupal.org/project/entity_access_policies

slide-48
SLIDE 48

A summary of previous work

Extend the entity access system with a new grants API (and deprecate the query-alter-based node grants API)
 https://www.drupal.org/project/drupal/issues/777578 Entity access policies
 https://www.drupal.org/project/entity_access_policies Implement a query-level entity access API
 https://www.drupal.org/project/entity/issues/2909970

slide-49
SLIDE 49

Entity access policies

slide-50
SLIDE 50

Entity access policies

A collection of access plugin, e.g.: is_published

slide-51
SLIDE 51

Entity access policies

A collection of access plugin, e.g.: is_published Used in policy config entities that list which entity types and

  • perations they apply to
slide-52
SLIDE 52

Entity access policies

A collection of access plugin, e.g.: is_published Used in policy config entities that list which entity types and

  • perations they apply to

When an entity query is launched, this system kicks in, finds all applicable policies and compiles them into one query alter

slide-53
SLIDE 53

Entity access policies

A collection of access plugin, e.g.: is_published Used in policy config entities that list which entity types and

  • perations they apply to

When an entity query is launched, this system kicks in, finds all applicable policies and compiles them into one query alter You can build a UI showing all of the active access policies for your website and even allowing you to edit them

slide-54
SLIDE 54

Entity access policies

Pros and cons

slide-55
SLIDE 55

Entity access policies

Pro: Supports any operation and entity type Pros and cons

slide-56
SLIDE 56

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pros and cons

slide-57
SLIDE 57

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pro: Works alongside node grants (until hopefully removed in D9) Pros and cons

slide-58
SLIDE 58

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pro: Works alongside node grants (until hopefully removed in D9) Pro: Easy to work around a problematic module Pros and cons

slide-59
SLIDE 59

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pro: Works alongside node grants (until hopefully removed in D9) Pro: Easy to work around a problematic module Con: Too big of a change at once to go into core Pros and cons

slide-60
SLIDE 60

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pro: Works alongside node grants (until hopefully removed in D9) Pro: Easy to work around a problematic module Con: Too big of a change at once to go into core Con: Loads a list of config entities to decide access to another list of entities Pros and cons

slide-61
SLIDE 61

Entity access policies

Pro: Supports any operation and entity type Pro: Option to have an access overview UI Pro: Works alongside node grants (until hopefully removed in D9) Pro: Easy to work around a problematic module Con: Too big of a change at once to go into core Con: Loads a list of config entities to decide access to another list of entities Con: Nowhere near finished Pros and cons

slide-62
SLIDE 62

A query-level entity access API

slide-63
SLIDE 63

A query-level entity access API

Registered as an entity type handler

slide-64
SLIDE 64

A query-level entity access API

Registered as an entity type handler Generates conditions based on the user's permissions which are ultimately added to the query

slide-65
SLIDE 65

A query-level entity access API

Registered as an entity type handler Generates conditions based on the user's permissions which are ultimately added to the query Fires an event to alter the conditions (so before query alter)

slide-66
SLIDE 66

A query-level entity access API

Registered as an entity type handler Generates conditions based on the user's permissions which are ultimately added to the query Fires an event to alter the conditions (so before query alter) Works for Views and entity queries

slide-67
SLIDE 67

Pros and cons

A query-level entity access API

slide-68
SLIDE 68

Pro: Familiar approach (entity handlers) Pros and cons

A query-level entity access API

slide-69
SLIDE 69

Pro: Familiar approach (entity handlers) Pro: Works well for most scenarios out of the box Pros and cons

A query-level entity access API

slide-70
SLIDE 70

Pro: Familiar approach (entity handlers) Pro: Works well for most scenarios out of the box Pro: Small enough in scope to make it into core Pros and cons

A query-level entity access API

slide-71
SLIDE 71

Pro: Familiar approach (entity handlers) Pro: Works well for most scenarios out of the box Pro: Small enough in scope to make it into core Con: Relies on a permission handler that hasn't made it to core yet Pros and cons

A query-level entity access API

slide-72
SLIDE 72

Pro: Familiar approach (entity handlers) Pro: Works well for most scenarios out of the box Pro: Small enough in scope to make it into core Con: Relies on a permission handler that hasn't made it to core yet Con: Hard to alter or prevent another module's access logic Pros and cons

A query-level entity access API

slide-73
SLIDE 73

Good news everyone

slide-74
SLIDE 74

Work on query access handler to be committed to Entity API within a week Permission handler on a fast-track to be added to core
 https://www.drupal.org/node/2809177 This paves the way for adding the query access handlers to core Likely in Drupal 8.7.0

Roadmap

slide-75
SLIDE 75

Become a Drupal contributor Friday from 9am

  • First timers workshop
  • Mentored contribution
  • General contribution
slide-76
SLIDE 76

Thank you!

slide-77
SLIDE 77

Questions?