lockdown 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/History.txt +4 -0
- data/Manifest.txt +4 -31
- data/README.txt +6 -31
- data/Rakefile +26 -28
- data/lib/lockdown.rb +40 -10
- data/lib/lockdown/controller.rb +2 -5
- data/lib/lockdown/database.rb +1 -2
- data/lib/lockdown/frameworks/merb.rb +14 -4
- data/lib/lockdown/frameworks/merb/controller.rb +7 -3
- data/lib/lockdown/frameworks/merb/view.rb +5 -3
- data/lib/lockdown/frameworks/rails.rb +14 -4
- data/lib/lockdown/frameworks/rails/controller.rb +21 -20
- data/lib/lockdown/frameworks/rails/view.rb +20 -24
- data/lib/lockdown/orms/active_record.rb +4 -2
- data/lib/lockdown/orms/data_mapper.rb +4 -2
- data/lib/lockdown/rights.rb +1 -1
- data/lib/lockdown/system.rb +2 -3
- data/rails_generators/lockdown/lockdown_generator.rb +21 -11
- data/rails_generators/lockdown/templates/app/controllers/users_controller.rb +1 -4
- data/rails_generators/lockdown/templates/app/helpers/permissions_helper.rb +0 -11
- data/rails_generators/lockdown/templates/app/helpers/user_groups_helper.rb +0 -33
- data/rails_generators/lockdown/templates/app/helpers/users_helper.rb +0 -76
- data/rails_generators/lockdown/templates/app/models/user.rb +37 -11
- data/rails_generators/lockdown/templates/app/views/permissions/show.html.erb +24 -1
- data/rails_generators/lockdown/templates/app/views/user_groups/edit.html.erb +29 -2
- data/rails_generators/lockdown/templates/app/views/user_groups/new.html.erb +28 -2
- data/rails_generators/lockdown/templates/app/views/user_groups/show.html.erb +24 -1
- data/rails_generators/lockdown/templates/app/views/users/edit.html.erb +46 -1
- data/rails_generators/lockdown/templates/app/views/users/new.html.erb +46 -1
- data/rails_generators/lockdown/templates/app/views/users/show.html.erb +30 -1
- data/rails_generators/lockdown/templates/config/initializers/lockit.rb +1 -0
- data/{app_generators/lockdown/templates → rails_generators/lockdown/templates/lib/lockdown}/init.rb +0 -1
- data/{app_generators/lockdown/templates → rails_generators/lockdown/templates/lib/lockdown}/session.rb +13 -12
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +192 -0
- data/tasks/git.rake +40 -0
- data/tasks/manifest.rake +48 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +50 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +279 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- metadata +29 -73
- data/License.txt +0 -20
- data/PostInstall.txt +0 -3
- data/app_generators/lockdown/USAGE +0 -5
- data/app_generators/lockdown/lockdown_generator.rb +0 -25
- data/bin/lockdown +0 -132
- data/lib/lockdown/version.rb +0 -9
- data/rails_generators/lockdown/USAGE +0 -5
- data/rails_generators/lockdown/templates/app/views/permissions/_data.html.erb +0 -13
- data/rails_generators/lockdown/templates/app/views/user_groups/_data.html.erb +0 -68
- data/rails_generators/lockdown/templates/app/views/user_groups/_form.html.erb +0 -11
- data/rails_generators/lockdown/templates/app/views/users/_data.html.erb +0 -87
- data/rails_generators/lockdown/templates/app/views/users/_form.html.erb +0 -12
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -82
- data/setup.rb +0 -1585
- data/test/test_generator_helper.rb +0 -29
- data/test/test_helper.rb +0 -2
- data/test/test_lockdown.rb +0 -11
- data/test/test_lockdown_all_generator.rb +0 -43
- data/test/test_lockdown_generator.rb +0 -45
- data/test/test_lockdown_models_generator.rb +0 -43
- data/website/index.html +0 -62
- data/website/index.txt +0 -20
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/model.jpg +0 -0
- data/website/stylesheets/screen.css +0 -138
- data/website/template.html.erb +0 -54
@@ -3,52 +3,48 @@ module Lockdown
|
|
3
3
|
module Rails
|
4
4
|
module View
|
5
5
|
def self.included(base)
|
6
|
-
base.
|
7
|
-
|
6
|
+
base.class_eval do
|
7
|
+
alias_method :link_to_open, :link_to
|
8
|
+
alias_method :link_to, :link_to_secured
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
alias_method :button_to_open, :button_to
|
11
|
+
alias_method :button_to, :button_to_secured
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def link_to_secured(name, options = {}, html_options = nil)
|
14
|
-
# Don't want to go through the url_for twice
|
15
16
|
url = url_for(options)
|
16
|
-
|
17
|
+
|
18
|
+
method = html_options ? html_options[:method] : nil
|
19
|
+
|
20
|
+
if authorized?(url, method)
|
17
21
|
return link_to_open(name, url, html_options)
|
18
22
|
end
|
19
23
|
return ""
|
20
24
|
end
|
21
25
|
|
22
|
-
def link_to_or_show(name, options = {}, html_options = nil)
|
23
|
-
lnk = link_to(name, options, html_options)
|
24
|
-
lnk.length == 0 ? name : lnk
|
25
|
-
end
|
26
|
-
|
27
26
|
def button_to_secured(name, options = {}, html_options = nil)
|
28
27
|
url = url_for(options)
|
29
|
-
|
28
|
+
|
29
|
+
method = html_options ? html_options[:method] : nil
|
30
|
+
|
31
|
+
if authorized?(url, method)
|
30
32
|
return button_to_open(name, url, html_options)
|
31
33
|
end
|
32
34
|
return ""
|
33
35
|
end
|
34
36
|
|
37
|
+
def link_to_or_show(name, options = {}, html_options = nil)
|
38
|
+
lnk = link_to(name, options, html_options)
|
39
|
+
lnk.length == 0 ? name : lnk
|
40
|
+
end
|
41
|
+
|
35
42
|
def links(*lis)
|
36
43
|
rvalue = []
|
37
44
|
lis.each{|link| rvalue << link if link.length > 0 }
|
38
45
|
rvalue.join(" | ")
|
39
46
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def test_path(url, html_options)
|
44
|
-
if html_options.is_a?(Hash) && html_options[:method] == :delete
|
45
|
-
url += "/destroy"
|
46
|
-
elsif url.split("/").last =~ /\A\d+\z/
|
47
|
-
url += "/show"
|
48
|
-
end
|
49
|
-
url
|
50
|
-
end
|
51
47
|
end # View
|
52
48
|
end # Rails
|
53
49
|
end # Frameworks
|
54
|
-
end # Lockdown
|
50
|
+
end # Lockdown
|
@@ -12,7 +12,9 @@ module Lockdown
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def mixin
|
15
|
-
Lockdown.orm_parent.
|
15
|
+
Lockdown.orm_parent.class_eval do
|
16
|
+
include Lockdown::Orms::ActiveRecord::Stamps
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end # class block
|
18
20
|
|
@@ -63,4 +65,4 @@ module Lockdown
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
66
|
-
end
|
68
|
+
end
|
@@ -12,7 +12,9 @@ module Lockdown
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def mixin
|
15
|
-
orm_parent.
|
15
|
+
orm_parent.class_eval do
|
16
|
+
include Lockdown::Orm::DataMapper::Stamps
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end # class block
|
18
20
|
|
@@ -65,4 +67,4 @@ module Lockdown
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
|
-
end
|
70
|
+
end
|
data/lib/lockdown/rights.rb
CHANGED
data/lib/lockdown/system.rb
CHANGED
@@ -14,9 +14,8 @@ module Lockdown
|
|
14
14
|
|
15
15
|
instance_eval(&block)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
Lockdown::Database.sync_with_db unless skip_sync?
|
18
|
+
|
20
19
|
end
|
21
20
|
|
22
21
|
# Return option value for key
|
@@ -3,7 +3,7 @@
|
|
3
3
|
if Rails::VERSION::MAJOR >= 2 && Rails::VERSION::MINOR >= 1
|
4
4
|
if Rails::VERSION::TINY == 0
|
5
5
|
@override_next_migration_string = true
|
6
|
-
elsif ActiveRecord::Base.timestamped_migrations
|
6
|
+
elsif ActiveRecord::Base.timestamped_migrations
|
7
7
|
@override_next_migration_string = true
|
8
8
|
end
|
9
9
|
end
|
@@ -35,6 +35,9 @@ class LockdownGenerator < Rails::Generator::Base
|
|
35
35
|
@view_path = "app/views"
|
36
36
|
@controller_path = "app/controllers"
|
37
37
|
@helper_path = "app/helpers"
|
38
|
+
@lib_path = "lib/lockdown"
|
39
|
+
|
40
|
+
@initializer = "config/environment.rb"
|
38
41
|
|
39
42
|
if @namespace
|
40
43
|
@view_path += "/#{@namespace}"
|
@@ -44,12 +47,17 @@ class LockdownGenerator < Rails::Generator::Base
|
|
44
47
|
end
|
45
48
|
|
46
49
|
def manifest
|
47
|
-
record do
|
48
|
-
@m = m
|
50
|
+
record do |@m|
|
49
51
|
# Ensure appropriate folder(s) exists
|
50
52
|
@m.directory @view_path
|
51
53
|
@m.directory @controller_path
|
52
54
|
@m.directory @helper_path
|
55
|
+
@m.directory @lib_path
|
56
|
+
|
57
|
+
unless options[:skip_rules]
|
58
|
+
@m.template "lib/lockdown/session.rb", "lib/lockdown/session.rb"
|
59
|
+
@m.file "lib/lockdown/init.rb", "lib/lockdown/init.rb"
|
60
|
+
end
|
53
61
|
|
54
62
|
if options[:basics]
|
55
63
|
options[:skip_management] = true
|
@@ -61,6 +69,8 @@ class LockdownGenerator < Rails::Generator::Base
|
|
61
69
|
add_login unless options[:skip_login]
|
62
70
|
|
63
71
|
add_models
|
72
|
+
|
73
|
+
@m.file "config/initializers/lockit.rb", "config/initializers/lockit.rb"
|
64
74
|
end #record do |m|
|
65
75
|
end
|
66
76
|
|
@@ -79,9 +89,6 @@ class LockdownGenerator < Rails::Generator::Base
|
|
79
89
|
|
80
90
|
copy_views("user_groups")
|
81
91
|
|
82
|
-
@m.template "app/views/permissions/_data.html.erb",
|
83
|
-
"#{@view_path}/permissions/_data.html.erb"
|
84
|
-
|
85
92
|
@m.template "app/views/permissions/index.html.erb",
|
86
93
|
"#{@view_path}/permissions/index.html.erb"
|
87
94
|
|
@@ -123,8 +130,6 @@ class LockdownGenerator < Rails::Generator::Base
|
|
123
130
|
end
|
124
131
|
|
125
132
|
def copy_views(vw)
|
126
|
-
@m.template "app/views/#{vw}/_data.html.erb", "#{@view_path}/#{vw}/_data.html.erb"
|
127
|
-
@m.template "app/views/#{vw}/_form.html.erb", "#{@view_path}/#{vw}/_form.html.erb"
|
128
133
|
@m.template "app/views/#{vw}/index.html.erb", "#{@view_path}/#{vw}/index.html.erb"
|
129
134
|
@m.template "app/views/#{vw}/show.html.erb", "#{@view_path}/#{vw}/show.html.erb"
|
130
135
|
@m.template "app/views/#{vw}/edit.html.erb", "#{@view_path}/#{vw}/edit.html.erb"
|
@@ -187,7 +192,9 @@ class LockdownGenerator < Rails::Generator::Base
|
|
187
192
|
Installs the lockdown framework to managing users user_groups
|
188
193
|
and viewing permissions. Also includes a login screen.
|
189
194
|
|
190
|
-
By default the entire set of stubs are installed.
|
195
|
+
By default the entire set of stubs are installed.
|
196
|
+
|
197
|
+
Please use the appropriate options to customize your install.
|
191
198
|
|
192
199
|
USAGE: #{$0} #{spec.name}
|
193
200
|
EOS
|
@@ -199,11 +206,13 @@ EOS
|
|
199
206
|
opt.on("--namespace=admin",
|
200
207
|
"Install lockdown templates with a namespace, in this example 'admin'.") { |v| options[:namespace] = v }
|
201
208
|
opt.on("--skip-management",
|
202
|
-
"
|
209
|
+
"Only lib/lockdown and app/models are generated.") { |v| options[:skip_management] = v }
|
203
210
|
opt.on("--skip-login",
|
204
|
-
"
|
211
|
+
"Skips generation of session controller and views.") { |v| options[:skip_login] = v }
|
205
212
|
opt.on("--basics",
|
206
213
|
"Install only models and migrations. Equivalent to skip-management and skip-login.") { |v| options[:basics] = v }
|
214
|
+
opt.on("--skip-rules",
|
215
|
+
"Skip installation of lib/lockdown/init.rb lib/lockdown/session.rb") { |v| options[:skip_rules] = v }
|
207
216
|
opt.on("--skip-migrations",
|
208
217
|
"Skip migrations installation") { |v| options[:skip_migrations] = v }
|
209
218
|
end
|
@@ -241,4 +250,5 @@ EOS
|
|
241
250
|
"#{match}\n #{str}"
|
242
251
|
end
|
243
252
|
end
|
253
|
+
|
244
254
|
end
|
@@ -101,15 +101,12 @@ class <%= "#{namespace.camelcase}::" unless namespace.blank? %>UsersController <
|
|
101
101
|
|
102
102
|
def update_user_groups
|
103
103
|
new_ug_ids = params.collect{|p| p[0].split("_")[1].to_i if p[0] =~ /^ug_/}.compact
|
104
|
-
#
|
105
104
|
# Removed previously associated user_groups if not checked this time.
|
106
105
|
#
|
107
106
|
@user.user_groups.dup.each do |g|
|
108
|
-
#Don't remove the automatically assigned user groups
|
109
|
-
next if Lockdown::System.has_user_group?(g)
|
110
107
|
@user.user_groups.delete(g) unless new_ug_ids.include?(g.id)
|
111
108
|
end
|
112
|
-
|
109
|
+
|
113
110
|
# Add in the new permissions
|
114
111
|
#
|
115
112
|
new_ug_ids.each do |id|
|
@@ -1,13 +1,2 @@
|
|
1
1
|
module <%= "#{namespace.camelcase}::" unless namespace.blank? %>PermissionsHelper
|
2
|
-
def permission_name_value
|
3
|
-
h @permission.name
|
4
|
-
end
|
5
|
-
|
6
|
-
def permission_access_rights_value
|
7
|
-
Lockdown::System.access_rights_for_permission(@permission).collect{|r| r}.join("<br/>")
|
8
|
-
end
|
9
|
-
|
10
|
-
def permission_users_value
|
11
|
-
@permission.all_users.collect{|u| link_to_or_show(u.full_name, <%= namespace.blank? ? 'u' : "#{namespace}_user_path(u)" %>)}.join("<br/>")
|
12
|
-
end
|
13
2
|
end
|
@@ -1,35 +1,2 @@
|
|
1
1
|
module <%= "#{namespace.camelcase}::" unless namespace.blank? %>UserGroupsHelper
|
2
|
-
def user_group_name_value
|
3
|
-
if <%= action_name %> == "show"
|
4
|
-
h @user_group.name
|
5
|
-
else
|
6
|
-
text_field :user_group, :name
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def user_group_permissions_value
|
11
|
-
if <%= action_name %> == "show"
|
12
|
-
@user_group.permissions.collect{|p| p.name + "<br/>"}
|
13
|
-
else
|
14
|
-
rvalue = %{<ul id="all_permissions" class="checklist">}
|
15
|
-
@all_permissions.each_with_index do |perm,i|
|
16
|
-
bg = ( i % 2 == 0 ) ? "even" : "odd"
|
17
|
-
input_id = "perm_#{perm.id}"
|
18
|
-
checked = (@user_group.permission_ids.include?(perm.id) ? "checked" : "")
|
19
|
-
bg << "_" << checked if checked.length > 0
|
20
|
-
rvalue << <<-HTML
|
21
|
-
<li class="#{bg}" id="li_#{input_id}">
|
22
|
-
<label for="#{input_id}" onclick="do_highlight('#{input_id}')">
|
23
|
-
<input id="#{input_id}" name="#{input_id}" type="checkbox" #{checked}/> #{perm.name}
|
24
|
-
</label>
|
25
|
-
</li>
|
26
|
-
HTML
|
27
|
-
end
|
28
|
-
rvalue << "</ul>"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def user_group_users_value
|
33
|
-
@user_group.all_users.collect{|u| link_to_or_show(u.full_name, <%= namespace.blank? ? 'u' : "#{namespace}_user_path(u)" %>)}.join("<br/>")
|
34
|
-
end
|
35
2
|
end
|
@@ -1,78 +1,2 @@
|
|
1
1
|
module <%= "#{namespace.camelcase}::" unless namespace.blank? %>UsersHelper
|
2
|
-
def user_first_name_value
|
3
|
-
if <%= action_name %> == "show"
|
4
|
-
h @user.first_name
|
5
|
-
else
|
6
|
-
text_field :user, :first_name
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def user_last_name_value
|
11
|
-
if <%= action_name %> == "show"
|
12
|
-
h @user.last_name
|
13
|
-
else
|
14
|
-
text_field :user, :last_name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def user_email_value
|
19
|
-
if <%= action_name %> == "show"
|
20
|
-
h @user.email
|
21
|
-
else
|
22
|
-
text_field :user, :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 :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}" id="li_#{input_id}">
|
67
|
-
<label 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
2
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
require 'digest/sha1'
|
2
2
|
class User < ActiveRecord::Base
|
3
3
|
has_and_belongs_to_many :user_groups
|
4
|
-
|
5
|
-
# that is bundled with lockdown.
|
6
|
-
# For more info: http://stonean.com
|
7
|
-
#
|
8
|
-
depends_on :profile, :attrs => [:first_name, :last_name, :email]
|
4
|
+
belongs_to :profile
|
9
5
|
|
10
6
|
# Virtual attributes
|
11
7
|
attr_accessor :password
|
@@ -18,7 +14,8 @@ class User < ActiveRecord::Base
|
|
18
14
|
validates_length_of :login, :within => 3..40
|
19
15
|
validates_uniqueness_of :login, :case_sensitive => false
|
20
16
|
|
21
|
-
before_save :
|
17
|
+
before_save :encrypt_password
|
18
|
+
before_save :save_profile
|
22
19
|
|
23
20
|
attr_accessible :login, :password, :password_confirmation,
|
24
21
|
:first_name, :last_name, :email
|
@@ -45,14 +42,39 @@ class User < ActiveRecord::Base
|
|
45
42
|
end
|
46
43
|
|
47
44
|
def full_name
|
48
|
-
|
45
|
+
first_name + " " + last_name
|
46
|
+
end
|
47
|
+
|
48
|
+
# Profile information
|
49
|
+
def first_name
|
50
|
+
user_profile.first_name
|
49
51
|
end
|
50
52
|
|
51
|
-
|
53
|
+
def first_name=(string)
|
54
|
+
user_profile.first_name = string
|
55
|
+
end
|
56
|
+
|
57
|
+
def last_name
|
58
|
+
user_profile.last_name
|
59
|
+
end
|
60
|
+
|
61
|
+
def last_name=(string)
|
62
|
+
user_profile.last_name = string
|
63
|
+
end
|
64
|
+
|
65
|
+
def email
|
66
|
+
user_profile.email
|
67
|
+
end
|
68
|
+
|
69
|
+
def email=(string)
|
70
|
+
user_profile.email = string
|
71
|
+
end
|
52
72
|
|
53
|
-
def
|
54
|
-
|
73
|
+
def user_profile
|
74
|
+
self.profile || self.profile = Profile.new
|
55
75
|
end
|
76
|
+
|
77
|
+
protected
|
56
78
|
|
57
79
|
def encrypt_password
|
58
80
|
return if password.blank?
|
@@ -61,7 +83,11 @@ class User < ActiveRecord::Base
|
|
61
83
|
end
|
62
84
|
self.crypted_password = encrypt(password)
|
63
85
|
end
|
64
|
-
|
86
|
+
|
87
|
+
def save_profile
|
88
|
+
profile.save
|
89
|
+
end
|
90
|
+
|
65
91
|
def password_required?
|
66
92
|
(crypted_password.blank? || !password.blank?)
|
67
93
|
end
|