add topic moving option for mods
This commit is contained in:
parent
8e646666d1
commit
cf66336e78
@ -94,6 +94,7 @@ app:get("thread", "/:slug", function(self)
|
||||
"WHERE posts.thread_id = ? ORDER BY posts.created_at ASC LIMIT ? OFFSET ?")
|
||||
local posts = db.query(query, thread.id, POSTS_PER_PAGE, (self.page - 1) * POSTS_PER_PAGE)
|
||||
self.topic = Topics:find(thread.topic_id)
|
||||
self.other_topics = db.query("SELECT topics.id, topics.name FROM topics")
|
||||
self.me = util.get_logged_in_user_or_transient(self)
|
||||
self.posts = posts
|
||||
|
||||
@ -169,4 +170,40 @@ app:post("thread_sticky", "/:slug/sticky", function(self)
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end)
|
||||
|
||||
app:post("thread_move", "/:slug/move", function(self)
|
||||
local user = util.get_logged_in_user(self)
|
||||
if not user then
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
|
||||
if not user:is_mod() then
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
|
||||
if not self.params.new_topic_id then
|
||||
util.inject_err_infobox(self, "Thread already in this topic.")
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
|
||||
local new_topic = Topics:find({id = self.params.new_topic_id})
|
||||
if not new_topic then
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
local thread = Threads:find({slug = self.params.slug})
|
||||
if not thread then
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
if new_topic.id == thread.topic_id then
|
||||
util.inject_err_infobox(self, "Thread already in this topic.")
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end
|
||||
|
||||
local old_topic = Topics:find({id = thread.topic_id})
|
||||
|
||||
thread:update({topic_id = new_topic.id})
|
||||
util.inject_infobox(self, ("Thread moved from \"%s\" to \"%s\"."):format(old_topic.name, new_topic.name))
|
||||
|
||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||
end)
|
||||
|
||||
return app
|
||||
|
@ -25,6 +25,15 @@
|
||||
<input type=hidden value="<%= not is_stickied %>" name="target_op">
|
||||
<input class="warn" type="submit" value="<%= is_stickied and "Unsticky thread" or "Sticky thread" %>">
|
||||
</form>
|
||||
<form class="modform" action="<%= url_for("thread_move", {slug = thread.slug}) %>" method="post">
|
||||
<label for="new_topic_id">Move to topic:</label>
|
||||
<select style="width:200px;" id="new_topic_id" name="new_topic_id" autocomplete="off">
|
||||
<% for _, topic in ipairs(other_topics) do %>
|
||||
<option value="<%= topic.id %>" <%- thread.topic_id == topic.id and "selected disabled" or "" %>><%= topic.name %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
<input class="warn" type="submit" value="Move thread">
|
||||
</form>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user