This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
17 changed files
with
151 additions
and
36 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
@users = User.all | ||
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,42 @@ | ||
class UsersController < ApplicationController | ||
before_filter :authenticate_user! | ||
load_and_authorize_resource :only => :index | ||
|
||
def resource_params | ||
unless params[resource_name].blank? | ||
params.require(resource_name).permit(:name, :email, :password, :password_confirmation, :remember_me) | ||
params.require(resource_name).permit(:role_ids, :as => :admin) | ||
end | ||
end | ||
|
||
# def index | ||
# authorize! :index, @user, :message => 'Not authorized as an administrator.' | ||
# @users = User.all | ||
# end | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def update | ||
authorize! :update, @user, :message => 'Not authorized as an administrator.' | ||
@user = User.find(params[:id]) | ||
if @user.update_attributes(params[:user], :as => :admin) | ||
redirect_to users_path, :notice => "User updated." | ||
else | ||
redirect_to users_path, :alert => "Unable to update user." | ||
end | ||
end | ||
|
||
def destroy | ||
authorize! :destroy, @user, :message => 'Not authorized as an administrator.' | ||
user = User.find(params[:id]) | ||
unless user == current_user | ||
user.destroy | ||
redirect_to users_path, :notice => "User deleted." | ||
else | ||
redirect_to users_path, :notice => "Can't delete yourself." | ||
end | ||
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 @@ | ||
module UsersHelper | ||
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
<h1>Home#index</h1> | ||
<p>Find me in app/views/home/index.html.erb</p> | ||
<h3>Home</h3> | ||
<% @users.each do |user| %> | ||
<p>User: <%=link_to user.name, user %></p> | ||
<% 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,15 @@ | ||
<div id="role-options-<%= user.id %>" class="modal" style="display: none;"> | ||
<%= simple_form_for user, :url => user_path(user), :html => {:method => :put, :class => 'form-horizontal' } do |f| %> | ||
<div class="modal-header"> | ||
<a class="close" data-dismiss="modal">×</a> | ||
<h3>Change Role</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<%= f.input :role_ids, :collection => Role.all, :as => :radio_buttons, :label_method => lambda {|t| t.name.titleize}, :label => false, :item_wrapper_class => 'inline', checked: user.role_ids.first %> | ||
</div> | ||
<div class="modal-footer"> | ||
<%= f.submit "Change Role", :class => "btn" %> | ||
<a class="btn" data-dismiss="modal" href="#">Close</a> | ||
</div> | ||
<% end %> | ||
</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,30 @@ | ||
<h3>Users</h3> | ||
<div class="span8"> | ||
<table class="table table-condensed"> | ||
<thead> | ||
<tr> | ||
<th>Username</th> | ||
<th>Email</th> | ||
<th>Registered</th> | ||
<th>Role</th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @users.each do |user| %> | ||
<tr> | ||
<td><%= link_to user.name, user %></td> | ||
<td><%= user.email %></td> | ||
<td><%= user.created_at.to_date %></td> | ||
<td><%= user.roles.first.name.titleize unless user.roles.first.nil? %></td> | ||
<td> | ||
<a data-toggle="modal" href="#role-options-<%= user.id %>" class="btn btn-mini" type="button">Change role</a> | ||
<%= render user %> | ||
</td> | ||
<td><%= link_to("Delete user", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'btn btn-mini') unless user == current_user %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</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>User: <%= @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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
end | ||
|
||
resources :items, only: :index | ||
resources :users | ||
|
||
root :to => 'home#index' | ||
|
||
|
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 |
---|---|---|
|
@@ -12,4 +12,4 @@ def change | |
t.timestamps | ||
end | ||
end | ||
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ def self.up | |
def self.down | ||
drop_attached_file :items, :photo | ||
end | ||
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
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 |
---|---|---|
|
@@ -5,3 +5,15 @@ | |
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
puts 'ROLES' | ||
YAML.load(ENV['ROLES']).each do |role| | ||
Role.find_or_create_by_name({ :name => role }, :without_protection => true) | ||
puts 'role: ' << role | ||
end | ||
puts 'DEFAULT USERS' | ||
user = User.find_or_create_by_email :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup | ||
puts 'user: ' << user.name | ||
user.add_role :admin | ||
user2 = User.find_or_create_by_email :name => 'Second User', :email => '[email protected]', :password => 'changeme', :password_confirmation => 'changeme' | ||
puts 'user: ' << user2.name | ||
user2.add_role :VIP |
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,15 @@ | ||
require 'spec_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the UsersHelper. For example: | ||
# | ||
# describe UsersHelper 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 UsersHelper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,5 @@ | ||
require 'spec_helper' | ||
|
||
describe "users/index.html.erb" do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,5 @@ | ||
require 'spec_helper' | ||
|
||
describe "users/show.html.erb" do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |