liquid_feedback_frontend
view app/main/delegation/_action/update.lua @ 1858:3d1f0464a3ea
Handle missing ldap.member.allowed function
| author | bsw | 
|---|---|
| date | Tue Sep 20 17:35:29 2022 +0200 (2022-09-20) | 
| parents | 72442abafb3c | 
| children | 
 line source
     1 if config.disable_delegations then
     2   return
     3 end
     5 local truster_id = app.session.member.id
     7 local trustee_id = param.get("trustee_id", atom.integer)
     9 local unit_id = param.get("unit_id", atom.integer)
    11 local area_id = param.get("area_id", atom.integer)
    13 local issue_id = param.get("issue_id", atom.integer)
    15 local initiative_id = param.get("initiative_id", atom.integer)
    17 if issue_id then 
    18   area_id = nil
    19 end
    21 local preview = param.get("preview") 
    23 if preview == "1" then
    24   request.redirect{ module = "delegation", view = "show", params = {
    25     unit_id = unit_id, area_id = area_id, issue_id = issue_id, initiative_id = initiative_id, preview_trustee_id = trustee_id
    26   } }
    27   return
    28 end
    30 local delegation = Delegation:by_pk(truster_id, unit_id, area_id, issue_id)
    33 if param.get("delete") or trustee_id == -1 then
    35   if delegation then
    36     delegation:destroy()
    37   end
    39 else
    41   local trustee
    43   if trustee_id then
    44     trustee = Member:by_id(trustee_id)
    45   end
    47   local check_unit_id
    48   if unit_id then
    49     check_unit_id = unit_id
    50   elseif area_id then
    51     local area = Area:by_id(area_id)
    52     check_unit_id = area.unit_id
    53   else
    54     local issue = Issue:by_id(issue_id)
    55     local area = Area:by_id(issue.area_id)
    56     check_unit_id = area.unit_id
    57   end
    59   if trustee and not (
    60     trustee:has_voting_right_for_unit_id(check_unit_id)
    61     or trustee:has_initiative_right_for_unit_id(check_unit_id)
    62   ) then
    63     slot.put_into("error", _"Trustee has no voting right in this unit")
    64     return false
    65   end
    67   if not (
    68     app.session.member:has_voting_right_for_unit_id(check_unit_id) 
    69     or app.session.member:has_initiative_right_for_unit_id(check_unit_id) 
    70   ) then
    71     return execute.view { module = "index", view = "403" }
    72   end
    74   if not delegation then
    75     delegation = Delegation:new()
    76     delegation.truster_id = truster_id
    77     delegation.unit_id    = unit_id
    78     delegation.area_id    = area_id
    79     delegation.issue_id   = issue_id
    80     if issue_id then
    81       delegation.scope = "issue"
    82     elseif area_id then
    83       delegation.scope = "area"
    84     elseif unit_id then
    85       delegation.scope = "unit"
    86     end
    87   end
    88   if trustee_id == 0 then
    89     delegation.trustee_id = nil
    90   else
    91     delegation.trustee_id = trustee_id
    92   end
    94   delegation:save()
    96 end
