diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..0027ffe --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,76 @@ +class UsersController < ApplicationController + load_and_authorize_resource + before_filter :authenticate_user! + + # GET /users + # GET /users.json + def index + @users = @users.sort_by(&:name) + + respond_to do |format| + format.html # index.html.erb + format.json { render :json => @users } + end + end + + # GET /users/1 + # GET /users/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.json { render :json => @user } + end + end + + # GET /users/new + # GET /users/new.json + def new + respond_to do |format| + format.html # new.html.erb + format.json { render :json => @user } + end + end + + # GET /users/1/edit + def edit + end + + # POST /users + # POST /users.json + def create + respond_to do |format| + if @user.save + format.html { redirect_to users_url, :notice => 'User was successfully created.' } + format.json { render :json => @user, :status => :created, :location => @user } + else + format.html { render :action => "new" } + format.json { render :json => @user.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /users/1 + # PUT /users/1.json + def update + respond_to do |format| + if @user.update_attributes(params[:user]) + format.html { redirect_to users_url, :notice => 'User was successfully updated.' } + format.json { head :no_content } + else + format.html { render :action => "edit" } + format.json { render :json => @user.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user.destroy + + respond_to do |format| + format.html { redirect_to users_url, :notice => 'User successfully deleted.' } + format.json { head :no_content } + end + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 3a28440..8523ae9 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -7,6 +7,7 @@ class Ability can :manage, :all else can :read, User, :id => user.id + can :read, Card, :user_id => user.id end end # Define abilities for the passed in user here. For example: diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 6791c16..5cebebe 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -1,7 +1,7 @@
User | @@ -22,9 +22,9 @@<%= card.id %> | <%= card.card_number %> | <%= if card.card_permissions == 1 then "Access" end %> | -<%= link_to 'Upload', upload_path(card) %> | -<%= link_to 'Edit', edit_card_path(card) %> | -<%= link_to 'Destroy', card, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE CARD FROM THE DOOR SYSTEM! DISABLE AND UPLOAD IT FIRST.', :method => :delete %> | +<%= link_to 'Upload', upload_path(card) if can? :upload, card %> | +<%= link_to 'Edit', edit_card_path(card) if can? :update, card %> | +<%= link_to 'Destroy', card, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE CARD FROM THE DOOR SYSTEM! DISABLE AND UPLOAD IT FIRST.', :method => :delete if can? :destroy, card %> |
---|
Name | +Cards | +Admin? | ++ | + | |
---|---|---|---|---|---|
<%= user.name %> | +<%= user.email %> | ++ <% user.cards.each do |c| %> + <%= link_to c.card_number, card_url(c) %><%= "," unless c == user.cards.last %> + <% end %> + | +<%= if user.admin? then "Admin" end %> | +<%= link_to 'Edit', edit_user_path(user) if can? :update, user %> | +<%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, user %> | +
+ Name: + <%= @user.name %> +
+ ++ Email: + <%= @user.email %> +
+ ++ Admin? + <%= @user.admin %> +
+ +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> diff --git a/config/routes.rb b/config/routes.rb index 56ed9fa..0e16b61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Dooraccess::Application.routes.draw do devise_for :users + resources :users match 'cards/upload_all' => 'cards#upload_all', :as => :upload_all resources :cards