public
Description: The easy to use rails wiki
Homepage: http://signalwiki.com
Clone URL: git://github.com/queso/signal-wiki.git
Adding the patches from ENTP.  Also fixed some bad page locking logic and tests.
queso (author)
Wed Apr 16 23:51:16 -0700 2008
commit  97e1874d38dc94079b9205b3cba0b341b3085fc5
tree    2acd64707634af291fae9a4b9e198c65760ec840
parent  ef22344ab94f249f9318c5e5bf5d93e436364d38
...
15
16
17
 
 
 
 
18
...
15
16
17
18
19
20
21
22
0
@@ -15,4 +15,8 @@ class ApplicationController < ActionController::Base
0
     @site ||= Site.find(:first)
0
   end
0
   
0
+  def require_admin
0
+    redirect_to(page_path('home')) unless logged_in? && current_user.admin?
0
+  end
0
+  
0
 end
...
5
6
7
8
 
9
10
11
...
13
14
15
16
 
17
18
19
...
5
6
7
 
8
9
10
11
...
13
14
15
 
16
17
18
19
0
@@ -5,7 +5,7 @@ class FlagsController < ApplicationController
0
   before_filter :admin_required, :only => :index
0
 protected
0
   def admin_required
0
-    raise AccessDenied unless current_user.admin?
0
+    redirect_to new_session_path unless current_user.admin?
0
   end
0
 
0
 public
0
@@ -13,7 +13,7 @@ public
0
   # collection methods
0
 
0
   def create
0
-    flag = current_user.flags.create! params[:flag]
0
+    flag = current_user.flags.create!(params[:flag])
0
     flash[:notice] = if flag.new_record?
0
       "You already flagged this content!"
0
     else # success
...
1
2
 
 
3
4
5
...
1
 
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 class PagesController < ApplicationController
0
-  before_filter :require_login, :except => [:index, :show, :revision]
0
+  before_filter :require_login, :except => [:index, :show, :revision, :search]
0
+  before_filter :require_admin, :only => [:lock]
0
   before_filter :check_private, :only => [:show, :revision]
0
   caches_page :show
0
   cache_sweeper :page_sweeper, :only => [:create, :update]
...
2
3
4
5
6
 
 
7
8
9
...
20
21
22
 
 
 
 
23
24
 
25
26
 
27
28
29
...
2
3
4
 
 
5
6
7
8
9
...
20
21
22
23
24
25
26
27
 
28
29
 
30
31
32
33
0
@@ -2,8 +2,8 @@ module PagesHelper
0
   
0
   def wikified_body(body)
0
     r = RedCloth.new(body)
0
-    r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|")[0..1])}
0
-    r.to_html
0
+    r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) }
0
+    sanitize r.to_html
0
   end
0
   
0
   def wiki_link(wiki_words, link_text = nil)
0
@@ -20,10 +20,14 @@ module PagesHelper
0
   end
0
   
0
   def body_input(f)
0
+    text_input(f, 'body')
0
+  end
0
+  
0
+  def text_input(f, attr)
0
     if site.disable_teh
0
-      f.text_area :body
0
+      f.text_area attr.to_sym
0
     else
0
-      textile_editor 'page', 'body'
0
+      textile_editor 'page', attr
0
     end
0
   end
0
   
...
89
90
91
92
 
 
 
 
 
93
94
95
...
89
90
91
 
92
93
94
95
96
97
98
99
0
@@ -89,7 +89,11 @@ class Page < ActiveRecord::Base
0
   end
0
   
0
   def locked?
0
-    locked_at.nil? or locked_at > Time.now
0
+    if locked_at.nil?
0
+      return false
0
+    else
0
+      locked_at < Time.now
0
+    end
0
   end
0
   
0
   def unlock
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@
0
   <tbody>
0
     <% @flags.each do |flag| %>
0
     <tr class="<%= cycle('alternate','') %>">
0
-      <td><%=h flag.created_at.to_s :short %></td>
0
+      <td><%=h flag.created_at.to_s(:short) %></td>
0
       <td><%=h flag.user.login %> (<%=h flag.user.flags.size %>)</td>
0
       <td><%= link_to h('%s %i' % [flag.flaggable_type, flag.flaggable_id]), flag.flaggable %></td>
0
       <td><%= flag.owner ? (link_to h(flag.owner.login), flag.owner) : "Anonymous" %></td>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
 
0
   <p>
0
     <label for="body">Body</label><br />
0
-  <%= body_input(f) %>
0
+    <%= body_input(f) %>
0
   </p>
0
 
0
   <p>
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@
0
 <ul class="meta_info">
0
   <li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.previous.version))) if @page.previous %></li>
0
   <li><%= link_to('View next revision', revision_page_url(:id => @page.permalink, :version => (@page.next.version))) if @page.next %></li>
0
-  <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && !current_user.admin?) %></li>
0
+  <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && (logged_in? && !current_user.admin?)) %></li>
0
   <%# FIXME Clean up this revision link logic %>
0
   <li><%= link_to 'Return to current revision', wiki_page_url(@page.permalink) %></li>
0
 </ul>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
0
@@ -0,0 +1,75 @@
0
+require File.dirname(__FILE__) + "/../spec_helper"
0
+
0
+describe FlagsController, "a user not logged in" do
0
+  fixtures :sites, :users, :pages
0
+  integrate_views
0
+  
0
+  before do
0
+    controller.stub!(:logged_in?).and_return false
0
+    controller.stub!(:current_user).and_return :false
0
+  end
0
+  
0
+  it "does not render 'index'" do
0
+    get :index
0
+    response.should redirect_to('session/new')
0
+  end
0
+  
0
+  it 'can not flag something' do
0
+    post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated' }
0
+    response.should redirect_to('session/new')
0
+  end
0
+end
0
+
0
+describe FlagsController, "a user logged in as normal user" do
0
+  fixtures :sites, :pages, :page_versions, :users
0
+  integrate_views
0
+  
0
+  before do
0
+    # Mocking this was a bitch.
0
+    @user = users(:jeremy)
0
+    
0
+    controller.stub!(:require_login)
0
+    controller.stub!(:logged_in?).and_return true
0
+    controller.stub!(:current_user).and_return @user
0
+  end
0
+  
0
+  it "does not render 'index'" do
0
+    get :index
0
+    response.should redirect_to('session/new')
0
+  end
0
+  
0
+  it 'can flag something' do
0
+    lambda {
0
+      post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+      response.should redirect_to('pages/hai')
0
+    }.should change(Flag, :count).by(1)
0
+  end
0
+end
0
+
0
+
0
+describe FlagsController, "a user logged in as admin" do
0
+  fixtures :sites, :pages, :page_versions, :users
0
+  integrate_views
0
+  
0
+  before do
0
+    @user = users(:admin)
0
+    controller.stub!(:require_login)
0
+    controller.stub!(:logged_in?).and_return true
0
+    controller.stub!(:current_user).and_return @user
0
+  end
0
+  
0
+  it "renders 'index'" do
0
+    get :index
0
+    response.should be_success
0
+    response.should render_template("index")    
0
+  end
0
+  
0
+  it 'can flag something' do
0
+    lambda {
0
+      post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+      response.should redirect_to('pages/hai')
0
+    }.should change(Flag, :count).by(1)
0
+  end
0
+  
0
+end
0
+
...
2
3
4
 
5
6
...
2
3
4
5
6
7
0
@@ -2,5 +2,6 @@
0
 first:
0
   id: 1
0
   title: RoR
0
+  require_login_to_post: 1
0
   created_at: 2008-03-15 10:28:00
0
   updated_at: 2008-03-15 10:28:00
...
46
47
48
49
 
50
51
52
 
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
60
61
62
...
46
47
48
 
49
50
51
 
52
53
54
55
56
57
58
 
59
60
61
62
63
64
65
66
67
68
69
0
@@ -46,17 +46,24 @@ describe Page, "locking pages" do
0
   fixtures :sites
0
   
0
   before do
0
-    @page1 = Page.create! :title => "outbound", :permalink => "outbound", :body => "empty", :site_id => 1
0
+    @page1 = Page.create! :title => "outbound", :permalink => "outbound", :body => "empty", :site_id => sites(:first).id
0
   end
0
   
0
-  it "edit a locked page" do
0
+  it "edits a locked page" do
0
     @page1.lock
0
     @page1.body = "Blah blah"
0
     @page1.save
0
     @page1.should_not be_valid
0
   end
0
   
0
-  it "edit a previous locked but now unlocked page" do
0
+  it "sets locked correctly" do
0
+    @page1.lock
0
+    @page1.should be_locked
0
+    @page1.unlock
0
+    @page1.should_not be_locked
0
+  end
0
+  
0
+  it "edits a previous locked but now unlocked page" do
0
     @page1.lock
0
     @page1.unlock
0
     @page1.body = "Blah blah"

Comments