Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	app/models/user.rb
  • Loading branch information
mcfocus committed Dec 9, 2013
2 parents f5742df + 45bc914 commit 251c8a9
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
16 changes: 16 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class AdminController < ApplicationController

before_filter :authenticate_user!
before_filter :get_current_user

def index
@users

end

def enable_user
end

def disable_user
end
end
2 changes: 2 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AdminHelper
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def is_provider?
is_provider
end

def is_admin?
is_administrator
end

def validate_must_have_identity
if !is_provider && !is_consumer
errors[:identity] << "must have an identity!"
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render 'shared/user_header' %>
<%= render 'shared/error' %>
8 changes: 7 additions & 1 deletion app/views/shared/_user_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
</div>

<div class="user_profile">

<% if @user && @user.is_admin? %>
<%= link_to admin_index_url do %>
<div clas="admin_dashboard">Admin Dashboard</div>
<% end %>
<% end %>
<% if user_signed_in? %>
<%= link_to destroy_user_session_path, :method => :delete do %>
<div class="logout">Log Out</div>
Expand All @@ -16,7 +23,6 @@
<% end %>
<% else %>

<div class="dropdown">
<div class="login" data-toggle="dropdown">Sign In</div>
<div class='dropdown-menu' >
Expand Down
9 changes: 8 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
PeakDemand::Application.routes.draw do

# root
root :to => 'resource#index'


# user & mailing
devise_for :users
post '/mail/send' => 'UserMailer#send_email'

# admin & announcement
get 'admin/index' => 'Admin#index'
post 'admin/enable_user' => 'Admin#enable_user'
post 'admin/disable_user' => 'Admin#disable_user'
resources :announcement, :except => [:index, :new, :edit]

# resource & demand
resources :resource do
resources :demand, :except => :index
end
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/admin_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe AdminController do

describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end

describe "GET 'enable_user'" do
it "returns http success" do
get 'enable_user'
response.should be_success
end
end

describe "GET 'disable_user'" do
it "returns http success" do
get 'disable_user'
response.should be_success
end
end

end
15 changes: 15 additions & 0 deletions spec/helpers/admin_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the AdminHelper. For example:
#
# describe AdminHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe AdminHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 251c8a9

Please sign in to comment.