Permalink
Browse files

Merge branch 'master' of git://github.com/queso/signal-wiki into flag

Conflicts:

	app/models/user.rb
  • Loading branch information...
courtenay committed Mar 18, 2008
2 parents 8bc3f83 + 16ba557 commit 3a3e0dd1b1dec1f5919bb6df431bbe06e178e707
View
@@ -6,3 +6,6 @@ tmp/**/*
.DS_Store
doc/api
doc/app
+db/*.db
+db/*.sqlite3
+index/*
View
@@ -0,0 +1,19 @@
+Copyright (c) 2007-2008 Josh Owens
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
3 README
@@ -17,6 +17,7 @@ Enjoy :)
* json
* ruby-openid
-* redcloth
+* ruby-yadis
+* RedCloth
@@ -129,6 +129,18 @@ def destroy
end
end
+ def lock
+ @page = site.pages.find_by_permalink(params[:id])
+ if @page.locked?
+ @page.unlock
+ else
+ @page.lock
+ end
+ respond_to do |format|
+ format.html { redirect_to(wiki_page_url(@page)) }
+ format.xml { head :ok }
+ end
+ end
def check_private
@page = site.pages.find_by_permalink(params[:id])
@@ -2,7 +2,7 @@ module PagesHelper
def wikified_body(body)
r = RedCloth.new(body)
- r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|"))}
+ r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|")[0..1])}
r.to_html
end
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: attachments
#
View
@@ -1,3 +1,15 @@
+# == Schema Information
+# Schema version: 13
+#
+# Table name: links
+#
+# id :integer not null, primary key
+# from_page_id :integer
+# to_page_id :integer
+# created_at :datetime
+# updated_at :datetime
+#
+
class Link < ActiveRecord::Base
belongs_to :to_page, :class_name => "Page"
belongs_to :from_page, :class_name => "Page"
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: pages
#
@@ -12,6 +12,8 @@
# updated_at :datetime
# private_page :boolean
# version :integer
+# site_id :integer
+# locked :boolean
#
class Page < ActiveRecord::Base
@@ -20,6 +22,7 @@ class Page < ActiveRecord::Base
has_many :inbound_links, :class_name => "Link", :foreign_key => "to_page_id"
has_many :outbound_links, :class_name => "Link", :foreign_key => "from_page_id"
acts_as_versioned
+ self.non_versioned_columns << 'locked_at'
attr_accessor :ip, :agent, :referrer
acts_as_indexed :fields => [:title, :body, :author]
@@ -29,6 +32,7 @@ class Page < ActiveRecord::Base
before_update :set_links
after_create :set_links
validates_presence_of :title, :body
+ validate_on_update :updatable
def validate
if site.akismet_key? && is_spam?(site)
@@ -51,7 +55,7 @@ def request=(request)
def set_permalink
if self.permalink.blank?
- self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(' ', '-')}"
+ self.permalink = Page.count == 0 ? "home" : "#{title.downcase.strip.gsub(/ |\.|@/, '-')}"
end
end
@@ -60,12 +64,10 @@ def set_links
# outbound_links.delete_all
body.scan(/\[\[(.*?)\]\]/).each do |link|
link = link[0].downcase.gsub(' ', '-')
- $stderr.puts link.inspect
- logger.warn link.inspect
if page = site.pages.find_by_permalink(link)
Link.create! :from_page_id => id, :to_page_id => page.id
else
- raise "No page here"
+ logger.warn "We couldn't find links for #{link}"
end
end
end
@@ -79,9 +81,32 @@ def author
(user && user.login) ? user.login.to_s.capitalize : "Anonymous"
end
- def self.find_all_by_wiki_word(wiki_word)
+ def lock
+ self.without_revision do
+ self.update_attribute(:locked_at, Time.now)
+ end
+ RAILS_DEFAULT_LOGGER.info "LOCKED #{self.permalink}"
+ end
+
+ def unlock
+ self.without_revision do
+ self.update_attribute(:locked_at, nil)
+ end
+ RAILS_DEFAULT_LOGGER.info "UNLOCKED #{self.permalink}"
+ end
+
+ def self.find_all_by_wiki_word(wiki_word, site = nil)
+ site ||= Site.find(:first)
pages = site.pages.find(:all)
pages.select {|p| p.body =~ /#{wiki_word}/i}
end
+ private
+
+ def updatable
+ unless self.locked_at.nil?
+ errors.add("page", "is locked from editing.")
+ end
+ end
+
end
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: sites
#
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: users
#
@@ -23,7 +23,7 @@ class User < ActiveRecord::Base
attr_protected :admin
can_flag
- has_many :pages
+ has_many :pages, :order => 'title ASC'
validates_presence_of :login, :email, :if => :not_openid?
validates_presence_of :password, :if => :password_required?
@@ -10,7 +10,8 @@
<ul class="meta_info">
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.previous.version))) if @page.previous %></li>
<li><%= link_to('View next revision', revision_page_url(:id => @page.permalink, :version => (@page.next.version))) if @page.next %></li>
- <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version)%></li>
+ <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>
+ <%# FIXME Clean up this revision link logic %>
<li><%= link_to 'Return to current revision', wiki_page_url(@page.permalink) %></li>
</ul>
<% end -%>
@@ -1,4 +1,4 @@
-<h2><%=h @page.title %></h2>
+<h2 class="title"><%=h @page.title %></h2>
<div id="flag" title="<%= @page.class.name %>_<%= @page.id %>">Login or sign up to flag this page.</div>
@@ -9,10 +9,11 @@
<% content_for :right do -%>
<h5>Author: <%= author(@page.user_id) %></h5>
<ul class="meta_info">
- <li><%= link_to 'Edit this page', edit_page_path(@page) %></li>
+ <li><%= link_to 'Edit this page', edit_page_path(@page) unless @page.locked? && !current_user.admin? %></li>
+ <li><%= link_to((@page.locked? ? "Unlock this page" : "Lock this page"), lock_page_path(@page)) if logged_in? && current_user.admin? %></li>
+ <li><%= link_to "Delete this page and all revisions", page_path(@page), :method => :delete if logged_in? && current_user.admin? && @page.permalink != 'home' %></li>
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.version - 1) )) if (@page.versions.size > 1 && @page.version > 1) %></li>
<li><%= link_to 'Return to home', pages_path unless @page.permalink == "home" %></li>
- <li><%= link_to "Delete this page and all revisions", page_path(@page), :method => :delete %></li>
<li>Inbound links:
<ul>
<% @page.inbound_links.each do |link| -%>
View
@@ -6,7 +6,7 @@
map.resource :session
map.resource :site, :member => {:expire_cache => :get, :mark_all_private => :get}
map.resources :users
- map.resources :pages, :member => {:revision => :get, :rollback => :get}, :collection => {:search => :get}
+ map.resources :pages, :member => {:revision => :get, :rollback => :get, :lock => :get}, :collection => {:search => :get}
map.resources :attachments
map.login '/login', :controller => 'sessions', :action => 'new'
@@ -0,0 +1,9 @@
+class AddLockingToPages < ActiveRecord::Migration
+ def self.up
+ add_column :pages, :locked_at, :datetime
+ end
+
+ def self.down
+ remove_column :pages, :locked_at
+ end
+end
View
@@ -83,6 +83,7 @@
t.boolean "private_page"
t.integer "version"
t.integer "site_id"
+ t.datetime "locked_at"
end
create_table "sites", :force => true do |t|
View
No changes.
View
@@ -33,4 +33,35 @@
Link.count.should == c+1
#lambda{ @page2.save! }.should change { Link.count }.by(1)
end
+
+ it "creates a new empty wiki link" do
+ @page1.body = "New wiki test [[link]]"
+ @page1.save!
+ @page1.should be_valid
+ end
+
end
+
+describe Page, "locking pages" do
+ fixtures :sites
+
+ before do
+ @page1 = Page.create! :title => "outbound", :permalink => "outbound", :body => "empty", :site_id => 1
+ end
+
+ it "edit a locked page" do
+ @page1.lock
+ @page1.body = "Blah blah"
+ @page1.save
+ @page1.should_not be_valid
+ end
+
+ it "edit a previous locked but now unlocked page" do
+ @page1.lock
+ @page1.unlock
+ @page1.body = "Blah blah"
+ @page1.save
+ @page1.should be_valid
+ end
+
+end

0 comments on commit 3a3e0dd

Please sign in to comment.