liquid_feedback_frontend
view app/main/admin/_action/area_update.lua @ 1569:32b9e4070777
Do not show login link when logged in for units without privileges
| author | bsw | 
|---|---|
| date | Wed Nov 11 11:11:59 2020 +0100 (2020-11-11) | 
| parents | 32cc544d5a5b | 
| children | 
 line source
     1 local area = Area:by_id(param.get_id()) or Area:new()
     3 param.update(area, "unit_id", "name", "description", "external_reference", "quorum_standard", "quorum_issues", "quorum_time", "quorum_exponent", "quorum_factor", "active")
     5 if #area.name < 1 then
     6   slot.select("error", function()
     7     ui.tag{ content = _"Please choose an area name" }
     8   end)
     9   return false
    10 end
    12 area:save()
    14 param.update_relationship{
    15   param_name        = "allowed_policies",
    16   id                = area.id,
    17   connecting_model  = AllowedPolicy,
    18   own_reference     = "area_id",
    19   foreign_reference = "policy_id"
    20 }
    22 -- we have to update the default flag because update_relationship can't handle it
    23 local old_default = AllowedPolicy:new_selector()
    24 :add_where{ "allowed_policy.area_id = ? AND allowed_policy.default_policy = 't'", area.id }
    25 :optional_object_mode()
    26 :exec()
    28 if old_default then
    29   old_default.default_policy = false;
    30   old_default:save()
    31 end
    33 local default_policy_id = param.get("default_policy", atom.integer)
    35 if default_policy_id and default_policy_id ~= -1 then
    36   local pol = AllowedPolicy:new_selector()
    37   :add_where{ "allowed_policy.area_id = ? AND allowed_policy.policy_id = ?", area.id, default_policy_id }
    38   :optional_object_mode()
    39   :exec()
    40   if pol then
    41     pol.default_policy = true;
    42     pol:save()
    43   end
    44 end
