GithubHelp home page GithubHelp logo

bjf-flatiron / devise_roles_lab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-curriculum/devise_roles_lab

0.0 1.0 0.0 178 KB

License: Other

Ruby 90.32% JavaScript 1.53% HTML 7.22% CSS 0.93%

devise_roles_lab'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.

First we'll have a User model, which pretty much always shows up when we talk about Devise. There will be three possible roles: user, vip, and admin.

We'll also have a Post model.

  • 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 its migrations have been set up for you as part of the devise install. We'll want to get the roles working.
  2. Take a look at the User model and the User spec
  3. Run rspec spec/models/user_spec.rb
  4. Add roles to the User model to get the User model specs working
  5. Note: Running rspec spec/models/post_spec.rb will fail because we haven't created those model or tables yet.
  6. Now that our User model is valid and has roles, let's get its controller working. Run its spec (and it will fail!) with rspec ./spec/controllers/users_controller_spec.rb
  7. Use the failing specs to help you update the UsersController. You'll want to use authentication and authorization filters to help accomplish this goal. Ensure that only administrators can update or destroy users
  8. Run rails generate devise:views to generate the views
  9. Be sure to add the ERB code to display the flash in app/views/layouts/application.html.erb

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 the 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's People

Contributors

queerviolet avatar lizbur10 avatar dependabot[bot] avatar victhevenot avatar maxwellbenton avatar pletcher avatar blake41 avatar gj avatar annjohn avatar danielseehausen avatar peterbell avatar rrcobb 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.