public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
allow disabling of users

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1413 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Jul 22 18:19:34 -0700 2006
commit  9156616934570a35db165facb53eb4b7fb2680ca
tree    a7d14532614674aedbb9b74c6cac0d6019fe8a8d
parent  77bde57a766f7091a7cc675819bab68a8312302c
...
1
2
3
 
 
 
4
5
6
7
8
 
 
 
 
9
10
11
...
28
29
30
31
32
33
 
 
 
 
 
 
 
 
 
 
 
34
35
36
...
1
2
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
34
35
36
 
 
 
37
38
39
40
41
42
43
44
45
46
47
48
 
49
0
@@ -1,11 +1,17 @@
0
 class Admin::UsersController < Admin::BaseController
0
   def index
0
- @users = User.find :all, :order => 'login'
0
+ @users = User.find_with_deleted :all, :order => 'login'
0
+ @enabled, @disabled = @users.partition { |u| u.deleted_at.nil? }
0
+ @users = @enabled + @disabled
0
   end
0
 
0
   def show
0
     @user = User.find_by_login params[:id]
0
   end
0
+
0
+ def new
0
+ @user = User.new
0
+ end
0
 
0
   def create
0
     @user = User.new params[:user]
0
@@ -28,9 +34,16 @@ class Admin::UsersController < Admin::BaseController
0
       render :action => 'show'
0
     end
0
   end
0
-
0
- def new
0
- @user = User.new
0
+
0
+ def destroy
0
+ @user = User.find params[:id]
0
+ @user.destroy
0
+ @user = User.find_with_deleted params[:id] # reload
0
+ end
0
+
0
+ def enable
0
+ @user = User.find_with_deleted params[:id]
0
+ @user.deleted_at = nil
0
+ @user.save!
0
   end
0
-
0
 end
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,6 +1,6 @@
0
 class Content < ActiveRecord::Base
0
   filtered_column :body, :excerpt, :only => :textile_filter
0
   validates_presence_of :body
0
- belongs_to :user
0
+ belongs_to :user, :with_deleted => true
0
   belongs_to :site
0
 end
0
\ No newline at end of file
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@ class Event < ActiveRecord::Base
0
   belongs_to :article, :foreign_key => 'article_id'
0
 
0
   # updater of the article at the time of the event
0
- belongs_to :user
0
+ belongs_to :user, :with_deleted => true
0
   
0
   belongs_to :comment
0
   belongs_to :site
...
12
13
14
15
 
16
17
18
...
12
13
14
 
15
16
17
18
0
@@ -12,7 +12,7 @@ class UserAuth < ActiveRecord::Base
0
   validates_confirmation_of :password, :if => :password_required?
0
   validates_length_of :login, :within => 3..40
0
   validates_length_of :email, :within => 3..100
0
- validates_uniqueness_of :login, :email, :salt
0
+ validates_uniqueness_of :login, :email, :case_sensitve => false
0
   before_save :encrypt_password
0
   
0
   # Uncomment this to use activation
...
9
10
11
12
13
14
15
16
17
18
 
19
20
...
9
10
11
 
 
 
 
 
 
 
12
13
14
0
@@ -9,11 +9,5 @@
0
 <% end %>
0
 
0
 <ul id="users">
0
-<% @users.each do |user| -%>
0
- <li class="clear">
0
- <%= avatar_for user %>
0
- <h3><%= link_to user.login, :action => 'show', :id => user %></h3>
0
- <%= user.email %>
0
- </li>
0
-<% end -%>
0
+<%= render :partial => "user", :collection => @users %>
0
 </ul>
0
\ No newline at end of file
...
88
89
90
 
 
 
 
 
 
 
 
 
 
91
92
93
...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
0
@@ -88,6 +88,16 @@ end
0
 
0
 # http://rails.techno-weenie.net/tip/2005/12/23/make_fixtures
0
 ActiveRecord::Base.class_eval do
0
+ # person.dom_id #-> "person-5"
0
+ # new_person.dom_id #-> "person-new"
0
+ # new_person.dom_id(:bare) #-> "new"
0
+ # person.dom_id(:person_name) #-> "person-name-5"
0
+ def dom_id(prefix=nil)
0
+ display_id = new_record? ? "new" : id
0
+ prefix ||= self.class.name.underscore
0
+ prefix != :bare ? "#{prefix.to_s.dasherize}-#{display_id}" : display_id
0
+ end
0
+
0
   # Write a fixture file for testing
0
   def self.to_fixture(fixture_path = nil)
0
     File.open(File.expand_path(fixture_path || "test/fixtures/#{table_name}.yml", RAILS_ROOT), 'w') do |out|
...
31
32
33
34
 
35
36
37
...
31
32
33
 
34
35
36
37
0
@@ -31,7 +31,7 @@ another:
0
   created_at: <%= 4.days.ago.to_s(:db) %>
0
   updated_at: <%= 4.days.ago.to_s(:db) %>
0
   published_at: <%= 4.days.ago.to_s(:db) %>
0
- user_id: 1
0
+ user_id: 3
0
   type: Article
0
 welcome_comment:
0
   id: 3
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
21
22
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
0
@@ -18,4 +18,15 @@ arthur:
0
   activation_code: arthurscode # only if you're activating new signups
0
   created_at: <%= 1.days.ago.to_s :db %>
0
   updated_at: <%= 1.days.ago.to_s :db %>
0
+ filters: "--- \n- :markdown_filter\n"
0
+aaron:
0
+ id: 3
0
+ login: aaron
0
+ email: aaron@example.com
0
+ salt: 55bc51360864c82dcd7ff4bcfec56a8d8e79e751
0
+ crypted_password: 37ba966058c6f39162e5b537adb516af91cd1fe6 # arthur
0
+ activation_code: arthurscode # only if you're activating new signups
0
+ created_at: <%= 1.days.ago.to_s :db %>
0
+ updated_at: <%= 1.days.ago.to_s :db %>
0
+ deleted_at: <%= 5.hours.ago.to_s :db %>
0
   filters: "--- \n- :markdown_filter\n"
0
\ No newline at end of file
...
81
82
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
0
@@ -81,4 +81,38 @@ class Admin::UsersControllerTest < Test::Unit::TestCase
0
     users(:quentin).reload
0
     assert_equal :markdown_filter, users(:quentin).filters.first
0
   end
0
+
0
+ def test_should_show_deleted_users
0
+ get :index
0
+ assert_equal 3, assigns(:users).size
0
+ normal_tag = { :tag => 'li', :attributes => { :id => 'user-1', :class => 'clear' } }
0
+ deleted_tag = { :tag => 'li', :attributes => { :id => 'user-3', :class => 'clear deleted' } }
0
+ assert_tag normal_tag
0
+ assert_tag 'li', :attributes => { :id => 'user-2', :class => 'clear' }
0
+ assert_tag deleted_tag
0
+ assert_tag 'a', :content => 'Disable', :ancestor => normal_tag
0
+ assert_no_tag 'a', :content => 'Disable', :ancestor => deleted_tag
0
+ assert_no_tag 'a', :content => 'Enable', :ancestor => normal_tag
0
+ assert_tag 'a', :content => 'Enable', :ancestor => deleted_tag
0
+ end
0
+
0
+ def test_should_disable_user
0
+ assert_no_difference User, :count_with_deleted do
0
+ assert_difference User, :count, -1 do
0
+ xhr :post, :destroy, :id => users(:quentin).id
0
+ assert_response :success
0
+ end
0
+ end
0
+
0
+ assert_equal users(:quentin), User.find_with_deleted(users(:quentin).id)
0
+ end
0
+
0
+ def test_should_enable_user
0
+ assert_no_difference User, :count_with_deleted do
0
+ assert_difference User, :count do
0
+ xhr :post, :enable, :id => 3
0
+ assert_response :success
0
+ end
0
+ end
0
+ end
0
 end
...
122
123
124
 
 
 
 
125
126
127
...
122
123
124
125
126
127
128
129
130
131
0
@@ -122,6 +122,10 @@ class ArticleTest < Test::Unit::TestCase
0
     assert a.published_at.utc?
0
   end
0
 
0
+ def test_should_find_deleted_user
0
+ assert_equal User.find_with_deleted(3), contents(:another).user
0
+ end
0
+
0
   protected
0
     def create_article(options = {})
0
       Article.create options.reverse_merge(:user_id => 1, :site_id => 1, :title => 'foo')

Comments

    No one has commented yet.