lockdown 0.3.1 → 0.3.2

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.3.2 2008-04-29
2
+ * Management screens looking good. Now moving on to testing with starter application.
3
+
1
4
  == 0.3.1 2008-04-29
2
5
  * Some initital testing done.
3
6
 
@@ -65,7 +65,18 @@ module Lockdown
65
65
  #
66
66
  def create_user_group(str_sym)
67
67
  return unless @options[:use_db_models]
68
- UserGroup.create(:name => string_name(str_sym))
68
+ ug = UserGroup.create(:name => string_name(str_sym))
69
+ #
70
+ # No need to create permissions records for administrators
71
+ #
72
+ ug_sym = symbol_name(ug.name)
73
+ return if ug_sym == administrator_group_symbol
74
+
75
+ if self.has_user_group?(ug)
76
+ @user_groups[ug_sym].collect do |perm|
77
+ Permission.create(:name => string_name(perm))
78
+ end
79
+ end
69
80
  end
70
81
 
71
82
  def create_administrator_user_group
@@ -73,6 +84,17 @@ module Lockdown
73
84
  Lockdown::System.create_user_group administrator_group_symbol
74
85
  end
75
86
 
87
+ #
88
+ # Determine if the user group is defined in init.rb
89
+ #
90
+ def has_user_group?(ug)
91
+ return true if symbol_name(ug.name) == administrator_group_symbol
92
+ @user_groups.each do |key,value|
93
+ return true if key == symbol_name(ug.name)
94
+ end
95
+ return false
96
+ end
97
+
76
98
  #
77
99
  # Delete a user group record from the database
78
100
  #
@@ -124,6 +146,21 @@ module Lockdown
124
146
  end
125
147
  end
126
148
 
149
+ #
150
+ # Similar to user_groups_assignable_for_user, this method should be
151
+ # used to restrict users from creating a user group with more power than
152
+ # they have been allowed.
153
+ #
154
+ def permissions_assignable_for_user(usr)
155
+ return [] if usr.nil?
156
+ if administrator?(usr)
157
+ @permissions.keys.collect{|k| Permission.find_by_name(string_name(k)) }.compact
158
+ else
159
+ groups = user_groups_assignable_for_user(usr)
160
+ groups.collect{|g| g.permissions}.flatten.compact
161
+ end
162
+ end
163
+
127
164
  def make_user_administrator(usr)
128
165
  usr.user_groups << UserGroup.find_or_create_by_name(administrator_group_string)
129
166
  end
@@ -2,7 +2,7 @@ module Lockdown #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -41,22 +41,6 @@ class LockdownAllGenerator < Rails::Generator::Base
41
41
 
42
42
 
43
43
 
44
- #Migrations
45
- m.migration_template "db/migrate/create_profiles.rb", "db/migrate",
46
- :migration_file_name => "create_profiles"
47
-
48
- m.migration_template "db/migrate/create_users.rb", "db/migrate",
49
- :migration_file_name => "create_users"
50
-
51
- m.migration_template "db/migrate/create_user_groups.rb", "db/migrate",
52
- :migration_file_name => "create_user_groups"
53
-
54
- m.migration_template "db/migrate/create_permissions.rb", "db/migrate",
55
- :migration_file_name => "create_permissions"
56
-
57
- m.migration_template "db/migrate/create_admin_user_and_user_group.rb",
58
- "db/migrate",
59
- :migration_file_name => "create_admin_user_and_user_group"
60
44
 
61
45
  #Route file (i like having them on individual lines)
62
46
  m.route_resources "permissions"
@@ -93,6 +77,47 @@ class LockdownAllGenerator < Rails::Generator::Base
93
77
 
94
78
  m.file "app/views/sessions/new.html.erb",
95
79
  "app/views/sessions/new.html.erb"
80
+
81
+ #Migrations
82
+ begin
83
+ m.migration_template "db/migrate/create_profiles.rb", "db/migrate",
84
+ :migration_file_name => "create_profiles"
85
+ rescue
86
+ puts "Profiles migration exists"
87
+ end
88
+
89
+ begin
90
+ m.migration_template "db/migrate/create_users.rb", "db/migrate",
91
+ :migration_file_name => "create_users"
92
+
93
+ rescue
94
+ puts "Users migration exists"
95
+ end
96
+
97
+ begin
98
+ m.migration_template "db/migrate/create_user_groups.rb", "db/migrate",
99
+ :migration_file_name => "create_user_groups"
100
+
101
+ rescue
102
+ puts "User Groups migration exists"
103
+ end
104
+
105
+ begin
106
+ m.migration_template "db/migrate/create_permissions.rb", "db/migrate",
107
+ :migration_file_name => "create_permissions"
108
+
109
+ rescue
110
+ puts "Permissions migration exists"
111
+ end
112
+
113
+ begin
114
+ m.migration_template "db/migrate/create_admin_user_and_user_group.rb",
115
+ "db/migrate",
116
+ :migration_file_name => "create_admin_user_and_user_group"
117
+
118
+ rescue
119
+ puts "Admin User Group... migration exists"
120
+ end
96
121
  end
97
122
  end
98
123
 
@@ -1,6 +1,5 @@
1
1
  class UserGroupsController < ApplicationController
2
2
  before_filter :find_user_group, :only => [:show, :edit, :update, :destroy]
3
- before_filter :protect_private, :only => [:edit, :update]
4
3
  after_filter :update_permissions, :only => [:create, :update]
5
4
 
6
5
  # GET /user_groups
@@ -27,7 +26,7 @@ class UserGroupsController < ApplicationController
27
26
  # GET /user_groups/new.xml
28
27
  def new
29
28
  @user_group = UserGroup.new
30
- @all_permissions = Lockdown::System.get_permissions
29
+ @all_permissions = Lockdown::System.permissions_assignable_for_user(current_user)
31
30
 
32
31
  respond_to do |format|
33
32
  format.html # new.html.erb
@@ -37,7 +36,7 @@ class UserGroupsController < ApplicationController
37
36
 
38
37
  # GET /user_groups/1/edit
39
38
  def edit
40
- @all_permissions = Lockdown::System.get_permissions
39
+ @all_permissions = Lockdown::System.permissions_assignable_for_user(current_user)
41
40
  end
42
41
 
43
42
  # POST /user_groups
@@ -51,6 +50,7 @@ class UserGroupsController < ApplicationController
51
50
  format.html { redirect_to(@user_group) }
52
51
  format.xml { render :xml => @user_group, :status => :created, :location => @user_group }
53
52
  else
53
+ @all_permissions = Lockdown::System.permissions_assignable_for_user(current_user)
54
54
  format.html { render :action => "new" }
55
55
  format.xml { render :xml => @user_group.errors, :status => :unprocessable_entity }
56
56
  end
@@ -89,10 +89,6 @@ class UserGroupsController < ApplicationController
89
89
  @user_group = UserGroup.find(params[:id])
90
90
  end
91
91
 
92
- def protect_private
93
- @user_group.protect_private
94
- end
95
-
96
92
  def update_permissions
97
93
  new_perm_ids = params.collect{|p| p[0].split("_")[1].to_i if p[0] =~ /^perm_/}.compact
98
94
  #
@@ -48,6 +48,7 @@ class UsersController < ApplicationController
48
48
  flash[:notice] = "Thanks for signing up!"
49
49
  redirect_to(users_path)
50
50
  else
51
+ @user_groups_for_user = Lockdown::System.user_groups_assignable_for_user(current_user)
51
52
  flash[:error] = "Please correct the following issues"
52
53
  render :action => "new"
53
54
  end
@@ -9,8 +9,8 @@
9
9
  <tr>
10
10
  <td><%=h user_group.name %></td>
11
11
  <td><%= link_to 'Show', user_group %></td>
12
- <td><%= link_to('Edit', edit_user_group_path(user_group)) unless user_group.private_record? %></td>
13
- <td><%= link_to('Destroy', user_group, :confirm => 'Are you sure?', :method => :delete) unless user_group.system_assigned? %></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
14
  </tr>
15
15
  <% end %>
16
16
  </table>
@@ -1,6 +1,6 @@
1
1
  <%= render :partial => "data", :locals => {:f => nil} %>
2
2
 
3
- <% unless @user_group.system_assigned? %>
3
+ <% unless Lockdown::System.has_user_group?(@user_group) %>
4
4
  <%= link_to 'Edit', edit_user_group_path(@user_group) %> |
5
5
  <% end %>
6
6
  <%= link_to 'Back', user_groups_path %>
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone