liquid_feedback_frontend

diff app/main/initiative/_action/create.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents 9604ba51624a
children
line diff
     1.1 --- a/app/main/initiative/_action/create.lua	Thu Jun 23 03:30:57 2016 +0200
     1.2 +++ b/app/main/initiative/_action/create.lua	Sun Jul 15 14:07:29 2018 +0200
     1.3 @@ -25,7 +25,7 @@
     1.4  end
     1.5  
     1.6  if not app.session.member:has_voting_right_for_unit_id(area.unit_id) then
     1.7 -  error("access denied")
     1.8 +  return execute.view { module = "index", view = "403" }
     1.9  end
    1.10  
    1.11  local policy_id = param.get("policy_id", atom.integer)
    1.12 @@ -44,15 +44,15 @@
    1.13      return false
    1.14    end
    1.15    if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    1.16 -    error("no polling right for this unit")
    1.17 +    return execute.view { module = "index", view = "403" }
    1.18    end
    1.19 -  
    1.20    if not area:get_reference_selector("allowed_policies")
    1.21      :add_where{ "policy.id = ?", policy_id }
    1.22      :optional_object_mode()
    1.23      :exec()
    1.24    then
    1.25 -    error("policy not allowed")
    1.26 +    slot.put_into("error", "policy not allowed")
    1.27 +    return false
    1.28    end
    1.29  end
    1.30  
    1.31 @@ -82,22 +82,6 @@
    1.32    return false
    1.33  end
    1.34  
    1.35 -local formatting_engine
    1.36 -if config.enforce_formatting_engine then
    1.37 -  formatting_engine = config.enforce_formatting_engine
    1.38 -else
    1.39 -  formatting_engine = param.get("formatting_engine")
    1.40 -  local formatting_engine_valid = false
    1.41 -  for i, fe in ipairs(config.formatting_engines) do
    1.42 -    if formatting_engine == fe.id then
    1.43 -      formatting_engine_valid = true
    1.44 -    end
    1.45 -  end
    1.46 -  if not formatting_engine_valid then
    1.47 -    error("invalid formatting engine!")
    1.48 -  end
    1.49 -end
    1.50 -
    1.51  local timing
    1.52  if not issue and policy.free_timeable then
    1.53    local free_timing_string = util.trim(param.get("free_timing"))
    1.54 @@ -109,7 +93,8 @@
    1.55    if config.free_timing and config.free_timing.available_func then
    1.56      available_timings = config.free_timing.available_func(policy)
    1.57      if available_timings == false then
    1.58 -      error("error in free timing config")
    1.59 +      slot.put_into("error", "error in free timing config")
    1.60 +      return false
    1.61      end
    1.62    end
    1.63    if available_timings then
    1.64 @@ -126,10 +111,39 @@
    1.65    end
    1.66    timing = config.free_timing.calculate_func(policy, free_timing_string)
    1.67    if not timing then
    1.68 -    error("error in free timing config")
    1.69 +    slot.put_into("error", "error in free timing config")
    1.70 +    return false
    1.71    end
    1.72  end
    1.73  
    1.74 +local draft_text = param.get("draft")
    1.75 +
    1.76 +if not draft_text then
    1.77 +  return false
    1.78 +end
    1.79 +
    1.80 +local draft_text = util.wysihtml_preproc(draft_text)
    1.81 +
    1.82 +local valid_html, error_message = util.html_is_safe(draft_text)
    1.83 +if not valid_html then
    1.84 +  slot.put_into("error", _("Draft contains invalid formatting or character sequence: #{error_message}", { error_message = error_message }) )
    1.85 +  return false
    1.86 +end
    1.87 +
    1.88 +if config.initiative_abstract then
    1.89 +  local abstract = param.get("abstract")
    1.90 +  if not abstract then
    1.91 +    return false
    1.92 +  end
    1.93 +  abstract = encode.html(abstract)
    1.94 +  draft_text = abstract .. "<!--END_OF_ABSTRACT-->" .. draft_text
    1.95 +end
    1.96 +
    1.97 +local location = param.get("location")
    1.98 +if location == "" then
    1.99 +  location = nil
   1.100 +end
   1.101 +
   1.102  if param.get("preview") or param.get("edit") then
   1.103    return
   1.104  end
   1.105 @@ -177,7 +191,8 @@
   1.106  local draft = Draft:new()
   1.107  draft.initiative_id = initiative.id
   1.108  draft.formatting_engine = formatting_engine
   1.109 -draft.content = param.get("draft")
   1.110 +draft.content = draft_text
   1.111 +draft.location = location
   1.112  draft.author_id = app.session.member.id
   1.113  draft:save()
   1.114  

Impressum / About Us