Giter Site home page Giter Site logo

devise_pundit_lab-v-000's Introduction

Devise and Pundit Lab

Objectives

We're going to learn how to integrate Pundit into a Rails application. For our data model, we're going to return to our secret notes message board.

Data model

We're going to have Users, Notes, and a viewers join table, which gives users read access to notes.

Instructions

The lab comes with a Rails skeleton with Devise installed.

  1. Add a role enum to the user model.
  2. Write a policy governing the User model. Ensure all policy specs pass.
  3. Add authentication and authorization filters to your users controller. Ensure that only administrators can update or destroy users.

We've included the relevant models/controllers and views from the CanCanCan lab so you don't have to rebuild them. The data model is exactly the same, the only difference is that we're using Roles and Pundit to authorize actions rather than CanCanCan.

Note

If you launch the app in the browser in its starting state it will throw an error. This occurs because certain things the code depends on, like current_user, are no longer functional. You'll need to start implementing devise to boot the app up in the browser. Follow the tests.

Hints

  • Some tests might require you adding the flash to a layout.
  • If you use all the devise modules you will run into problems. Figure out which ones you need and include only those modules.

Using the User policy as a guide, write a spec for the NotePolicy class, then write the NotePolicy class. You should ensure that:

  • Normal users can:
    • Create notes owned by them
    • Edit their own posts
    • Delete their own posts
    • Add viewers to their own posts
    • Remove viewers from their own posts
    • See notes they're viewers of
    • See their own notes
  • Moderators can:
    • See all notes.
  • Admins can:
    • Perform any action on a user or a note.

Once your policy spec is written and passes, write feature specs for creating, reading, and updating notes. You can copy the feature specs that currently exist for updating and deleting users.

References

View Devise and Pundit Lab on Learn.co and start learning to code for free.

devise_pundit_lab-v-000's People

Contributors

queerviolet avatar blake41 avatar pletcher avatar annjohn avatar victhevenot avatar crwhitesides avatar dannyd4315 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.