Anonymous avatar Anonymous committed 134fce4

Cache for rendered wiki texts; Accountless API keys; Reverse id order for initiative API
- Support for caching html version of drafts
- Using pre-rendered html versions of help messages
- Added Support for api keys not connected to an account
- Added order option "id_desc" to initiative API

Comments (0)

Files changed (11)

Makefile

-default:
-
-
-translations-de:
-	cd ../webmcp/framework/bin/ && ./langtool.lua ~/workspace/liquid_feedback/locale/translations.de.lua ~/workspace/liquid_feedback/app ~/workspace/liquid_feedback/locale/translations.de.lua
-
 your webserver appropriatly.
 
 
+7. Compile help messages from wiki to html
+
+cd /opt/liquid_feedback_frontend/locale/help
+for file in *.txt; do /opt/rocketwiki-lqfb/rocketwiki-lqfb < $file > $file.html; done
+
+
+

app/main/api/_filter/00_api.lua

   error("No API key supplied.")
 end
 
-local setting_key = "liquidfeedback_frontend_api_key"
+local accepted = false
 
-local setting = Setting:new_selector()
-  :add_where{ "key = ?", setting_key }
-  :add_where{ "value = ?", api_key }
-  :join("member", nil, "member.id = setting.member_id")
-  :add_where("member.active")
-  :optional_object_mode()
-  :exec()
+if config.api_keys then
+  for i, config_api_key in ipairs(config.api_keys) do
+    if api_key == config_api_key then
+      accepted = true
+    end
+  end
+end
 
-if not setting then
+if not accepted then
+  local setting_key = "liquidfeedback_frontend_api_key"
+
+  local setting = Setting:new_selector()
+    :add_where{ "key = ?", setting_key }
+    :add_where{ "value = ?", api_key }
+    :join("member", nil, "member.id = setting.member_id")
+    :add_where("member.active")
+    :optional_object_mode()
+    :exec()
+
+  if setting then
+    accepted = true
+  end
+end
+
+if not accepted then
   error("Supplied API key is not valid.")
 end
 

app/main/api/initiative.lua

   initiatives_selector:add_order_by("initiative.supporter_count")
 end
 
-initiatives_selector:add_order_by("initiative.id")
+if order == "id_desc" then
+  initiatives_selector:add_order_by("initiative.id DESC")
+else
+  initiatives_selector:add_order_by("initiative.id")
+end
 
 if limit then
   initiatives_selector:limit(limit)

app/main/draft/_action/add.lua

   error("access denied")
 end
 
-local draft = Draft:new()
-draft.author_id = app.session.member.id
-draft.initiative_id = initiative.id
 local formatting_engine = param.get("formatting_engine")
+
 local formatting_engine_valid = false
 for fe, dummy in pairs(config.formatting_engine_executeables) do
   if formatting_engine == fe then
 if not formatting_engine_valid then
   error("invalid formatting engine!")
 end
+
+
+local draft = Draft:new()
+draft.author_id = app.session.member.id
+draft.initiative_id = initiative.id
 draft.formatting_engine = formatting_engine
 draft.content = param.get("content")
 draft:save()
 
+draft:render_content()
+
 slot.put_into("notice", _"New draft has been added to initiative")
 

app/main/draft/_show.lua

     ui.container{
       attr = { class = "draft_content wiki" },
       content = function()
-        slot.put(format.wiki_text(draft.content, draft.formatting_engine))
+        slot.put(draft:get_content("html"))
       end
     }
   end

app/main/initiative/_action/create.lua

   end
 end
 
-
-
 local name = param.get("name")
 
 local name = util.trim(name)
   return false
 end
 
+local formatting_engine = param.get("formatting_engine")
+
+local formatting_engine_valid = false
+for fe, dummy in pairs(config.formatting_engine_executeables) do
+  if formatting_engine == fe then
+    formatting_engine_valid = true
+  end
+end
+if not formatting_engine_valid then
+  error("invalid formatting engine!")
+end
+
+
+
 local initiative = Initiative:new()
 
 if not issue then
 
 local draft = Draft:new()
 draft.initiative_id = initiative.id
-local formatting_engine = param.get("formatting_engine")
-local formatting_engine_valid = false
-for fe, dummy in pairs(config.formatting_engine_executeables) do
-  if formatting_engine == fe then
-    formatting_engine_valid = true
-  end
-end
-if not formatting_engine_valid then
-  error("invalid formatting engine!")
-end
 draft.formatting_engine = formatting_engine
 draft.content = param.get("draft")
 draft.author_id = app.session.member.id

config/default.lua

 config.app_name = "LiquidFeedback"
-config.app_version = "beta21"
+config.app_version = "beta22"
 
 config.app_title = config.app_name .. " (" .. request.get_config_name() .. " environment)"
 

env/util/help.lua

         }
         local lang = locale.get("lang")
         local basepath = request.get_app_basepath() 
-        local file_name = basepath .. "/locale/help/" .. id .. "." .. lang .. ".txt"
+        local file_name = basepath .. "/locale/help/" .. id .. "." .. lang .. ".txt.html"
         local file = io.open(file_name)
         if file ~= nil then
           local help_text = file:read("*a")
             ui.container{
               attr = { class = "wiki" },
               content = function()
-                slot.put(format.wiki_text(help_text))
+                slot.put(help_text)
               end
             }
           else
 Draft = mondelefant.new_class()
 Draft.table = 'draft'
 
+-- Many drafts belonging to an initiative
 Draft:add_reference{
   mode          = 'm1',
   to            = "Initiative",
   ref           = 'initiative',
 }
 
+-- Many drafts are authored by a member
 Draft:add_reference{
   mode          = 'm1',
   to            = "Member",
   ref           = 'author',
 }
 
--- reference to supporter probably not needed
-
 function Draft.object_get:author_name()
   return self.author and self.author.name or _"Unknown author"
 end
+
+-- render draft to html, save it as rendered_draft and return it
+function Draft.object:render_content()
+  -- local draft for update
+  local draft_lock = Draft:new_selector()
+    :add_where{ "id = ?", self.id }
+    :single_object_mode()
+    :for_update()
+    :exec()
+  -- check if there is already a rendered draft
+  local rendered_draft = RenderedDraft:new_selector()
+    :add_where{ "draft_id = ?", self.id }
+    :add_where{ "format = 'html'" }
+    :optional_object_mode()
+    :exec()
+  if rendered_draft then
+    return rendered_draft
+  end
+  -- create rendered_draft record
+  local rendered_draft = RenderedDraft:new()
+  rendered_draft.draft_id = self.id
+  rendered_draft.format = "html"
+  rendered_draft.content = format.wiki_text(self.content, self.formatting_engine)
+  rendered_draft:save()
+  -- and return it
+  return rendered_draft
+end
+
+-- returns rendered version of draft for specific format
+function Draft.object:get_content(format)
+  -- Fetch rendered_draft record for specified format
+  local rendered_draft = RenderedDraft:new_selector()
+    :add_where{ "draft_id = ?", self.id }
+    :add_where{ "format = ?", format }
+    :optional_object_mode()
+    :exec()
+  -- If this format isn't rendered yet, render it
+  if not rendered_draft then
+    rendered_draft = self:render_content()
+  end
+  -- return rendered content
+  return rendered_draft.content
+end

model/rendered_draft.lua

+RenderedDraft = mondelefant.new_class()
+RenderedDraft.table = 'rendered_draft'
+RenderedDraft.primary_key = { "draft_id", "format" }
+
+RenderedDraft:add_reference{
+  mode          = 'm1',
+  to            = "Draft",
+  this_key      = 'draft_id',
+  that_key      = 'id',
+  ref           = 'draft',
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.