Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c7ec07
commit 1a4a22a
Showing
11 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class UsersController < ApplicationController | ||
before_filter :authenticate_user! | ||
before_filter :admin_only, :except => :show | ||
|
||
def index | ||
@users = User.all | ||
end | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
unless current_user.admin? | ||
unless @user == current_user | ||
redirect_to :back, :alert => "Access denied." | ||
end | ||
end | ||
end | ||
|
||
def update | ||
@user = User.find(params[:id]) | ||
if @user.update_attributes(secure_params) | ||
redirect_to users_path, :notice => "User updated." | ||
else | ||
redirect_to users_path, :alert => "Unable to update user." | ||
end | ||
end | ||
|
||
def destroy | ||
user = User.find(params[:id]) | ||
user.destroy | ||
redirect_to users_path, :notice => "User deleted." | ||
end | ||
|
||
private | ||
|
||
def admin_only | ||
unless current_user.admin? | ||
redirect_to :back, :alert => "Access denied." | ||
end | ||
end | ||
|
||
def secure_params | ||
params.require(:user).permit(:role) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class VisitorsController < ApplicationController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
<%# add navigation links to this file %> | ||
<% if user_signed_in? %> | ||
<li><%= link_to 'Edit account', edit_user_registration_path %></li> | ||
<li><%= link_to 'Sign out', destroy_user_session_path, :method=>'delete' %></li> | ||
<% else %> | ||
<li><%= link_to 'Sign in', new_user_session_path %></li> | ||
<li><%= link_to 'Sign up', new_user_registration_path %></li> | ||
<% end %> | ||
<% if user_signed_in? %> | ||
<li><%= link_to 'Users', users_path %></li> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<td> | ||
<%= link_to user.email, user %> | ||
</td> | ||
<td> | ||
<%= form_for(user) do |f| %> | ||
<%= f.select(:role, User.roles.keys.map {|role| [role.titleize,role]}) %> | ||
<%= f.submit 'Change Role', :class => 'button-xs' %> | ||
<% end %> | ||
</td> | ||
<td> | ||
<%= link_to("Delete user", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'button-xs') unless user == current_user %> | ||
</td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="container"> | ||
<div class="row"> | ||
<h3>Users</h3> | ||
<div class="column"> | ||
<table class="table"> | ||
<tbody> | ||
<% @users.each do |user| %> | ||
<tr> | ||
<%= render user %> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h3>User</h3> | ||
<p>Name: <%= @user.name if @user.name %></p> | ||
<p>Email: <%= @user.email if @user.email %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h3>Welcome</h3> | ||
<p><%= link_to 'Users:', users_path %> <%= User.count %> registered</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module DevisePermittedParameters | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_filter :configure_permitted_parameters | ||
end | ||
|
||
protected | ||
|
||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.for(:sign_up) << :name | ||
devise_parameter_sanitizer.for(:account_update) << :name | ||
end | ||
|
||
end | ||
|
||
DeviseController.send :include, DevisePermittedParameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Feature: Home page | ||
# As a visitor | ||
# I want to visit a home page | ||
# So I can learn more about the website | ||
feature 'Home page' do | ||
|
||
# Scenario: Visit the home page | ||
# Given I am a visitor | ||
# When I visit the home page | ||
# Then I see "Welcome" | ||
scenario 'visit the home page' do | ||
visit root_path | ||
expect(page).to have_content 'Welcome' | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Feature: Navigation links | ||
# As a visitor | ||
# I want to see navigation links | ||
# So I can find home, sign in, or sign up | ||
feature 'Navigation links', :devise do | ||
|
||
# Scenario: View navigation links | ||
# Given I am a visitor | ||
# When I visit the home page | ||
# Then I see "home," "sign in," and "sign up" | ||
scenario 'view navigation links' do | ||
visit root_path | ||
expect(page).to have_content 'Home' | ||
expect(page).to have_content 'Sign in' | ||
expect(page).to have_content 'Sign up' | ||
end | ||
|
||
end |