public
Description: El Dorado is a full-stack community web application written in Ruby/Rails.
Homepage: http://almosteffortless.com/eldorado/
Clone URL: git://github.com/trevorturk/el-dorado.git
changing topics closed to locked and adjusting logic to allow admins and 
topic creators to post anyway

git-svn-id: http://eldorado.googlecode.com/svn/trunk@447 
9c008b19-a030-0410-9975-d76d301b4276
trevorturk (author)
Thu Sep 06 20:28:36 -0700 2007
commit  b8251fd8da3475f8addf217e4cc2ba6c0c1e1e7a
tree    779dc3f1fa29a91402797f7f28260b6be9643791
parent  86b996d011de45fac2fdb666c56dbd9a7e842918
...
13
14
15
16
17
 
 
 
 
18
19
20
...
13
14
15
 
16
17
18
19
20
21
22
23
0
@@ -13,8 +13,11 @@ class PostsController < ApplicationController
0
   end
0
     
0
   def create
0
- @post = current_user.posts.build(params[:post])
0
     @topic = Topic.find(params[:post][:topic_id])
0
+ @post = current_user.posts.build(params[:post])
0
+ if @topic.locked
0
+ redirect_to home_path and return false unless admin? || (current_user == @topic.user)
0
+ end
0
     @topic.posts_count += 1 # hack to set last_page correctly
0
     if (@topic.posts << @post)
0
       redirect_to :controller => 'topics', :action => 'show', :id => @topic.id, :page => @topic.last_page, :anchor => 'p' + @post.id.to_s
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: avatars
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: bans
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: categories
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: events
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: forums
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: headers
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: options
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: posts
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: ranks
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: subscriptions
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: themes
0
 #
...
1
2
 
3
4
5
...
13
14
15
16
 
17
18
19
...
31
32
33
34
 
35
36
37
...
1
 
2
3
4
5
...
13
14
15
 
16
17
18
19
...
31
32
33
 
34
35
36
37
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: topics
0
 #
0
@@ -13,7 +13,7 @@
0
 # last_post_at :datetime
0
 # last_post_by :integer(11)
0
 # private :boolean(1)
0
-# closed :boolean(1)
0
+# locked :boolean(1)
0
 # sticky :boolean(1)
0
 # forum_id :integer(11)
0
 #
0
@@ -31,7 +31,7 @@ class Topic < ActiveRecord::Base
0
     
0
   attr_accessor :body
0
   
0
- attr_accessible :title, :private, :closed, :sticky, :forum_id
0
+ attr_accessible :title, :private, :locked, :sticky, :forum_id
0
   
0
   PER_PAGE = 30
0
   
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: uploads
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: users
0
 #
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 <% form_for :post, :url => posts_path do |f| -%>
0
   <div class="box">
0
- <span class="top">Post a Reply</span><br />
0
+ <span id="reply" class="top">Post a Reply</span><br />
0
       <%= f.hidden_field :topic_id, :value => @topic.id %>
0
       <%= f.text_area :body, :rows => '8', :style => "width:66%;" %>
0
       <p>
...
10
11
12
 
13
14
15
...
10
11
12
13
14
15
16
0
@@ -10,6 +10,7 @@
0
         <%= f.text_field :title, :style => "width:66%" %>
0
       <% end %>
0
        &nbsp; <%= f.check_box(:private) %><label for="topic_private"> Private</label>
0
+ &nbsp; <%= f.check_box(:locked) %><label for="topic_locked"> Locked</label>
0
     </p>
0
     <p class="label"><label for="topic_forum">Forum</label></p>
0
     <p>
...
6
7
8
9
 
10
11
12
...
6
7
8
 
9
10
11
12
0
@@ -6,7 +6,7 @@
0
     <p>
0
       <%= f.text_field :title, :style => "width:66%" %> &nbsp;
0
       <%= f.check_box(:private) %><label for="topic_private"> Private</label> &nbsp;
0
- <%= f.check_box(:closed) %><label for="topic_closed"> Closed</label>
0
+ <%= f.check_box(:locked) %><label for="topic_locked"> Locked</label>
0
     </p>
0
     <p>
0
       <%= submit_tag "Save Changes", :disable_with => "Save Changes" %> or
...
9
10
11
12
 
13
14
15
...
88
89
90
91
 
92
93
94
95
 
96
97
98
...
104
105
106
107
108
 
109
110
 
 
111
112
 
113
114
 
 
115
116
117
...
9
10
11
 
12
13
14
15
...
88
89
90
 
91
92
93
94
 
95
96
97
98
...
104
105
106
 
 
107
108
 
109
110
111
 
112
113
 
114
115
116
117
118
0
@@ -9,7 +9,7 @@
0
       &laquo; <%= link_to @topic.forum.name, forum_path(@topic.forum) %>
0
       &laquo; <%= link_to @topic.forum.category.name, category_path(@topic.forum.category) %>
0
       &nbsp;|&nbsp;
0
- <%= @topic.private? ? 'Private' : 'Public' %><%= @topic.closed? ? ', Closed' : '' %>
0
+ <%= @topic.private? ? 'Private' : 'Public' %><%= @topic.locked? ? ', Locked' : '' %>
0
     </span>
0
   </div>
0
   <div class="info-right">
0
@@ -88,11 +88,11 @@
0
           <% end %>
0
           
0
           <% if current_controller == 'search' %>
0
- <% if logged_in? && !post.topic.closed %>
0
+ <% if logged_in? && !post.topic.locked %>
0
               <%= link_to 'Quote', quote_post_path(post) %>
0
             <% end %>
0
           <% else %>
0
- <% if logged_in? && !@topic.closed %>
0
+ <% if logged_in? && !@topic.locked %>
0
               <%= link_to 'Quote', quote_post_path(post) %>
0
             <% end %>
0
           <% end %>
0
@@ -104,14 +104,15 @@
0
 <% end %>
0
 
0
 <% unless current_controller == 'search' %>
0
- <span id="reply"></span>
0
- <% if logged_in? && !@topic.closed %>
0
+ <% if logged_in? && (!@topic.locked || can_edit?(@topic)) %>
0
     <%= render :partial => 'posts/new' %>
0
- <% elsif logged_in? && @topic.closed %>
0
+ <% end %>
0
+ <% if @topic.locked && !can_edit?(@topic) %>
0
     <div class="nav nav-footer">
0
- <p class="nav-left">This Topic is Closed</p>
0
+ <p class="nav-right">This Topic is Locked</p>
0
     </div>
0
- <% else %>
0
+ <% end %>
0
+ <% if !logged_in? %>
0
     <div class="nav nav-footer">
0
       <p class="nav-right">
0
         <%= link_to('Login', login_path) %> or
...
2
3
4
5
 
6
7
8
...
147
148
149
150
 
151
152
153
...
2
3
4
 
5
6
7
8
...
147
148
149
 
150
151
152
153
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 61) do
0
+ActiveRecord::Schema.define(:version => 62) do
0
 
0
   create_table "avatars", :force => true do |t|
0
     t.integer "parent_id"
0
@@ -147,7 +147,7 @@ ActiveRecord::Schema.define(:version => 61) do
0
     t.datetime "last_post_at"
0
     t.integer "last_post_by"
0
     t.boolean "private", :default => false
0
- t.boolean "closed", :default => false
0
+ t.boolean "locked"
0
     t.boolean "sticky", :default => false
0
     t.integer "forum_id"
0
   end
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
222
223
224
 
 
 
 
225
226
227
...
206
207
208
 
209
210
211
212
213
214
 
215
216
217
...
220
221
222
223
224
225
226
227
228
229
0
@@ -206,14 +206,12 @@ tbody {
0
 tbody td {
0
   padding: 5px;
0
   vertical-align: top;
0
- vertical-align: middle;
0
   border-top: 1px solid #cedeb9;
0
   border-right: 1px solid #cedeb9;
0
 }
0
 
0
 tbody .tci {
0
   width: 10px !important;
0
- vertical-align: top;
0
   border-right: 0;
0
 }
0
 
0
@@ -222,6 +220,10 @@ tbody .tcm {
0
   background: #dedfdf;
0
 }
0
 
0
+.forums-index .tcm {
0
+ vertical-align: middle;
0
+}
0
+
0
 tbody .tcr {
0
   border-right: 0;
0
 }
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: avatars
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: bans
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: categories
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: events
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: forums
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: headers
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: options
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: posts
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: ranks
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: subscriptions
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: themes
0
 #
...
1
2
 
3
4
5
...
13
14
15
16
 
17
18
19
...
30
31
32
33
 
34
35
36
...
43
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
...
1
 
2
3
4
5
...
13
14
15
 
16
17
18
19
...
30
31
32
 
33
34
35
36
...
43
44
45
 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: topics
0
 #
0
@@ -13,7 +13,7 @@
0
 # last_post_at :datetime
0
 # last_post_by :integer(11)
0
 # private :boolean(1)
0
-# closed :boolean(1)
0
+# locked :boolean(1)
0
 # sticky :boolean(1)
0
 # forum_id :integer(11)
0
 #
0
@@ -30,7 +30,7 @@ Testing:
0
   last_post_at: <%= 1.week.ago.to_s :db %>
0
   last_post_by: 1
0
   private: 0
0
- closed: 0
0
+ locked: 0
0
   forum_id: 1
0
 Private:
0
   id: 2
0
@@ -43,5 +43,18 @@ Private:
0
   last_post_at: <%= 5.minutes.ago.to_s :db %>
0
   last_post_by: 2
0
   private: 1
0
- closed: 0
0
+ locked: 0
0
+ forum_id: 1
0
+Locked:
0
+ id: 3
0
+ user_id: 4
0
+ title: Private
0
+ created_at: <%= 5.days.ago.to_s :db %>
0
+ views: 31
0
+ posts_count: 1
0
+ last_post_id: 1
0
+ last_post_at: <%= 5.minutes.ago.to_s :db %>
0
+ last_post_by: 2
0
+ private: 1
0
+ locked: 1
0
   forum_id: 1
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: uploads
0
 #
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 # == Schema Information
0
-# Schema version: 61
0
+# Schema version: 62
0
 #
0
 # Table name: users
0
 #
...
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
...
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
0
@@ -92,4 +92,25 @@ class PostsControllerTest < Test::Unit::TestCase
0
     assert_redirected_to :controller => 'topics', :action => 'show', :id => '1', :page => '1'
0
   end
0
   
0
+ def test_should_not_allow_post_if_logged_in_and_locked
0
+ login_as :Timothy
0
+ old_post_count = Post.count
0
+ post :create, :post => { :topic_id => "3", :body => "this is a test" }
0
+ assert_equal old_post_count, Post.count
0
+ end
0
+
0
+ def test_should_allow_post_if_logged_in_and_locked_but_is_admin
0
+ login_as :Administrator
0
+ old_post_count = Post.count
0
+ post :create, :post => { :topic_id => "3", :body => "this is a test" }
0
+ assert_equal old_post_count+1, Post.count
0
+ end
0
+
0
+ def test_should_allow_post_if_logged_in_and_locked_but_is_topic_creator
0
+ login_as :trevor
0
+ old_post_count = Post.count
0
+ post :create, :post => { :topic_id => "3", :body => "this is a test" }
0
+ assert_equal old_post_count+1, Post.count
0
+ end
0
+
0
 end
...
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -38,4 +38,60 @@ class SearchControllerTest < Test::Unit::TestCase
0
     assert_response :success
0
   end
0
   
0
+ def test_avatars_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_events_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_files_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_headers_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_posts_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_topics_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_avatars_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
+ def test_users_search
0
+ # login_as :trevor
0
+ # get :index, :type => 'avatars', :query => 'test'
0
+ # assert_response :success
0
+ # assert_select "span#reply"
0
+ end
0
+
0
 end
...
204
205
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
208
...
204
205
206
207
208
209
210
211