Giter Site home page Giter Site logo

devise_roles_lab-v-000's Introduction

Devise with Roles

Learning Objectives

  1. Explain the use of role-based authorization with Devise.
  2. Design a set of roles to model a forum with different permission levels.
  3. Set up Devise roles to implement such a model.

Data Model

In this lab, we're going to make a simple discussion board.

We'll have a Post model, and three user roles: user, vip, and admin.

  • Users can read anyone's Posts, and create, read, update, and delete their own posts.
  • VIPs can do everything a User can do, and update other users' posts.
  • Admins can do anything that Users and VIPs can do, and they can delete other users' posts.

Instructions

Provided is a Rails skeleton with the Devise gem installed.

  1. Run the migrations. A basic User model and migrations have been set up for you as part of the devise install.
  2. Add roles to the user model. The specs will tell you what roles are expected of the model.
  3. Add authentication and authorization filters to your users controller. Ensure that only administrators can update or destroy users.
  4. Run rails generate devise:views to generate the views.

Once you've reached this point, all the User specs should be passing. For the next part, we'll create a Post model, which has different permissions for different User roles.

We've written one basic Post spec for you, but you will need to write additional specs for the Post model and controller. You can reference the feature and model specs for the Users controller to see how to write these.

  1. Create a Post model and migration. Posts have an owner and content.
  2. Create a posts controller. Ensure that it enforces the following requirements:
  • Posts can be created by any user
  • Anyone can read any post
  • Users can edit or delete Posts they own
  • VIPs can edit anyone's Posts
  • Admins can do anything to any post.
  1. Write views for your posts.
  2. Try it out!

Resources

devise_roles_lab-v-000's People

Contributors

queerviolet avatar victhevenot avatar pletcher avatar blake41 avatar lizdenhup avatar annjohn avatar peterbell avatar thelucasmoore avatar alexgriff 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.