local app = require("lapis").Application() local db = require("lapis.db") local util = require("util") local models = require("models") local Users = models.Users -- everything here requires a logged in moderator app:before_filter(function(self) self.me = util.get_logged_in_user(self) if not self.me then self:write{redirect_to = self:url_for("all_topics")} return end if not self.me:is_mod() then self:write{redirect_to = self:url_for("all_topics")} return end end) app:get("user_list", "/list", function(self) self.users = Users:select("") return {render = "mod.user-list"} end) app:get("sort_topics", "/sort-topics", function(self) self.topics = db.query("SELECT * FROM topics ORDER BY sort_order ASC") self.page_title = "sorting topics" return {render = "mod.sort-topics"} end) app:post("sort_topics", "/sort-topics", function(self) local updates = self.params db.query("BEGIN") for topic_id, new_order in pairs(updates) do db.update("topics", {sort_order = new_order}, {id = topic_id}) end db.query("COMMIT") return {redirect_to = self:url_for("sort_topics")} end) return app