lockdown 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.2.0 2008-04-25
2
+ * First full implementation of generate script "lockdown_all". Warranted a bump up of the minor version.
3
+
1
4
  == 0.1.4 2008-04-25
2
5
  * Uncommented line in config/hoe.rb to hopefully resolved rubigen dependency issue.
3
6
 
data/Manifest.txt CHANGED
@@ -30,6 +30,7 @@ rails_generators/lockdown_all/templates/app/helpers/permissions_helper.rb
30
30
  rails_generators/lockdown_all/templates/app/helpers/user_groups_helper.rb
31
31
  rails_generators/lockdown_all/templates/app/helpers/users_helper.rb
32
32
  rails_generators/lockdown_all/templates/app/models/permission.rb
33
+ rails_generators/lockdown_all/templates/app/models/profile.rb
33
34
  rails_generators/lockdown_all/templates/app/models/user.rb
34
35
  rails_generators/lockdown_all/templates/app/models/user_group.rb
35
36
  rails_generators/lockdown_all/templates/app/views/permissions/_data.html.erb
@@ -49,8 +50,9 @@ rails_generators/lockdown_all/templates/app/views/users/edit.html.erb
49
50
  rails_generators/lockdown_all/templates/app/views/users/index.html.erb
50
51
  rails_generators/lockdown_all/templates/app/views/users/new.html.erb
51
52
  rails_generators/lockdown_all/templates/app/views/users/show.html.erb
53
+ rails_generators/lockdown_all/templates/db/migrate/create_base_user_groups.rb
52
54
  rails_generators/lockdown_all/templates/db/migrate/create_permissions.rb
53
- rails_generators/lockdown_all/templates/db/migrate/create_profile.rb
55
+ rails_generators/lockdown_all/templates/db/migrate/create_profiles.rb
54
56
  rails_generators/lockdown_all/templates/db/migrate/create_user_groups.rb
55
57
  rails_generators/lockdown_all/templates/db/migrate/create_users.rb
56
58
  script/console
@@ -95,8 +95,10 @@ module Lockdown
95
95
  #
96
96
  # All newly created users are assigned to this User Group by default
97
97
  #
98
+ # Sample registered user permission:
99
+ # [:my_account]
98
100
  def registered_users
99
- #[:my_account]
101
+ []
100
102
  end
101
103
 
102
104
  #
@@ -52,7 +52,7 @@ module Lockdown
52
52
  end
53
53
 
54
54
  def current_user
55
- return User.find(current_user_id, :include => [:profile, :user_groups])
55
+ return current_user_id > 0 ? User.find(current_user_id, :include => [:profile, :user_groups]) : nil
56
56
  end
57
57
 
58
58
  end # Session module
data/bin/lockdown CHANGED
@@ -5,7 +5,12 @@ require "rubigen"
5
5
  require "rubigen/scripts/generate"
6
6
  require 'optparse'
7
7
 
8
- #require File.join(File.dirname(__FILE__), "..", "lib", "lockdown_generator")
8
+ if %w(-v --version).include? ARGV.first
9
+ require 'lockdown/version'
10
+ puts "#{File.basename($0)} #{Lockdown::VERSION::STRING}"
11
+ exit(0)
12
+ end
13
+
9
14
 
10
15
  #
11
16
  # Created on 2008-4-21.
@@ -190,7 +190,7 @@ module Lockdown
190
190
  respond_to do |accepts|
191
191
  accepts.html do
192
192
  store_location
193
- send_to login_path
193
+ send_to "/"
194
194
  end
195
195
  accepts.xml do
196
196
  headers["Status"] = "Unauthorized"
@@ -1,8 +1,8 @@
1
1
  module Lockdown #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 4
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,16 +1,5 @@
1
- require "rubigen"
2
-
3
- class LockdownAllGenerator < RubiGen::Base
4
-
5
- default_options :author => nil
6
-
7
- attr_reader :name
8
-
9
- def initialize(runtime_args, runtime_options = {})
10
- super
11
- usage if args.empty?
12
- @name = args.shift
13
- end
1
+ class LockdownAllGenerator < Rails::Generator::Base
2
+ attr_accessor :file_name
14
3
 
15
4
  def manifest
16
5
  record do |m|
@@ -28,11 +17,28 @@ class LockdownAllGenerator < RubiGen::Base
28
17
  m.file "app/controllers/permissions_controller.rb", "app/controllers/permissions_controller.rb"
29
18
  m.file "app/controllers/users_controller.rb", "app/controllers/users_controller.rb"
30
19
  m.file "app/controllers/user_groups_controller.rb", "app/controllers/user_groups_controller.rb"
20
+ m.file "app/controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb"
31
21
 
32
22
  #Models
33
23
  m.file "app/models/permission.rb", "app/models/permission.rb"
34
24
  m.file "app/models/user.rb", "app/models/user.rb"
35
25
  m.file "app/models/user_group.rb", "app/models/user_group.rb"
26
+ m.file "app/models/profile.rb", "app/models/profile.rb"
27
+
28
+
29
+
30
+ #Migrations
31
+ m.migration_template "db/migrate/create_profiles.rb", "db/migrate", :migration_file_name => "create_profiles"
32
+ m.migration_template "db/migrate/create_users.rb", "db/migrate", :migration_file_name => "create_users"
33
+ m.migration_template "db/migrate/create_user_groups.rb", "db/migrate", :migration_file_name => "create_user_groups"
34
+ m.migration_template "db/migrate/create_permissions.rb", "db/migrate", :migration_file_name => "create_permissions"
35
+ m.migration_template "db/migrate/create_base_user_groups.rb", "db/migrate", :migration_file_name => "create_base_user_groups"
36
+
37
+ #Route file (i like having them on individual lines)
38
+ m.route_resources "permissions"
39
+ m.route_resources "user_groups"
40
+ m.route_resources "users"
41
+ m.route_resources "sessions"
36
42
 
37
43
  #Helpers
38
44
  m.file "app/helpers/permissions_helper.rb", "app/helpers/permissions_helper.rb"
@@ -45,7 +51,9 @@ class LockdownAllGenerator < RubiGen::Base
45
51
 
46
52
  copy_views(m, "user_groups")
47
53
 
48
- copy_views(m, "permissions")
54
+ m.file "app/views/permissions/_data.html.erb", "app/views/permissions/_data.html.erb"
55
+ m.file "app/views/permissions/index.html.erb", "app/views/permissions/index.html.erb"
56
+ m.file "app/views/permissions/show.html.erb", "app/views/permissions/show.html.erb"
49
57
 
50
58
  m.file "app/views/sessions/new.html.erb", "app/views/sessions/new.html.erb"
51
59
  end
@@ -54,9 +62,10 @@ class LockdownAllGenerator < RubiGen::Base
54
62
  protected
55
63
  def banner
56
64
  <<-EOS
57
- Creates a ...
65
+ Installs the lockdown framework to managing users user_groups and viewing permissions.
66
+ Also includes a login screen.
58
67
 
59
- USAGE: #{$0} #{spec.name} name
68
+ USAGE: #{$0} #{spec.name}
60
69
  EOS
61
70
  end
62
71
 
@@ -5,8 +5,6 @@ class UsersController < ApplicationController
5
5
  # GET /users.xml
6
6
  def index
7
7
  @users = User.all
8
- logger.info "===============> access rights: #{session[:access_rights].join("\n")}" unless session[:access_rights] == :all
9
- logger.info "===============> is: #{current_user_is_admin?}"
10
8
  respond_to do |format|
11
9
  format.html # index.html.erb
12
10
  format.xml { render :xml => @users }
@@ -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
@@ -95,6 +95,8 @@ class UserGroup < ActiveRecord::Base
95
95
  # to errors by mistakingly removing them.
96
96
  #
97
97
  def find_assignable_for_user(usr)
98
+ return [] if usr.nil?
99
+
98
100
  if usr.administrator?
99
101
  find :all,
100
102
  :conditions => "name != 'Public Access' and name != 'Registered Users'",
@@ -121,6 +123,8 @@ class UserGroup < ActiveRecord::Base
121
123
  #
122
124
  #
123
125
  def find_content_assignable_for_user(usr)
126
+ return [] if usr.nil?
127
+
124
128
  if usr.administrator?
125
129
  find :all
126
130
  else
@@ -0,0 +1,11 @@
1
+ class CreateBaseUserGroups < ActiveRecord::Migration
2
+ def self.up
3
+ UserGroup.create_record :administrators
4
+ UserGroup.create_record :public_access
5
+ UserGroup.create_record :registered_users
6
+ end
7
+
8
+ def self.down
9
+ #Nothing to see here...
10
+ end
11
+ end
@@ -5,11 +5,15 @@ class CreatePermissions < ActiveRecord::Migration
5
5
 
6
6
  t.timestamps
7
7
  end
8
- create_join_table :permissions, :user_groups
8
+
9
+ create_table :permissions_user_groups, :id => false do |t|
10
+ t.integer :permission_id
11
+ t.integer :user_group_id
12
+ end
9
13
  end
10
14
 
11
15
  def self.down
12
- drop_join_table :permissions, :user_groups
16
+ drop_table :permissions_user_groups
13
17
  drop_table :permissions
14
18
  end
15
19
  end
@@ -9,11 +9,9 @@ class CreateProfiles < ActiveRecord::Migration
9
9
 
10
10
  t.timestamps
11
11
  end
12
- define_foreign_key_column :profiles, :updated_by, :profiles
13
12
  end
14
13
 
15
14
  def self.down
16
- remove_foreign_key_column :profiles, :updated_by
17
15
  drop_table :profiles
18
16
  end
19
17
  end
@@ -5,11 +5,15 @@ class CreateUserGroups < ActiveRecord::Migration
5
5
 
6
6
  t.timestamps
7
7
  end
8
- create_join_table :user_groups, :users
8
+
9
+ create_table :user_groups_users, :id => false do |t|
10
+ t.integer :user_group_id
11
+ t.integer :user_id
12
+ end
9
13
  end
10
14
 
11
15
  def self.down
12
- drop_join_table :user_groups, :users
16
+ drop_table :user_groups_users
13
17
  drop_table :user_groups
14
18
  end
15
19
  end
@@ -4,17 +4,14 @@ class CreateUsers < ActiveRecord::Migration
4
4
  t.string :login
5
5
  t.string :crypted_password
6
6
  t.string :salt
7
+ t.integer :profile_id
7
8
  t.integer :updated_by
8
9
 
9
10
  t.timestamps
10
11
  end
11
- add_foreign_key :users, :profiles
12
- define_foreign_key_column :users, :updated_by, :profiles
13
12
  end
14
13
 
15
14
  def self.down
16
- remove_foreign_key :users, :profiles
17
- remove_foreign_key_column :users, :updated_by
18
15
  drop_table :users
19
16
  end
20
17
  end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>lockdown</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/lockdown"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/lockdown" class="numbers">0.1.4</a>
36
+ <a href="http://rubyforge.org/projects/lockdown" class="numbers">0.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;lockdown&#8217;</h1>
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -68,6 +68,7 @@ files:
68
68
  - rails_generators/lockdown_all/templates/app/helpers/user_groups_helper.rb
69
69
  - rails_generators/lockdown_all/templates/app/helpers/users_helper.rb
70
70
  - rails_generators/lockdown_all/templates/app/models/permission.rb
71
+ - rails_generators/lockdown_all/templates/app/models/profile.rb
71
72
  - rails_generators/lockdown_all/templates/app/models/user.rb
72
73
  - rails_generators/lockdown_all/templates/app/models/user_group.rb
73
74
  - rails_generators/lockdown_all/templates/app/views/permissions/_data.html.erb
@@ -87,8 +88,9 @@ files:
87
88
  - rails_generators/lockdown_all/templates/app/views/users/index.html.erb
88
89
  - rails_generators/lockdown_all/templates/app/views/users/new.html.erb
89
90
  - rails_generators/lockdown_all/templates/app/views/users/show.html.erb
91
+ - rails_generators/lockdown_all/templates/db/migrate/create_base_user_groups.rb
90
92
  - rails_generators/lockdown_all/templates/db/migrate/create_permissions.rb
91
- - rails_generators/lockdown_all/templates/db/migrate/create_profile.rb
93
+ - rails_generators/lockdown_all/templates/db/migrate/create_profiles.rb
92
94
  - rails_generators/lockdown_all/templates/db/migrate/create_user_groups.rb
93
95
  - rails_generators/lockdown_all/templates/db/migrate/create_users.rb
94
96
  - script/console