pundit - ruby on rails police department

15
PUNDIT Ruby on Rails Police Department Piotr Kochowicz

Upload: binar-apps-ruby-on-rails-developers

Post on 09-Apr-2017

425 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Pundit - Ruby on Rails Police Department

PUNDITRuby on Rails Police Department

Piotr Kochowicz

Page 2: Pundit - Ruby on Rails Police Department

AGENDA

Motivation

Gem overview

Use cases

Page 3: Pundit - Ruby on Rails Police Department

MOTIVATION

Peer discussion

Project experience

Curiosity

Page 4: Pundit - Ruby on Rails Police Department

PUNDIT history

created by ELABS

alternative for CanCan

based on objectify

Page 5: Pundit - Ruby on Rails Police Department

PUNDIT

simple

object oriented

flexible

isolated

Page 6: Pundit - Ruby on Rails Police Department

APPLICATION POLICY

Base class for policies

Defines default policy behaviour

Page 7: Pundit - Ruby on Rails Police Department

POLICY

Defined for an object

Accesses a user and an object

Contains Scope class and authorization methods

inherits from ApplicationPolicy

Page 8: Pundit - Ruby on Rails Police Department

APPLICATION CONTROLLER

Ensures policies are used

Handles authorization exception

Additional exception info

exception.policy

exception.query

exception.record

Page 9: Pundit - Ruby on Rails Police Department

CONTROLLER

Uses policy for scoping

Authorizes object

Page 10: Pundit - Ruby on Rails Police Department

RSPEC

Page 11: Pundit - Ruby on Rails Police Department

RSPEC simple

http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/

Page 12: Pundit - Ruby on Rails Police Department

OTHER FEATURES

Using policy in a view

Strong parameters

Custom user

Custom policy class

Page 13: Pundit - Ruby on Rails Police Department

OTHER FEATURES

Policy without objectAlias method

Page 14: Pundit - Ruby on Rails Police Department

DISCUSSION

Best use cases

Where it creates overhead?

Page 15: Pundit - Ruby on Rails Police Department

Thank you

Piotr Kochowicz [email protected]

Reference:https://github.com/elabs/pundithttp://www.elabs.se/blog/52-simple-authorization-in-ruby-on-rails-appshttp://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/http://www.sitepoint.com/straightforward-rails-authorization-with-pundit/https://github.com/FetLife/objectifyhttp://www.slideshare.net/BruceWhite3/pundit-37048056 by Bruce Whitehttp://slides.com/maciekbrodecki/prezpundit#/ by Maciej Brodecki