liquid_feedback_frontend

changeset 1536:feeac2fd945e

merge
author bsw
date Tue Oct 06 19:31:38 2020 +0200 (2020-10-06)
parents 770ab0a7f79b 0d9bb3937310
children 1e5c1edf7388
files app/main/draft/new.lua
line diff
     1.1 --- a/app/main/_prefork/10_init.lua	Tue Oct 06 19:31:19 2020 +0200
     1.2 +++ b/app/main/_prefork/10_init.lua	Tue Oct 06 19:31:38 2020 +0200
     1.3 @@ -237,5 +237,21 @@
     1.4    max_fork = 1
     1.5  }
     1.6  
     1.7 +if config.firstlife_groups then
     1.8 +  assert(loadcached(encode.file_path(WEBMCP_BASE_PATH, "lib", "firstlife", "groups.lua")))()
     1.9 +  listen{
    1.10 +    {
    1.11 +      proto = "interval",
    1.12 +      name  = "send_pending_notifications",
    1.13 +      delay = 5,
    1.14 +      handler = function()
    1.15 +        firstlife_mirror_groups()
    1.16 +      end
    1.17 +    },
    1.18 +    min_fork = 1,
    1.19 +    max_fork = 1
    1.20 +  }
    1.21 +end
    1.22 +
    1.23  execute.inner()
    1.24  
     2.1 --- a/app/main/draft/new.lua	Tue Oct 06 19:31:19 2020 +0200
     2.2 +++ b/app/main/draft/new.lua	Tue Oct 06 19:31:38 2020 +0200
     2.3 @@ -12,6 +12,13 @@
     2.4    if area_id then
     2.5      area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
     2.6      area:load_delegation_info_once_for_member_id(app.session.member_id)
     2.7 +  else
     2.8 +    local firstlife_id = param.get("firstlife_id")
     2.9 +    if firstlife_id then
    2.10 +      area = Area:new_selector():join("unit", nil, "unit.id = area.unit_id"):add_where{"attr->>'firstlife_id'=?",firstlife_id}:single_object_mode():exec()
    2.11 +      area:load_delegation_info_once_for_member_id(app.session.member_id)
    2.12 +      area_id = area.id
    2.13 +    end
    2.14    end
    2.15  end
    2.16  
     3.1 --- a/app/main/index/_head.lua	Tue Oct 06 19:31:19 2020 +0200
     3.2 +++ b/app/main/index/_head.lua	Tue Oct 06 19:31:38 2020 +0200
     3.3 @@ -135,6 +135,9 @@
     3.4      if unit.description and #(unit.description) > 0 then
     3.5        ui.container{ attr = { class = "mdl-card__supporting-text mdl-card--border" }, content = unit.description }
     3.6      end
     3.7 +    if config.render_external_reference_unit then
     3.8 +      config.render_external_reference_unit(unit)
     3.9 +    end
    3.10      --ui.container{ attr = { class = "mdl-card__actions mdl-card--border" }, content = function()
    3.11      --end }
    3.12    end }
     4.1 --- a/app/main/member/show.lua	Tue Oct 06 19:31:19 2020 +0200
     4.2 +++ b/app/main/member/show.lua	Tue Oct 06 19:31:38 2020 +0200
     4.3 @@ -63,7 +63,12 @@
     4.4  
     4.5  ui.grid{ content = function()
     4.6    ui.cell_main{ content = function()
     4.7 +
     4.8      ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
     4.9 + 
    4.10 +      if app.session.member_id == member.id then
    4.11 +        execute.view{ module = "index", view = "_lang_chooser" }
    4.12 +      end
    4.13        
    4.14        ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
    4.15          ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = function()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/lib/firstlife/groups.lua	Tue Oct 06 19:31:38 2020 +0200
     5.3 @@ -0,0 +1,114 @@
     5.4 +local function firstlife_mirror_group_users(unit)
     5.5 +  local url = config.firstlife_groups.api_base_url .. "v6/fl/Things/" .. unit.attr.firstlife_id .. "/participants"
     5.6 +  
     5.7 +  local output, err, status = extos.pfilter(doc, "curl", "-X", "GET", "-H", "Content-Type: application/json", "-d", "@-", url)
     5.8 +  
     5.9 +  local data = json.import(output)
    5.10 +
    5.11 +  local old_privileges_list = Privilege:new_selector()
    5.12 +    :add_where{ "unit_id = ?", unit.id }
    5.13 +    :exec()
    5.14 +
    5.15 +  local old_privileges = {}
    5.16 +  for i, old_privilege in ipairs(old_privileges_list) do
    5.17 +    old_privileges[old_privilege.member_id] = old_privilege
    5.18 +  end
    5.19 +
    5.20 +  local new_user_hash = {}
    5.21 +
    5.22 +  for i, user in ipairs(data) do
    5.23 +--    print("  Processing user ID " .. user.id)
    5.24 +    local user_id = tonumber(string.match(user.id, "^(.+)@"))
    5.25 +    new_user_hash[user_id] = user
    5.26 +    if old_privileges[user_id] then
    5.27 +--      print("    Privilege entry exists")
    5.28 +    else
    5.29 +--      print("    Creating new privilege")
    5.30 +      local privilege = Privilege:new()
    5.31 +      privilege.unit_id = unit.id
    5.32 +      privilege.member_id = user_id
    5.33 +      privilege.initiative_right = true
    5.34 +      privilege.voting_right = true
    5.35 +      privilege.weight = 1
    5.36 +      privilege:save()
    5.37 +    end
    5.38 +  end
    5.39 +
    5.40 +  for i, old_privilege in ipairs(old_privileges_list) do
    5.41 +    if not new_user_hash[old_privilege.member_id] then
    5.42 +--      print("  Destroying privilege for user ID " .. old_privilege.member_id)
    5.43 +      old_privilege:destroy()
    5.44 +    end
    5.45 +  end
    5.46 +
    5.47 +end
    5.48 +
    5.49 +function _G.firstlife_mirror_groups()
    5.50 +
    5.51 +
    5.52 +  local url = config.firstlife_groups.api_base_url .. "v6/fl/Things/search?types=CO3_ACA"
    5.53 +  
    5.54 +  local output, err, status = extos.pfilter(doc, "curl", "-X", "GET", "-H", "Content-Type: application/json", "-d", "@-", url)
    5.55 +  
    5.56 +  local data = json.import(output)
    5.57 +
    5.58 +  if not data then return end
    5.59 +  if not data.things then return end
    5.60 +  if data.things.type ~= "FeatureCollection" then return end
    5.61 +  if not data.things.features then return end
    5.62 +  if json.type(data.things.features) ~= "array" then return end
    5.63 +
    5.64 +  local units_new = {}
    5.65 +
    5.66 +  for i, feature in ipairs(data.things.features) do
    5.67 +--    print(feature.id, feature.properties.name)
    5.68 +    units_new[feature.id] = feature
    5.69 +  end
    5.70 +
    5.71 +  local old_units_list = Unit:new_selector()
    5.72 +    :add_where("attr->'firstlife_id' NOTNULL")
    5.73 +    :exec()
    5.74 +
    5.75 +  local old_units = {}
    5.76 +
    5.77 +  for i, old_unit in ipairs(old_units_list) do
    5.78 +    old_units[old_unit.attr.firstlife_id] = old_unit
    5.79 +  end
    5.80 +
    5.81 +  for id, unit_new in pairs(units_new) do
    5.82 +    local name_new = unit_new.properties.name
    5.83 +    local unit
    5.84 +--    print("Processing unit ID " .. id .. " with name " .. name_new)
    5.85 +    if old_units[id] then
    5.86 +      unit = old_units[id]
    5.87 +--      print("  Unit already exists")
    5.88 +      if old_units[id].name == name_new then
    5.89 +--        print("  Name not changed")
    5.90 +      else
    5.91 +--        print("  Name changed, updating")
    5.92 +        old_units[id].name = name_new
    5.93 +        old_units[id]:save()
    5.94 +      end
    5.95 +    else          
    5.96 +--      print("  Creating as new unit")
    5.97 +      local u = Unit:new()
    5.98 +      u.name = name_new
    5.99 +      u.attr = json.object()
   5.100 +      u.attr.firstlife_id = id
   5.101 +      u:save()
   5.102 +      local area = Area:new()
   5.103 +      area.unit_id = u.id
   5.104 +      area.name = config.firstlife_groups.area_name
   5.105 +      area:save()
   5.106 +      local allowed_policy = AllowedPolicy:new()
   5.107 +      allowed_policy.area_id = area.id
   5.108 +      allowed_policy.policy_id = config.firstlife_groups.policy_id
   5.109 +      allowed_policy.default_policy = true
   5.110 +      allowed_policy:save()
   5.111 +      unit = u
   5.112 +    end
   5.113 +    firstlife_mirror_group_users(unit)
   5.114 +  end
   5.115 +
   5.116 +end
   5.117 +

Impressum / About Us