Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ability to lock topics. Fixes #87.

  • Loading branch information...
commit 4e4a20f5070c59a7d25041a08d25a8c8d3b98bae 1 parent 337c027
@polarina authored
View
6 app/helpers/forums_helper.rb
@@ -40,7 +40,11 @@ def forums_overview(topics, options = {})
haml_tag :tbody do
topics.each do |topic|
haml_tag :tr do
- haml_tag :td, (topic.last_post_read == topic.last_post_id ? "" : "Nei")
+ haml_tag :td do
+ haml_concat (topic.last_post_read == topic.last_post_id ? "" : "Nei")
+ haml_concat ", læst" if topic.locked
+ end
+
haml_tag :td, (link_to topic.subject, forum_topic_path(@forum, topic))
haml_tag :td, topic.posts_count
haml_tag :td, (link_to topic.username, user_path(topic.username))
View
4 app/models/topic.rb
@@ -6,7 +6,8 @@ class Topic < ActiveRecord::Base
has_many :posts, :dependent => :destroy
attr_accessible :subject,
- :sticky
+ :sticky,
+ :locked
validates :subject,
:length => { :within => 5..48 }
@@ -28,6 +29,7 @@ def self.overview(current_user)
id,
forum_id,
subject,
+ locked,
user.username.as(username),
t1.count.as(posts_count),
t2.post_id.as(last_post_read),
View
29 app/models/user.rb
@@ -95,17 +95,24 @@ def inst(klass, something)
"page" => true,
},
"posts" => {
- "create" => true,
+ "create" => Proc.new do
+ topic = inst Topic, params[:topic_id]
+ not topic.locked
+ end,
"destroy" => Proc.new do
+ topic = inst Topic, params[:topic_id]
post = inst Post, params[:id]
post_topic_id = post.topic_id
oldest = Post.limit(1).select{id}.where{topic_id == post_topic_id}.order{created_at.asc}
newest = Post.limit(1).select{id}.where{topic_id == post_topic_id}.order{created_at.desc}
- post.user_id == self.id and newest.first.id == post.id and oldest.first.id != post.id
+ (not topic.locked) and post.user_id == self.id and newest.first.id == post.id and oldest.first.id != post.id
+ end,
+ "update" => Proc.new do
+ topic = inst Topic, params[:topic_id]
+ (not topic.locked) and inst(Post, params[:id]).user_id == self.id
end,
- "update" => Proc.new { inst(Post, params[:id]).user_id == self.id },
},
"profiles" => {
"show" => true,
@@ -118,15 +125,22 @@ def inst(klass, something)
"create" => true,
"destroy" => Proc.new do
topic = Topic.find params[:id]
- topic.user_id == self.id and topic.posts.limit(2).count <= 1
+ (not topic.locked) and topic.user_id == self.id and topic.posts.limit(2).count <= 1
end,
"show" => true,
"update" => Proc.new do
- if params[:topic] and params[:topic][:sticky]
- next false unless params[:topic][:sticky] == "false"
+ if params[:topic]
+ if params[:topic][:sticky]
+ next false unless params[:topic][:sticky] == "false"
+ end
+
+ if params[:topic][:locked]
+ next false unless params[:topic][:locked] == "false"
+ end
end
- inst(Topic, params[:id]).user_id == self.id
+ topic = inst(Topic, params[:id])
+ (not topic.locked) and topic.user_id == self.id
end,
},
"torrents" => {
@@ -175,6 +189,7 @@ def inst(klass, something)
"update" => true,
},
"posts" => {
+ "create" => true,
"destroy" => Proc.new do
post = inst Post, params[:id]
post_topic_id = post.topic_id
View
5 app/views/topics/_form.html.haml
@@ -26,5 +26,10 @@
= f.label :sticky, "Sticky"
= f.select :sticky, [["", true], ["Nei", false]]
+ - link :topics, :update, :id => @topic, :topic => { :locked => "true" } do
+ %div
+ = f.label :locked, "Læst"
+ = f.select :locked, [["", true], ["Nei", false]]
+
%div
= f.submit "Vista"
View
6 app/views/topics/show.html.haml
@@ -15,14 +15,14 @@
- message :user => post.user, :created_at => post.created_at, :content => post do
- link :reports, :new, :post => post.id do
%li= link_to "Tilkynna", new_report_path(:post => post.id)
- - link :posts, :new, :quote => post.id do
+ - link :posts, :new, :topic_id => @topic, :quote => post.id do
%li= link_to "Tilvitna", new_forum_topic_post_path(@forum, @topic, :quote => post.id)
- - link :posts, :edit, :id => post do
+ - link :posts, :edit, :topic_id => @topic, :id => post do
- if post == @first_post
%li= link_to "Breyta", edit_forum_topic_path(@forum, @topic)
- else
%li= link_to "Breyta", edit_forum_topic_post_path(@forum, @topic, post)
- - link :posts, :destroy, :id => post do
+ - link :posts, :destroy, :topic_id => @topic, :id => post do
%li= link_to "Eyða", forum_topic_post_path(@forum, @topic, post), :confirm => "Ertu viss um að þú viljir eyða þessu innleggi?", :method => :delete
.section.headrepeat
View
5 db/migrate/20111015223200_add_locked_to_topics.rb
@@ -0,0 +1,5 @@
+class AddLockedToTopics < ActiveRecord::Migration
+ def change
+ add_column :topics, :locked, :boolean, :default => false, :null => false
+ end
+end
View
3  db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111014204000) do
+ActiveRecord::Schema.define(:version => 20111015223200) do
create_table "bans", :force => true do |t|
t.datetime "created_at", :null => false
@@ -182,6 +182,7 @@
t.integer "user_id", :null => false
t.string "subject", :null => false
t.boolean "sticky", :default => false, :null => false
+ t.boolean "locked", :default => false, :null => false
end
add_index "topics", ["forum_id", "sticky"], :name => "index_topics_on_forum_id_and_sticky"
Please sign in to comment.
Something went wrong with that request. Please try again.