lockdown 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +39 -0
- data/lib/lockdown/controller.rb +3 -3
- data/lib/lockdown/system.rb +1 -5
- data/lib/lockdown/version.rb +2 -2
- data/rails_generators/lockdown/USAGE +5 -0
- data/rails_generators/lockdown/lockdown_generator.rb +221 -0
- data/rails_generators/lockdown/templates/app/controllers/permissions_controller.rb +22 -0
- data/rails_generators/lockdown/templates/app/controllers/sessions_controller.rb +38 -0
- data/rails_generators/lockdown/templates/app/controllers/user_groups_controller.rb +113 -0
- data/rails_generators/lockdown/templates/app/controllers/users_controller.rb +124 -0
- data/rails_generators/lockdown/templates/app/helpers/permissions_helper.rb +13 -0
- data/rails_generators/lockdown/templates/app/helpers/user_groups_helper.rb +35 -0
- data/rails_generators/lockdown/templates/app/helpers/users_helper.rb +78 -0
- data/rails_generators/lockdown/templates/app/models/permission.rb +13 -0
- data/rails_generators/lockdown/templates/app/models/profile.rb +10 -0
- data/rails_generators/lockdown/templates/app/models/user.rb +72 -0
- data/rails_generators/lockdown/templates/app/models/user_group.rb +15 -0
- data/rails_generators/lockdown/templates/app/views/permissions/_data.html.erb +13 -0
- data/rails_generators/lockdown/templates/app/views/permissions/index.html.erb +16 -0
- data/rails_generators/lockdown/templates/app/views/permissions/show.html.erb +3 -0
- data/rails_generators/lockdown/templates/app/views/sessions/new.html.erb +12 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/_data.html.erb +44 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/_form.html.erb +11 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/edit.html.erb +6 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/index.html.erb +20 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/new.html.erb +5 -0
- data/rails_generators/lockdown/templates/app/views/user_groups/show.html.erb +6 -0
- data/rails_generators/lockdown/templates/app/views/users/_data.html.erb +62 -0
- data/rails_generators/lockdown/templates/app/views/users/_form.html.erb +18 -0
- data/rails_generators/lockdown/templates/app/views/users/_password.html.erb +5 -0
- data/rails_generators/lockdown/templates/app/views/users/edit.html.erb +6 -0
- data/rails_generators/lockdown/templates/app/views/users/index.html.erb +22 -0
- data/rails_generators/lockdown/templates/app/views/users/new.html.erb +5 -0
- data/rails_generators/lockdown/templates/app/views/users/show.html.erb +4 -0
- data/rails_generators/lockdown/templates/db/migrate/create_admin_user_and_user_group.rb +19 -0
- data/rails_generators/lockdown/templates/db/migrate/create_permissions.rb +19 -0
- data/rails_generators/lockdown/templates/db/migrate/create_profiles.rb +26 -0
- data/rails_generators/lockdown/templates/db/migrate/create_user_groups.rb +19 -0
- data/rails_generators/lockdown/templates/db/migrate/create_users.rb +17 -0
- data/rails_generators/lockdown_all/lockdown_all_generator.rb +0 -2
- data/test/test_generator_helper.rb +10 -1
- data/test/test_lockdown_generator.rb +11 -9
- data/website/generator.html +243 -0
- data/website/generator.txt +174 -0
- data/website/index.html +331 -0
- data/website/index.txt +62 -26
- data/website/model.jpg +0 -0
- metadata +42 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module UsersHelper
|
|
2
|
+
def profile_first_name_value
|
|
3
|
+
if @action_name == "show"
|
|
4
|
+
h @profile.first_name
|
|
5
|
+
else
|
|
6
|
+
text_field_tag "profile[first_name]", @profile.first_name
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def profile_last_name_value
|
|
11
|
+
if @action_name == "show"
|
|
12
|
+
h @profile.last_name
|
|
13
|
+
else
|
|
14
|
+
text_field_tag "profile[last_name]", @profile.last_name
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def profile_email_value
|
|
19
|
+
if @action_name == "show"
|
|
20
|
+
h @profile.email
|
|
21
|
+
else
|
|
22
|
+
text_field_tag "profile[email]", @profile.email
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def user_login_value
|
|
27
|
+
if @action_name == "show"
|
|
28
|
+
h @user.login
|
|
29
|
+
else
|
|
30
|
+
text_field_tag "user[login]", @user.login
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def user_password_value
|
|
35
|
+
if @action_name == "show"
|
|
36
|
+
h "Hidden for security..."
|
|
37
|
+
else
|
|
38
|
+
%{<input autocomplete="off" type="password" name="user[password]" id="user_password"/>}
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def user_password_confirmation_value
|
|
43
|
+
if @action_name == "show"
|
|
44
|
+
h "Hidden for security..."
|
|
45
|
+
else
|
|
46
|
+
%{<input autocomplete="off" type="password" name="user[password_confirmation]" id="user_password_confirmation"/>}
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def user_user_groups_value
|
|
51
|
+
if @action_name == "show"
|
|
52
|
+
@user.user_groups.collect{|ug| ug.name + "<br/>"}
|
|
53
|
+
else
|
|
54
|
+
rvalue = %{<ul id="all_user_groups" class="checklist">}
|
|
55
|
+
#
|
|
56
|
+
# Restrict user group list to the list of the current user.
|
|
57
|
+
# This prevents a user from creating someone with more access than
|
|
58
|
+
# him/herself.
|
|
59
|
+
#
|
|
60
|
+
@user_groups_for_user.each_with_index do |ug,i|
|
|
61
|
+
bg = ( i % 2 == 0 ) ? "even" : "odd"
|
|
62
|
+
input_id = "ug_#{ug.id}"
|
|
63
|
+
checked = (@user.user_group_ids.include?(ug.id) ? "checked" : "")
|
|
64
|
+
bg << "_" << checked if checked.length > 0
|
|
65
|
+
rvalue << <<-HTML
|
|
66
|
+
<li class="#{bg}">
|
|
67
|
+
<label id="lbl_#{input_id}" for="#{input_id}" onclick="do_highlight('#{input_id}')">
|
|
68
|
+
<input id="#{input_id}" name="#{input_id}" type="checkbox" #{checked}/> #{ug.name}
|
|
69
|
+
</label>
|
|
70
|
+
</li>
|
|
71
|
+
HTML
|
|
72
|
+
end
|
|
73
|
+
rvalue << "</ul>"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Permission < ActiveRecord::Base
|
|
2
|
+
has_and_belongs_to_many :user_groups
|
|
3
|
+
|
|
4
|
+
def all_users
|
|
5
|
+
User.find_by_sql <<-SQL
|
|
6
|
+
select users.*
|
|
7
|
+
from users, user_groups_users, permissions_user_groups
|
|
8
|
+
where users.id = user_groups_users.user_id
|
|
9
|
+
and user_groups_users.user_group_id = permissions_user_groups.user_group_id
|
|
10
|
+
and permissions_user_groups.permission_id = #{self.id}
|
|
11
|
+
SQL
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class Profile < ActiveRecord::Base
|
|
2
|
+
SYSTEM = 1
|
|
3
|
+
|
|
4
|
+
validates_presence_of :email, :first_name, :last_name
|
|
5
|
+
|
|
6
|
+
validates_length_of :email, :within => 5..100
|
|
7
|
+
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
|
8
|
+
|
|
9
|
+
validates_uniqueness_of :email, :case_sensitive => false
|
|
10
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'digest/sha1'
|
|
2
|
+
class User < ActiveRecord::Base
|
|
3
|
+
has_and_belongs_to_many :user_groups
|
|
4
|
+
belongs_to :profile
|
|
5
|
+
|
|
6
|
+
# Virtual attributes
|
|
7
|
+
attr_accessor :password
|
|
8
|
+
|
|
9
|
+
validates_presence_of :login
|
|
10
|
+
validates_presence_of :password, :if => :password_required?
|
|
11
|
+
validates_presence_of :password_confirmation, :if => :password_required?
|
|
12
|
+
validates_length_of :password, :within => 4..40, :if => :password_required?
|
|
13
|
+
validates_confirmation_of :password, :if => :password_required?
|
|
14
|
+
validates_length_of :login, :within => 3..40
|
|
15
|
+
validates_uniqueness_of :login, :case_sensitive => false
|
|
16
|
+
|
|
17
|
+
validates_presence_of :profile
|
|
18
|
+
validates_associated :profile
|
|
19
|
+
|
|
20
|
+
before_save :prepare_for_save
|
|
21
|
+
|
|
22
|
+
attr_accessible :login, :password, :password_confirmation
|
|
23
|
+
|
|
24
|
+
# Authenticates a user by their login name and unencrypted password.
|
|
25
|
+
# Returns the user or nil.
|
|
26
|
+
def self.authenticate(login, password)
|
|
27
|
+
u = find :first, :conditions => ['login = ?', login] # need to get the salt
|
|
28
|
+
u && u.authenticated?(password) ? u : nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Encrypts some data with the salt.
|
|
32
|
+
def self.encrypt(password, salt)
|
|
33
|
+
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Encrypts the password with the user salt
|
|
37
|
+
def encrypt(password)
|
|
38
|
+
self.class.encrypt(password, salt)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def authenticated?(password)
|
|
42
|
+
crypted_password == encrypt(password)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def email
|
|
46
|
+
self.profile.email
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def full_name
|
|
50
|
+
self.profile.first_name + " " + self.profile.last_name
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
def prepare_for_save
|
|
56
|
+
encrypt_password
|
|
57
|
+
self.profile.save
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def encrypt_password
|
|
61
|
+
return if password.blank?
|
|
62
|
+
if new_record?
|
|
63
|
+
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--")
|
|
64
|
+
end
|
|
65
|
+
self.crypted_password = encrypt(password)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def password_required?
|
|
69
|
+
(crypted_password.blank? || !password.blank?)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class UserGroup < ActiveRecord::Base
|
|
2
|
+
has_and_belongs_to_many :permissions
|
|
3
|
+
has_and_belongs_to_many :users
|
|
4
|
+
|
|
5
|
+
validates_presence_of :name
|
|
6
|
+
|
|
7
|
+
def all_users
|
|
8
|
+
User.find_by_sql <<-SQL
|
|
9
|
+
select users.*
|
|
10
|
+
from users, user_groups_users
|
|
11
|
+
where users.id = user_groups_users.user_id
|
|
12
|
+
and user_groups_users.user_group_id = #{self.id}
|
|
13
|
+
SQL
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<%= flash[:notice] if flash[:notice] %>
|
|
2
|
+
<%= flash[:error] if flash[:error] %>
|
|
3
|
+
|
|
4
|
+
<% form_tag sessions_path do -%>
|
|
5
|
+
<p><label for="login">Login</label><br/>
|
|
6
|
+
<%= text_field_tag 'login' %></p>
|
|
7
|
+
|
|
8
|
+
<p><label for="password">Password</label><br/>
|
|
9
|
+
<%= password_field_tag 'password' %></p>
|
|
10
|
+
|
|
11
|
+
<p><%= submit_tag 'Log in' %></p>
|
|
12
|
+
<% end -%>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
take the style block out. this is duplicated in users/_data.html.erb
|
|
3
|
+
without this, the user group selection is just no good
|
|
4
|
+
-->
|
|
5
|
+
<style>
|
|
6
|
+
.checklist{
|
|
7
|
+
overflow: auto;
|
|
8
|
+
border: 1px solid #ccc;
|
|
9
|
+
list-style: none;
|
|
10
|
+
height: 300px;
|
|
11
|
+
text-align: left;
|
|
12
|
+
list-style: none;
|
|
13
|
+
margin-left: 12px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.checklist li{
|
|
17
|
+
padding-left: 6px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
li.even_checked,
|
|
21
|
+
li.even{
|
|
22
|
+
background: #DFDFDF;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
li.even_checked,
|
|
26
|
+
li.odd_checked{
|
|
27
|
+
color: red;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
30
|
+
|
|
31
|
+
<p>
|
|
32
|
+
<b>Name</b><br />
|
|
33
|
+
<%= user_group_name_value %>
|
|
34
|
+
</p>
|
|
35
|
+
<p>
|
|
36
|
+
<b>Permissions</b><br />
|
|
37
|
+
<%= user_group_permissions_value %>
|
|
38
|
+
</p>
|
|
39
|
+
<% if @action_name == "show" %>
|
|
40
|
+
<p>
|
|
41
|
+
<b>Users in user group:</b><br />
|
|
42
|
+
<%= user_group_users_value %>
|
|
43
|
+
</p>
|
|
44
|
+
<% end%>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<%
|
|
2
|
+
submit_label = "Update"
|
|
3
|
+
submit_label = "Create" if @user_group.new_record?
|
|
4
|
+
-%>
|
|
5
|
+
|
|
6
|
+
<%= error_messages_for :user_group %>
|
|
7
|
+
|
|
8
|
+
<% form_for(@user_group) do |f| %>
|
|
9
|
+
<%= render :partial => "data", :locals => {:f => f} %>
|
|
10
|
+
<p> <%= f.submit submit_label %> </p>
|
|
11
|
+
<% end %>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<h1>Listing User Groups</h1>
|
|
2
|
+
|
|
3
|
+
<table>
|
|
4
|
+
<tr>
|
|
5
|
+
<th>Name</th>
|
|
6
|
+
</tr>
|
|
7
|
+
|
|
8
|
+
<% for user_group in @user_groups %>
|
|
9
|
+
<tr>
|
|
10
|
+
<td><%=h user_group.name %></td>
|
|
11
|
+
<td><%= link_to 'Show', user_group %></td>
|
|
12
|
+
<td><%= link_to('Edit', edit_user_group_path(user_group)) unless Lockdown::System.has_user_group?(user_group) %></td>
|
|
13
|
+
<td><%= link_to('Destroy', user_group, :confirm => 'Are you sure?', :method => :delete) unless Lockdown::System.has_user_group?(user_group) %></td>
|
|
14
|
+
</tr>
|
|
15
|
+
<% end %>
|
|
16
|
+
</table>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
|
|
20
|
+
<%= link_to 'New User Group', new_user_group_path %>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
take the style block out. this is duplicated in users/_data.html.erb
|
|
3
|
+
without this, the user group selection is just no good
|
|
4
|
+
-->
|
|
5
|
+
<style>
|
|
6
|
+
.checklist{
|
|
7
|
+
overflow: auto;
|
|
8
|
+
border: 1px solid #ccc;
|
|
9
|
+
list-style: none;
|
|
10
|
+
height: 300px;
|
|
11
|
+
text-align: left;
|
|
12
|
+
list-style: none;
|
|
13
|
+
margin-left: 12px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.checklist li{
|
|
17
|
+
padding-left: 6px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
li.even_checked,
|
|
21
|
+
li.even{
|
|
22
|
+
background: #DFDFDF;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
li.even_checked,
|
|
26
|
+
li.odd_checked{
|
|
27
|
+
color: red;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
30
|
+
|
|
31
|
+
<p>
|
|
32
|
+
<b>First name</b><br />
|
|
33
|
+
<%= profile_first_name_value %>
|
|
34
|
+
</p>
|
|
35
|
+
<p>
|
|
36
|
+
<b>Last name</b><br />
|
|
37
|
+
<%= profile_last_name_value %>
|
|
38
|
+
</p>
|
|
39
|
+
<p>
|
|
40
|
+
<b>Email</b><br />
|
|
41
|
+
<%= profile_email_value %>
|
|
42
|
+
</p>
|
|
43
|
+
<p>
|
|
44
|
+
<b><span>L</span>ogin</b><br />
|
|
45
|
+
<%= user_login_value %>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<% unless @action_name == "show" -%>
|
|
49
|
+
<p id="password">
|
|
50
|
+
<% if @user.new_record? %>
|
|
51
|
+
<%= render :partial => "password" %>
|
|
52
|
+
<% else %>
|
|
53
|
+
<a href="#" onclick="change_password()">Change Password</a><br/>
|
|
54
|
+
<% end %>
|
|
55
|
+
</p>
|
|
56
|
+
<% end -%>
|
|
57
|
+
|
|
58
|
+
<p>
|
|
59
|
+
<b>User Groups</b><br />
|
|
60
|
+
<%= user_user_groups_value %>
|
|
61
|
+
</p>
|
|
62
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%
|
|
2
|
+
submit_label = "Update"
|
|
3
|
+
submit_label = "Create" if @user.new_record?
|
|
4
|
+
-%>
|
|
5
|
+
|
|
6
|
+
<script type="text/javascript">
|
|
7
|
+
function change_password()
|
|
8
|
+
{
|
|
9
|
+
new Ajax.Request("/users/change_password", {asynchronous: true, postBody: 'authenticity_token=<%= form_authenticity_token %>'});
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
<%= error_messages_for :profile %>
|
|
13
|
+
<%= error_messages_for :user %>
|
|
14
|
+
|
|
15
|
+
<% form_for(@user) do |f| %>
|
|
16
|
+
<%= render :partial => "data", :locals => {:f => f} %>
|
|
17
|
+
<p> <%= f.submit submit_label %> </p>
|
|
18
|
+
<% end %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h1>Listing Users</h1>
|
|
2
|
+
|
|
3
|
+
<table>
|
|
4
|
+
<tr>
|
|
5
|
+
<th>Login</th>
|
|
6
|
+
<th>Name</th>
|
|
7
|
+
</tr>
|
|
8
|
+
|
|
9
|
+
<% @users.each do |user| %>
|
|
10
|
+
<tr>
|
|
11
|
+
<td><%=h user.login %></td>
|
|
12
|
+
<td><%=h user.full_name %></td>
|
|
13
|
+
<td><%= link_to 'Show', user %></td>
|
|
14
|
+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
|
15
|
+
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
|
16
|
+
</tr>
|
|
17
|
+
<% end %>
|
|
18
|
+
</table>
|
|
19
|
+
|
|
20
|
+
<br />
|
|
21
|
+
|
|
22
|
+
<%= link_to 'New User', new_user_path %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class CreateAdminUserAndUserGroup < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
# TODO: Change the password
|
|
4
|
+
u = User.new( :password => "password",
|
|
5
|
+
:password_confirmation => "password",
|
|
6
|
+
:login => "admin")
|
|
7
|
+
|
|
8
|
+
u.profile = Profile.create(:first_name => "Administrator",
|
|
9
|
+
:last_name => "User",
|
|
10
|
+
:email => "administrator@a.com")
|
|
11
|
+
u.save
|
|
12
|
+
|
|
13
|
+
Lockdown::System.make_user_administrator(u)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.down
|
|
17
|
+
#Nothing to see here...
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class CreatePermissions < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :permissions do |t|
|
|
4
|
+
t.string :name
|
|
5
|
+
|
|
6
|
+
t.timestamps
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
create_table :permissions_user_groups, :id => false do |t|
|
|
10
|
+
t.integer :permission_id
|
|
11
|
+
t.integer :user_group_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.down
|
|
16
|
+
drop_table :permissions_user_groups
|
|
17
|
+
drop_table :permissions
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CreateProfiles < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :profiles do |t|
|
|
4
|
+
t.string :first_name
|
|
5
|
+
t.string :last_name
|
|
6
|
+
t.string :email
|
|
7
|
+
t.integer :updated_by
|
|
8
|
+
t.boolean :is_disabled
|
|
9
|
+
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# The System profile is used as the updated_by reference when records
|
|
14
|
+
# are created programatically and the responsible user cannot be determined
|
|
15
|
+
# or is simply not available.
|
|
16
|
+
# TODO: Change email address
|
|
17
|
+
Profile.create(:first_name => "System",
|
|
18
|
+
:last_name => "User",
|
|
19
|
+
:email => "system@a.com")
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.down
|
|
24
|
+
drop_table :profiles
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class CreateUserGroups < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :user_groups do |t|
|
|
4
|
+
t.string :name
|
|
5
|
+
|
|
6
|
+
t.timestamps
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
create_table :user_groups_users, :id => false do |t|
|
|
10
|
+
t.integer :user_group_id
|
|
11
|
+
t.integer :user_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.down
|
|
16
|
+
drop_table :user_groups_users
|
|
17
|
+
drop_table :user_groups
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :users do |t|
|
|
4
|
+
t.string :login
|
|
5
|
+
t.string :crypted_password
|
|
6
|
+
t.string :salt
|
|
7
|
+
t.integer :profile_id
|
|
8
|
+
t.integer :updated_by
|
|
9
|
+
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.down
|
|
15
|
+
drop_table :users
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
begin
|
|
2
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
end
|
|
2
6
|
require 'fileutils'
|
|
3
7
|
|
|
4
8
|
# Must set before requiring generator libs.
|
|
@@ -10,6 +14,11 @@ if defined?(APP_ROOT)
|
|
|
10
14
|
else
|
|
11
15
|
APP_ROOT = app_root
|
|
12
16
|
end
|
|
17
|
+
if defined?(RAILS_ROOT)
|
|
18
|
+
RAILS_ROOT.replace(app_root)
|
|
19
|
+
else
|
|
20
|
+
RAILS_ROOT = app_root
|
|
21
|
+
end
|
|
13
22
|
|
|
14
23
|
begin
|
|
15
24
|
require 'rubigen'
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
|
2
2
|
|
|
3
|
+
require 'rails_generator'
|
|
4
|
+
|
|
3
5
|
class TestLockdownGenerator < Test::Unit::TestCase
|
|
4
6
|
include RubiGen::GeneratorTestHelper
|
|
5
7
|
|
|
6
8
|
def setup
|
|
7
9
|
bare_setup
|
|
8
10
|
end
|
|
9
|
-
|
|
11
|
+
|
|
10
12
|
def teardown
|
|
11
13
|
bare_teardown
|
|
12
14
|
end
|
|
13
|
-
|
|
15
|
+
|
|
14
16
|
# Some generator-related assertions:
|
|
15
17
|
# assert_generated_file(name, &block) # block passed the file contents
|
|
16
18
|
# assert_directory_exists(name)
|
|
@@ -24,20 +26,20 @@ class TestLockdownGenerator < Test::Unit::TestCase
|
|
|
24
26
|
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
|
25
27
|
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
|
26
28
|
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
|
27
|
-
|
|
29
|
+
|
|
28
30
|
def test_generator_without_options
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
assert_generated_file
|
|
31
|
+
name = "myapp"
|
|
32
|
+
run_generator('lockdown', [name], sources)
|
|
33
|
+
assert_generated_file("some_file")
|
|
32
34
|
end
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
private
|
|
35
37
|
def sources
|
|
36
38
|
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
|
37
39
|
]
|
|
38
40
|
end
|
|
39
|
-
|
|
41
|
+
|
|
40
42
|
def generator_path
|
|
41
|
-
"
|
|
43
|
+
"rails_generators"
|
|
42
44
|
end
|
|
43
45
|
end
|