captain_oveur 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.textile +3 -0
- data/LICENSE +20 -0
- data/Manifest +32 -0
- data/README +21 -0
- data/README.textile +21 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/app/controllers/admin/users_controller.rb +106 -0
- data/app/views/admin/users/_form.erb +12 -0
- data/app/views/admin/users/edit.html.erb +6 -0
- data/app/views/admin/users/index.html.erb +12 -0
- data/app/views/admin/users/new.html.erb +2 -0
- data/app/views/admin/users/show.html.erb +4 -0
- data/captain_oveur.gemspec +39 -0
- data/generators/captain_oveur/README +6 -0
- data/generators/captain_oveur/USAGE +1 -0
- data/generators/captain_oveur/captain_oveur_generator.rb +55 -0
- data/generators/captain_oveur/lib/insert_commands.rb +33 -0
- data/generators/captain_oveur/lib/rake_commands.rb +22 -0
- data/generators/captain_oveur/templates/admins.rb +4 -0
- data/generators/captain_oveur/templates/migrations/update_admins.rb +23 -0
- data/generators/captain_oveur_features/USAGE +1 -0
- data/generators/captain_oveur_features/captain_oveur_features_generator.rb +16 -0
- data/generators/captain_oveur_features/templates/features/administration.feature +82 -0
- data/generators/captain_oveur_features/templates/features/step_definitions/administration_steps.rb +49 -0
- data/generators/captain_oveur_features/templates/features/support/paths.rb +42 -0
- data/lib/captain_oveur.rb +3 -0
- data/lib/captain_oveur/authentication.rb +27 -0
- data/lib/captain_oveur/routes.rb +20 -0
- data/lib/captain_oveur/user.rb +21 -0
- data/test/captain_oveur_test.rb +7 -0
- data/test/factories/admins.rb +4 -0
- data/test/test_helper.rb +10 -0
- metadata +165 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/CHANGELOG.textile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Disruptive Ventures, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
CHANGELOG.textile
|
2
|
+
LICENSE
|
3
|
+
Manifest
|
4
|
+
README
|
5
|
+
README.textile
|
6
|
+
Rakefile
|
7
|
+
VERSION
|
8
|
+
app/controllers/admin/users_controller.rb
|
9
|
+
app/views/admin/users/_form.erb
|
10
|
+
app/views/admin/users/edit.html.erb
|
11
|
+
app/views/admin/users/index.html.erb
|
12
|
+
app/views/admin/users/new.html.erb
|
13
|
+
app/views/admin/users/show.html.erb
|
14
|
+
generators/captain_oveur/README
|
15
|
+
generators/captain_oveur/USAGE
|
16
|
+
generators/captain_oveur/captain_oveur_generator.rb
|
17
|
+
generators/captain_oveur/lib/insert_commands.rb
|
18
|
+
generators/captain_oveur/lib/rake_commands.rb
|
19
|
+
generators/captain_oveur/templates/admins.rb
|
20
|
+
generators/captain_oveur/templates/migrations/update_admins.rb
|
21
|
+
generators/captain_oveur_features/USAGE
|
22
|
+
generators/captain_oveur_features/captain_oveur_features_generator.rb
|
23
|
+
generators/captain_oveur_features/templates/features/administration.feature
|
24
|
+
generators/captain_oveur_features/templates/features/step_definitions/administration_steps.rb
|
25
|
+
generators/captain_oveur_features/templates/features/support/paths.rb
|
26
|
+
lib/captain_oveur.rb
|
27
|
+
lib/captain_oveur/authentication.rb
|
28
|
+
lib/captain_oveur/routes.rb
|
29
|
+
lib/captain_oveur/user.rb
|
30
|
+
test/captain_oveur_test.rb
|
31
|
+
test/factories/admins.rb
|
32
|
+
test/test_helper.rb
|
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem-Based Admins for Clearance
|
2
|
+
|
3
|
+
Do you like movies about gladiators or Clearance-based authentication? If you do, you and Captain Oveur will become fast friends. Captain Oveur adds user-management tools and admin authentication to make flights of web development smoother.
|
4
|
+
|
5
|
+
Tested with Rails 2.3.5 and Clearance 0.8.8
|
6
|
+
|
7
|
+
Install it as a gem (after installing clearance, cucumber and clearance_features):
|
8
|
+
|
9
|
+
gem install captain_oveur
|
10
|
+
|
11
|
+
script/generate captain_oveur
|
12
|
+
|
13
|
+
for the cucumber features:
|
14
|
+
|
15
|
+
script/generate captain_oveur_features
|
16
|
+
|
17
|
+
NOTE
|
18
|
+
|
19
|
+
A lot of this gem looks exactly like clearance. Firstly, I am an unabashed fan of thoughtbot and clearance. Given the problem domain, I also think it was the best way to handle a lot of issues, but I am open to criticism and/or suggestions.
|
20
|
+
|
21
|
+
(c)2009-2010 Disruptive Ventures, Inc. See LICENSE for details.
|
data/README.textile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*Gem-Based Admins for Clearance*
|
2
|
+
|
3
|
+
Do you like movies about gladiators or "Clearance-based":http://github.com/thoughtbot/clearance authentication? If you do, you and Captain Oveur will become fast friends. Captain Oveur adds user-management tools and admin authentication to make flights of web development smoother.
|
4
|
+
|
5
|
+
Tested with Rails 2.3.5 and Clearance 0.8.8
|
6
|
+
|
7
|
+
Install it as a gem (after installing clearance, cucumber and clearance_features):
|
8
|
+
|
9
|
+
gem install captain_oveur
|
10
|
+
|
11
|
+
script/generate captain_oveur
|
12
|
+
|
13
|
+
for the cucumber features:
|
14
|
+
|
15
|
+
script/generate captain_oveur_features
|
16
|
+
|
17
|
+
NOTE
|
18
|
+
|
19
|
+
A lot of this gem looks exactly like "clearance":http://github.com/thoughtbot/clearance. Firstly, I am an unabashed fan of "thoughtbot":http://thoughtbot.com and clearance. Given the problem domain, I also think it was the best way to handle a lot of issues, but I am open to criticism and/or suggestions.
|
20
|
+
|
21
|
+
(c) 2009-2010 Disruptive Ventures, Inc. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('captain_oveur', '0.8.10') do |p|
|
6
|
+
p.description = "Admins for Clearance"
|
7
|
+
p.url = "http://disruptive.github.com/captain_oveur"
|
8
|
+
p.author = "Jerry Richardson, Zachery Maloney"
|
9
|
+
p.email = "jerry@disruptiveventures.com"
|
10
|
+
p.ignore_pattern = []
|
11
|
+
p.runtime_dependencies = ["clearance >=0.8.8","formtastic >=0.9.10"]
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.8.10
|
@@ -0,0 +1,106 @@
|
|
1
|
+
class Admin::UsersController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :admin_only
|
4
|
+
|
5
|
+
def index
|
6
|
+
@users = User.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@user = User.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@user = User.new(params[:user])
|
15
|
+
respond_to do |format|
|
16
|
+
if @user.save
|
17
|
+
flash[:msg] = "User created."
|
18
|
+
format.html do
|
19
|
+
redirect_to admin_user_path(@user)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
format.html do
|
23
|
+
render :action => :new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
@user = User.find(params[:id])
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
@user = User.find(params[:id])
|
35
|
+
if params[:user_admin] and params[:user_admin] == 1
|
36
|
+
@user.activate_admin!
|
37
|
+
else
|
38
|
+
@user.deactivate_admin!
|
39
|
+
end
|
40
|
+
respond_to do |format|
|
41
|
+
if @user.update_attributes(params[:user])
|
42
|
+
flash[:msg] = "User #{@user.email} was successfully updated."
|
43
|
+
format.html do
|
44
|
+
redirect_to admin_users_path
|
45
|
+
end
|
46
|
+
else
|
47
|
+
format.html do
|
48
|
+
render :action => :edit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def activate_admin
|
55
|
+
@user = User.find(params[:id])
|
56
|
+
respond_to do |format|
|
57
|
+
if @user.activate_admin!
|
58
|
+
flash[:msg] = "User #{@user.email} was promoted to Admin."
|
59
|
+
format.html do
|
60
|
+
redirect_to edit_admin_user_path(@user)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
format.html do
|
64
|
+
flash[:msg] = "User #{@user.email} could not be promoted to Admin."
|
65
|
+
render :action => :edit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def deactivate_admin
|
72
|
+
@user = User.find(params[:id])
|
73
|
+
respond_to do |format|
|
74
|
+
if @user.deactivate_admin!
|
75
|
+
flash[:msg] = "User #{@user.email} was demoted from Admin."
|
76
|
+
format.html do
|
77
|
+
redirect_to edit_admin_user_path(@user)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
format.html do
|
81
|
+
flash[:msg] = "User #{@user.email} could not be demoted from Admin."
|
82
|
+
render :action => :edit
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def show
|
89
|
+
@user = User.find(params[:id])
|
90
|
+
end
|
91
|
+
|
92
|
+
def destroy
|
93
|
+
@user = User.find(params[:id])
|
94
|
+
respond_to do |format|
|
95
|
+
if current_user.id != @user.id && @user.destroy
|
96
|
+
flash[:msg] = "User deleted."
|
97
|
+
else
|
98
|
+
flash[:msg] = "User could not be deleted."
|
99
|
+
end
|
100
|
+
format.html do
|
101
|
+
redirect_to admin_users_path
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% semantic_form_for [:admin, @user] do |form| %>
|
2
|
+
<% form.inputs do %>
|
3
|
+
<%= form.input :email, :label => 'Email' %>
|
4
|
+
<%= form.input :password, :label => 'Password' %>
|
5
|
+
<%= form.input :password_confirmation, :label => 'Confirm Password' %>
|
6
|
+
<%= form.input :admin, :label => 'Admin' %>
|
7
|
+
<%= form.input :email_confirmed, :label => 'Email confirmed' %>
|
8
|
+
<% end %>
|
9
|
+
<% form.buttons do %>
|
10
|
+
<%= form.commit_button %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<h1>Edit User <%= @user.id %></h1>
|
2
|
+
<%= render(:partial => "form") %>
|
3
|
+
|
4
|
+
<%= button_to "Activate Admin", { :action => "activate_admin", :id => @user.id }, { :confirm => "Are you sure?", :id => "activate_admin_user_#{@user.id}" } %>
|
5
|
+
|
6
|
+
<%= button_to "Deactivate Admin", { :action => "deactivate_admin", :id => @user.id }, { :confirm => "Are you sure?", :id => "deactivate_admin_user_#{@user.id}" } %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1>User Management Home Page</h1>
|
2
|
+
|
3
|
+
<ul>
|
4
|
+
<% @users.each do |u| %>
|
5
|
+
<li class='users'><%= link_to u.email, admin_user_path(u), :id => "show_user_#{u.id}" %><br>
|
6
|
+
<%= link_to "Edit", edit_admin_user_path(u), :id => "edit_user_#{u.id}" %>
|
7
|
+
<%= button_to "Delete", { :action => "destroy", :id => u.id }, :confirm => "Are you sure?", :method => :delete, :id => "delete_user_#{u.id}" %>
|
8
|
+
</li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
|
12
|
+
<p><%= link_to "Add a new user", new_admin_user_path %></p>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{captain_oveur}
|
5
|
+
s.version = "0.8.10"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jerry Richardson, Zachery Maloney"]
|
9
|
+
s.cert_chain = ["/users/jerry/.ssh/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-07-05}
|
11
|
+
s.description = %q{Admins for Clearance}
|
12
|
+
s.email = %q{jerry@disruptiveventures.com}
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG.textile", "LICENSE", "README", "README.textile", "lib/captain_oveur.rb", "lib/captain_oveur/authentication.rb", "lib/captain_oveur/routes.rb", "lib/captain_oveur/user.rb"]
|
14
|
+
s.files = ["CHANGELOG.textile", "LICENSE", "Manifest", "README", "README.textile", "Rakefile", "VERSION", "app/controllers/admin/users_controller.rb", "app/views/admin/users/_form.erb", "app/views/admin/users/edit.html.erb", "app/views/admin/users/index.html.erb", "app/views/admin/users/new.html.erb", "app/views/admin/users/show.html.erb", "generators/captain_oveur/README", "generators/captain_oveur/USAGE", "generators/captain_oveur/captain_oveur_generator.rb", "generators/captain_oveur/lib/insert_commands.rb", "generators/captain_oveur/lib/rake_commands.rb", "generators/captain_oveur/templates/admins.rb", "generators/captain_oveur/templates/migrations/update_admins.rb", "generators/captain_oveur_features/USAGE", "generators/captain_oveur_features/captain_oveur_features_generator.rb", "generators/captain_oveur_features/templates/features/administration.feature", "generators/captain_oveur_features/templates/features/step_definitions/administration_steps.rb", "generators/captain_oveur_features/templates/features/support/paths.rb", "lib/captain_oveur.rb", "lib/captain_oveur/authentication.rb", "lib/captain_oveur/routes.rb", "lib/captain_oveur/user.rb", "test/captain_oveur_test.rb", "test/factories/admins.rb", "test/test_helper.rb", "captain_oveur.gemspec"]
|
15
|
+
s.homepage = %q{http://disruptive.github.com/captain_oveur}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Captain_oveur", "--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{captain_oveur}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/users/jerry/.ssh/gem-private_key.pem}
|
21
|
+
s.summary = %q{Admins for Clearance}
|
22
|
+
s.test_files = ["test/captain_oveur_test.rb", "test/test_helper.rb"]
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 3
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_runtime_dependency(%q<clearance>, [">= 0.8.8"])
|
30
|
+
s.add_runtime_dependency(%q<formtastic>, [">= 0.9.10"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<clearance>, [">= 0.8.8"])
|
33
|
+
s.add_dependency(%q<formtastic>, [">= 0.9.10"])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<clearance>, [">= 0.8.8"])
|
37
|
+
s.add_dependency(%q<formtastic>, [">= 0.9.10"])
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
script/generate captain_oveur
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
|
3
|
+
|
4
|
+
class CaptainOveurGenerator < Rails::Generator::Base
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
# m.directory File.join("config", "initializers")
|
9
|
+
# m.file "captain_oveur.rb", "config/initializers/captain_oveur.rb"
|
10
|
+
|
11
|
+
m.insert_into "app/controllers/application_controller.rb",
|
12
|
+
"include CaptainOveur::Authentication"
|
13
|
+
|
14
|
+
|
15
|
+
m.insert_into "config/routes.rb",
|
16
|
+
"CaptainOveur::Routes.draw(map)"
|
17
|
+
|
18
|
+
m.directory File.join("test", "factories")
|
19
|
+
m.file "admins.rb", "test/factories/clearance_admins.rb"
|
20
|
+
|
21
|
+
m.migration_template "migrations/update_admins.rb",
|
22
|
+
'db/migrate',
|
23
|
+
:migration_file_name => "captain_oveur_#{migration_target_name}"
|
24
|
+
|
25
|
+
m.readme "../README"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def schema_version_constant
|
30
|
+
# if upgrading_clearance_again?
|
31
|
+
# "To#{schema_version.gsub('_', '')}"
|
32
|
+
# end
|
33
|
+
""
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def migration_target_name
|
39
|
+
# if upgrading_captain_oveur_again?
|
40
|
+
# "update_admins_to_#{schema_version}"
|
41
|
+
# else
|
42
|
+
# 'update_admins'
|
43
|
+
# end
|
44
|
+
"update_admins"
|
45
|
+
end
|
46
|
+
|
47
|
+
def schema_version
|
48
|
+
IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_')
|
49
|
+
end
|
50
|
+
|
51
|
+
# def upgrading_clearance_again?
|
52
|
+
# ActiveRecord::Base.connection.table_exists?(:users)
|
53
|
+
# end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
def insert_into(file, line)
|
11
|
+
logger.insert "#{line} into #{file}"
|
12
|
+
unless options[:pretend] || file_contains?(file, line)
|
13
|
+
gsub_file file, /^(class|module|.*Routes).*$/ do |match|
|
14
|
+
"#{match}\n #{line}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
21
|
+
def insert_into(file, line)
|
22
|
+
logger.remove "#{line} from #{file}"
|
23
|
+
unless options[:pretend]
|
24
|
+
gsub_file file, "\n #{line}", ''
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Rails::Generator::Commands::List.class_eval do
|
30
|
+
def insert_into(file, line)
|
31
|
+
logger.insert "#{line} into #{file}"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def rake_db_migrate
|
3
|
+
logger.rake "db:migrate"
|
4
|
+
unless system("rake db:migrate")
|
5
|
+
logger.rake "db:migrate failed. Rolling back"
|
6
|
+
command(:destroy).invoke!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
12
|
+
def rake_db_migrate
|
13
|
+
logger.rake "db:rollback"
|
14
|
+
system "rake db:rollback"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Rails::Generator::Commands::List.class_eval do
|
19
|
+
def rake_db_migrate
|
20
|
+
logger.rake "db:migrate"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CaptainOveurUpdateAdmins<%= schema_version_constant %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
<%
|
4
|
+
existing_columns = ActiveRecord::Base.connection.columns(:users).collect { |each| each.name }
|
5
|
+
columns = [
|
6
|
+
[:admin, 't.boolean :admin, :default => false, :null => false']
|
7
|
+
].delete_if {|c| existing_columns.include?(c.first.to_s)}
|
8
|
+
-%>
|
9
|
+
change_table(:users) do |t|
|
10
|
+
<% columns.each do |c| -%>
|
11
|
+
<%= c.last %>
|
12
|
+
<% end -%>
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
change_table(:users) do |t|
|
18
|
+
<% unless columns.empty? -%>
|
19
|
+
t.remove <%= columns.collect { |each| ":#{each.first}" }.join(',') %>
|
20
|
+
<% end -%>
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
script/generate captain_oveur_features
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CaptainOveurFeaturesGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
m.directory File.join("features", "step_definitions")
|
6
|
+
m.directory File.join("features", "support")
|
7
|
+
|
8
|
+
["features/step_definitions/administration_steps.rb",
|
9
|
+
"features/support/paths.rb",
|
10
|
+
"features/administration.feature"].each do |file|
|
11
|
+
m.file file, file
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
Feature: Administrate Site Users
|
2
|
+
In order to manage the site
|
3
|
+
Administrators should be able to
|
4
|
+
administrate site users
|
5
|
+
|
6
|
+
Scenario: Administrator should be able to manage users
|
7
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
8
|
+
And there are 5 users
|
9
|
+
And I go to the user administration home page
|
10
|
+
Then I should see "User Management Home Page"
|
11
|
+
And I should see 6 listings of users
|
12
|
+
And I should see "user1@jerryr.dev"
|
13
|
+
|
14
|
+
Scenario: Non-Admin User should not be able to manage users
|
15
|
+
Given I have signed in with "jerry@jerryr.dev/password"
|
16
|
+
When I go to the user administration home page
|
17
|
+
Then I should see "Please Login as an administrator to Access that Feature."
|
18
|
+
|
19
|
+
Scenario: Visitors should not be able to manage users
|
20
|
+
When I go to the user administration home page
|
21
|
+
Then I should see "Please Login as an administrator to Access that Feature."
|
22
|
+
|
23
|
+
Scenario: Administrator should be able to add a new User
|
24
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
25
|
+
And I go to the user administration home page
|
26
|
+
And I follow "Add a new user"
|
27
|
+
And I fill in "Email" with "user@jerryr.dev"
|
28
|
+
And I fill in "Password" with "password"
|
29
|
+
And I fill in "Confirm password" with "password"
|
30
|
+
And I press "Create User"
|
31
|
+
Then I should see "User created."
|
32
|
+
And I should see "user@jerryr.dev"
|
33
|
+
|
34
|
+
Scenario: Administrator should be able to delete a User
|
35
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
36
|
+
And there are 5 users
|
37
|
+
And an id-specific user signed up "zachery@jerryr.dev/password/90210"
|
38
|
+
And go to the user administration home page
|
39
|
+
And I press "delete_user_90210"
|
40
|
+
Then I should see "User deleted."
|
41
|
+
And I should not see "zachery@jerryr.dev"
|
42
|
+
And I should see 6 listings of users
|
43
|
+
# And show me the page
|
44
|
+
|
45
|
+
Scenario: Administrator should be not able to delete his own account
|
46
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
47
|
+
And I go to the user administration home page
|
48
|
+
And I press "Delete"
|
49
|
+
Then I should see "User could not be deleted."
|
50
|
+
And I should see "ken@tacostorm.dev"
|
51
|
+
|
52
|
+
Scenario: Administrator should be able to edit a User
|
53
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
54
|
+
And an id-specific user signed up "zachery@jerryr.dev/password/90210"
|
55
|
+
And go to the user administration home page
|
56
|
+
And I follow "edit_user_90210"
|
57
|
+
And I fill in "user_email" with "zachery2@jerryr.dev"
|
58
|
+
And I press "Update User"
|
59
|
+
Then I should see "User zachery2@jerryr.dev was successfully updated."
|
60
|
+
|
61
|
+
Scenario: Administrator should be able to view a User
|
62
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
63
|
+
And an id-specific user signed up "zachery@jerryr.dev/password/90210"
|
64
|
+
And go to the user administration home page
|
65
|
+
And I follow "show_user_90210"
|
66
|
+
Then I should see "zachery@jerryr.dev"
|
67
|
+
|
68
|
+
Scenario: Administrator can identify a User as a Admin
|
69
|
+
Given I am an admin signed in as "ken@tacostorm.dev/password"
|
70
|
+
And an id-specific user signed up "zachery@disruptive.dev/password/90211"
|
71
|
+
And go to the user administration home page
|
72
|
+
And I follow "edit_user_90211"
|
73
|
+
And I press "Activate Admin"
|
74
|
+
Then the "admin" checkbox should be checked
|
75
|
+
|
76
|
+
Scenario: Administrator can remove a User from Admin status
|
77
|
+
Given an id-specific admin user signed up and confirmed as "zachery@disruptive.dev/password/90211"
|
78
|
+
And I am an admin signed in as "ken@tacostorm.dev/password"
|
79
|
+
And go to the user administration home page
|
80
|
+
And I follow "edit_user_90211"
|
81
|
+
And I press "Deactivate Admin"
|
82
|
+
Then the "admin" checkbox should not be checked
|
data/generators/captain_oveur_features/templates/features/step_definitions/administration_steps.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Given /^an id-specific user signed up "(.*)\/(.*)\/(.*)"$/ do |email, password, id|
|
2
|
+
user = Factory :email_confirmed_user,
|
3
|
+
:id => id,
|
4
|
+
:email => email,
|
5
|
+
:password => password,
|
6
|
+
:password_confirmation => password
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /^a user signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
|
10
|
+
Given %{I am signed up and confirmed as a specific user "#{email}/#{password}"}
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^an id-specific admin user signed up and confirmed as "(.*)\/(.*)\/(.*)"$/ do |email, password, id|
|
14
|
+
user = Factory :admin_user,
|
15
|
+
:id => id,
|
16
|
+
:email => email,
|
17
|
+
:password => password,
|
18
|
+
:password_confirmation => password
|
19
|
+
end
|
20
|
+
|
21
|
+
Given /^I am an admin signed up as "(.*)\/(.*)"$/ do |email, password|
|
22
|
+
user = Factory :admin_user,
|
23
|
+
:email => email,
|
24
|
+
:password => password,
|
25
|
+
:password_confirmation => password
|
26
|
+
end
|
27
|
+
|
28
|
+
Given /^an admin user signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
|
29
|
+
Given %{I am an admin signed up as "#{email}/#{password}"}
|
30
|
+
end
|
31
|
+
|
32
|
+
Given /^I am an admin signed in as "(.*)\/(.*)"$/ do |email, password|
|
33
|
+
Given %{I am an admin signed up as "#{email}/#{password}"}
|
34
|
+
And %{I sign in as "#{email}/#{password}"}
|
35
|
+
end
|
36
|
+
|
37
|
+
Given /^there are (\d+) users$/ do |n|
|
38
|
+
n.to_i.times{|i| Given %{I am signed up and confirmed as "user#{i}@jerryr.dev/password"} }
|
39
|
+
end
|
40
|
+
|
41
|
+
Then /^I should see (.*) listings of (.*)$/ do |count, list_class|
|
42
|
+
assert_select "li[class=#{list_class}]", :count => count.to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^I follow the "([^\"]*)" link for "([^\"]*)"$/ do |link, cell_value|
|
46
|
+
within "//*[.//text()='#{cell_value}' and .//a[text()='#{link}']]" do |scope|
|
47
|
+
scope.click_link link
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
# Maps a name to a path. Used by the
|
3
|
+
#
|
4
|
+
# When /^I go to (.+)$/ do |page_name|
|
5
|
+
#
|
6
|
+
# step definition in web_steps.rb
|
7
|
+
#
|
8
|
+
def path_to(page_name)
|
9
|
+
case page_name
|
10
|
+
|
11
|
+
when /the home\s?page/
|
12
|
+
'/'
|
13
|
+
when /the sign up page/i
|
14
|
+
sign_up_path
|
15
|
+
when /the sign in page/i
|
16
|
+
sign_in_path
|
17
|
+
when /the password reset request page/i
|
18
|
+
new_password_path
|
19
|
+
when /the administration home page/i
|
20
|
+
admin_panel_path
|
21
|
+
when /the user administration home page/i
|
22
|
+
admin_users_path
|
23
|
+
# Add more mappings here.
|
24
|
+
# Here is an example that pulls values out of the Regexp:
|
25
|
+
#
|
26
|
+
# when /^(.*)'s profile page$/i
|
27
|
+
# user_profile_path(User.find_by_login($1))
|
28
|
+
|
29
|
+
else
|
30
|
+
begin
|
31
|
+
page_name =~ /the (.*) page/
|
32
|
+
path_components = $1.split(/\s+/)
|
33
|
+
self.send(path_components.push('path').join('_').to_sym)
|
34
|
+
rescue Object => e
|
35
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
36
|
+
"Now, go and add a mapping in #{__FILE__}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
World(NavigationHelpers)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CaptainOveur
|
2
|
+
module Authentication
|
3
|
+
|
4
|
+
def self.included(controller)
|
5
|
+
controller.send(:include, InstanceMethods)
|
6
|
+
controller.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def self.extended(controller)
|
11
|
+
controller.helper_method :admin?
|
12
|
+
controller.hide_action :admin?, :admin_only
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def admin?
|
18
|
+
current_user && current_user.admin
|
19
|
+
end
|
20
|
+
|
21
|
+
def admin_only
|
22
|
+
deny_access("Please Login as an administrator to Access that Feature.") unless admin?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CaptainOveur
|
2
|
+
class Routes
|
3
|
+
|
4
|
+
# In your application's config/routes.rb, draw CaptainOveur's
|
5
|
+
# Routes right after Clearance's routes:
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# map.resources :posts
|
9
|
+
# Clearance::Routes.draw(map)
|
10
|
+
# CaptainOveur::Routes.draw(map)
|
11
|
+
def self.draw(map)
|
12
|
+
|
13
|
+
map.namespace :admin do |admin|
|
14
|
+
admin.resources :users
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module CaptainOveur
|
4
|
+
module User
|
5
|
+
|
6
|
+
def self.included(model)
|
7
|
+
model.send(:include, InstanceMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def activate_admin!
|
12
|
+
return self.update_attribute("admin", true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def deactivate_admin!
|
16
|
+
return self.update_attribute("admin", false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: captain_oveur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 43
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 10
|
10
|
+
version: 0.8.10
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jerry Richardson, Zachery Maloney
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDRjCCAi6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBJMQ4wDAYDVQQDDAVqZXJy
|
20
|
+
eTEiMCAGCgmSJomT8ixkARkWEmRpc3J1cHRpdmV2ZW50dXJlczETMBEGCgmSJomT
|
21
|
+
8ixkARkWA2NvbTAeFw0xMDA3MDMwMzIxMThaFw0xMTA3MDMwMzIxMThaMEkxDjAM
|
22
|
+
BgNVBAMMBWplcnJ5MSIwIAYKCZImiZPyLGQBGRYSZGlzcnVwdGl2ZXZlbnR1cmVz
|
23
|
+
MRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
24
|
+
CgKCAQEApGoL2172SQsohHPmC5uWskpMJxdEFNYsLkh02pEpkL3xtdYRKnYeYXJ6
|
25
|
+
6OzAwc1gxHSDvlKMNOzs8cAv48pjrEnEgiwkQ2RV1LjCgxKODs3xJr/q7m/96A8P
|
26
|
+
v32Nk783IxjPUQjd6dkeeSoyH8b1fZT0qDV+vthzBLvmNNKHCboZrmlw9NKVhdDp
|
27
|
+
Hrvik+hseFTyRBFBnYP4H8zWY3jwBW/dq1dEWEAH55Jjb86quTNsp4UEt7kQ86nH
|
28
|
+
fces3O8CDTbGAsb5oHB4E/JjPOG/sFMao0QAH5EVdx+m1vhrrTKmxE8EMEVetSV1
|
29
|
+
W5KDjklkZH7lQMWoo1Ktr1WiGLiMcQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1Ud
|
30
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUQYUunQvey42EFLspsNHGUQbxLVAwDQYJKoZIhvcN
|
31
|
+
AQEFBQADggEBAEJICcZD0dNBobtNyRZ8ygj1WFMycpVcjUm2DKNWC5PZZG4GPX6B
|
32
|
+
ird6DHAnhgZ9aEHuBK0UMQboA0SXHk69LseZuTIbbIhorTPpF1vfnl+D98C/Y5ou
|
33
|
+
PTKGqqNhcAmv3v+r9EpRayQsP7HSbrKMtgPlEkqVQY2St7VQu3qKciFV1qJXJYPd
|
34
|
+
xbwowofGcVamEdKGpyX54opfSrmSZXfRUPYeJ25/d6dS+G3tvvnTYa9QgYWS2gJE
|
35
|
+
/eC3ArwUSNMnuP5i+2xXPsu7c82zIauU01bv3ywlC5C8KwmX8UjcIwsHtPnaGesF
|
36
|
+
MULeaT9wztQIvRS+mr/QYLKBA08UERlaUm4=
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2010-07-05 00:00:00 -04:00
|
40
|
+
default_executable:
|
41
|
+
dependencies:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: clearance
|
44
|
+
prerelease: false
|
45
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 47
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
- 8
|
54
|
+
- 8
|
55
|
+
version: 0.8.8
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: *id001
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: formtastic
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 47
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
- 9
|
70
|
+
- 10
|
71
|
+
version: 0.9.10
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: *id002
|
74
|
+
description: Admins for Clearance
|
75
|
+
email: jerry@disruptiveventures.com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files:
|
81
|
+
- CHANGELOG.textile
|
82
|
+
- LICENSE
|
83
|
+
- README
|
84
|
+
- README.textile
|
85
|
+
- lib/captain_oveur.rb
|
86
|
+
- lib/captain_oveur/authentication.rb
|
87
|
+
- lib/captain_oveur/routes.rb
|
88
|
+
- lib/captain_oveur/user.rb
|
89
|
+
files:
|
90
|
+
- CHANGELOG.textile
|
91
|
+
- LICENSE
|
92
|
+
- Manifest
|
93
|
+
- README
|
94
|
+
- README.textile
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- app/controllers/admin/users_controller.rb
|
98
|
+
- app/views/admin/users/_form.erb
|
99
|
+
- app/views/admin/users/edit.html.erb
|
100
|
+
- app/views/admin/users/index.html.erb
|
101
|
+
- app/views/admin/users/new.html.erb
|
102
|
+
- app/views/admin/users/show.html.erb
|
103
|
+
- generators/captain_oveur/README
|
104
|
+
- generators/captain_oveur/USAGE
|
105
|
+
- generators/captain_oveur/captain_oveur_generator.rb
|
106
|
+
- generators/captain_oveur/lib/insert_commands.rb
|
107
|
+
- generators/captain_oveur/lib/rake_commands.rb
|
108
|
+
- generators/captain_oveur/templates/admins.rb
|
109
|
+
- generators/captain_oveur/templates/migrations/update_admins.rb
|
110
|
+
- generators/captain_oveur_features/USAGE
|
111
|
+
- generators/captain_oveur_features/captain_oveur_features_generator.rb
|
112
|
+
- generators/captain_oveur_features/templates/features/administration.feature
|
113
|
+
- generators/captain_oveur_features/templates/features/step_definitions/administration_steps.rb
|
114
|
+
- generators/captain_oveur_features/templates/features/support/paths.rb
|
115
|
+
- lib/captain_oveur.rb
|
116
|
+
- lib/captain_oveur/authentication.rb
|
117
|
+
- lib/captain_oveur/routes.rb
|
118
|
+
- lib/captain_oveur/user.rb
|
119
|
+
- test/captain_oveur_test.rb
|
120
|
+
- test/factories/admins.rb
|
121
|
+
- test/test_helper.rb
|
122
|
+
- captain_oveur.gemspec
|
123
|
+
has_rdoc: true
|
124
|
+
homepage: http://disruptive.github.com/captain_oveur
|
125
|
+
licenses: []
|
126
|
+
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options:
|
129
|
+
- --line-numbers
|
130
|
+
- --inline-source
|
131
|
+
- --title
|
132
|
+
- Captain_oveur
|
133
|
+
- --main
|
134
|
+
- README
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 11
|
152
|
+
segments:
|
153
|
+
- 1
|
154
|
+
- 2
|
155
|
+
version: "1.2"
|
156
|
+
requirements: []
|
157
|
+
|
158
|
+
rubyforge_project: captain_oveur
|
159
|
+
rubygems_version: 1.3.7
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: Admins for Clearance
|
163
|
+
test_files:
|
164
|
+
- test/captain_oveur_test.rb
|
165
|
+
- test/test_helper.rb
|
metadata.gz.sig
ADDED
Binary file
|