# HG changeset patch # User bsw # Date 1602005498 -7200 # Node ID feeac2fd945e79e3f89ff1552f9d40ebbdebe6de # Parent 770ab0a7f79bbb57a01dcfd70697563254192f18# Parent 0d9bb39373103733a30adae7d093eaf77030915c merge diff -r 770ab0a7f79b -r feeac2fd945e app/main/_prefork/10_init.lua --- a/app/main/_prefork/10_init.lua Tue Oct 06 19:31:19 2020 +0200 +++ b/app/main/_prefork/10_init.lua Tue Oct 06 19:31:38 2020 +0200 @@ -237,5 +237,21 @@ max_fork = 1 } +if config.firstlife_groups then + assert(loadcached(encode.file_path(WEBMCP_BASE_PATH, "lib", "firstlife", "groups.lua")))() + listen{ + { + proto = "interval", + name = "send_pending_notifications", + delay = 5, + handler = function() + firstlife_mirror_groups() + end + }, + min_fork = 1, + max_fork = 1 + } +end + execute.inner() diff -r 770ab0a7f79b -r feeac2fd945e app/main/draft/new.lua --- a/app/main/draft/new.lua Tue Oct 06 19:31:19 2020 +0200 +++ b/app/main/draft/new.lua Tue Oct 06 19:31:38 2020 +0200 @@ -12,6 +12,13 @@ if area_id then area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec() area:load_delegation_info_once_for_member_id(app.session.member_id) + else + local firstlife_id = param.get("firstlife_id") + if firstlife_id then + area = Area:new_selector():join("unit", nil, "unit.id = area.unit_id"):add_where{"attr->>'firstlife_id'=?",firstlife_id}:single_object_mode():exec() + area:load_delegation_info_once_for_member_id(app.session.member_id) + area_id = area.id + end end end diff -r 770ab0a7f79b -r feeac2fd945e app/main/index/_head.lua --- a/app/main/index/_head.lua Tue Oct 06 19:31:19 2020 +0200 +++ b/app/main/index/_head.lua Tue Oct 06 19:31:38 2020 +0200 @@ -135,6 +135,9 @@ if unit.description and #(unit.description) > 0 then ui.container{ attr = { class = "mdl-card__supporting-text mdl-card--border" }, content = unit.description } end + if config.render_external_reference_unit then + config.render_external_reference_unit(unit) + end --ui.container{ attr = { class = "mdl-card__actions mdl-card--border" }, content = function() --end } end } diff -r 770ab0a7f79b -r feeac2fd945e app/main/member/show.lua --- a/app/main/member/show.lua Tue Oct 06 19:31:19 2020 +0200 +++ b/app/main/member/show.lua Tue Oct 06 19:31:38 2020 +0200 @@ -63,7 +63,12 @@ ui.grid{ content = function() ui.cell_main{ content = function() + ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function() + + if app.session.member_id == member.id then + execute.view{ module = "index", view = "_lang_chooser" } + end ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = function() diff -r 770ab0a7f79b -r feeac2fd945e lib/firstlife/groups.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/firstlife/groups.lua Tue Oct 06 19:31:38 2020 +0200 @@ -0,0 +1,114 @@ +local function firstlife_mirror_group_users(unit) + local url = config.firstlife_groups.api_base_url .. "v6/fl/Things/" .. unit.attr.firstlife_id .. "/participants" + + local output, err, status = extos.pfilter(doc, "curl", "-X", "GET", "-H", "Content-Type: application/json", "-d", "@-", url) + + local data = json.import(output) + + local old_privileges_list = Privilege:new_selector() + :add_where{ "unit_id = ?", unit.id } + :exec() + + local old_privileges = {} + for i, old_privilege in ipairs(old_privileges_list) do + old_privileges[old_privilege.member_id] = old_privilege + end + + local new_user_hash = {} + + for i, user in ipairs(data) do +-- print(" Processing user ID " .. user.id) + local user_id = tonumber(string.match(user.id, "^(.+)@")) + new_user_hash[user_id] = user + if old_privileges[user_id] then +-- print(" Privilege entry exists") + else +-- print(" Creating new privilege") + local privilege = Privilege:new() + privilege.unit_id = unit.id + privilege.member_id = user_id + privilege.initiative_right = true + privilege.voting_right = true + privilege.weight = 1 + privilege:save() + end + end + + for i, old_privilege in ipairs(old_privileges_list) do + if not new_user_hash[old_privilege.member_id] then +-- print(" Destroying privilege for user ID " .. old_privilege.member_id) + old_privilege:destroy() + end + end + +end + +function _G.firstlife_mirror_groups() + + + local url = config.firstlife_groups.api_base_url .. "v6/fl/Things/search?types=CO3_ACA" + + local output, err, status = extos.pfilter(doc, "curl", "-X", "GET", "-H", "Content-Type: application/json", "-d", "@-", url) + + local data = json.import(output) + + if not data then return end + if not data.things then return end + if data.things.type ~= "FeatureCollection" then return end + if not data.things.features then return end + if json.type(data.things.features) ~= "array" then return end + + local units_new = {} + + for i, feature in ipairs(data.things.features) do +-- print(feature.id, feature.properties.name) + units_new[feature.id] = feature + end + + local old_units_list = Unit:new_selector() + :add_where("attr->'firstlife_id' NOTNULL") + :exec() + + local old_units = {} + + for i, old_unit in ipairs(old_units_list) do + old_units[old_unit.attr.firstlife_id] = old_unit + end + + for id, unit_new in pairs(units_new) do + local name_new = unit_new.properties.name + local unit +-- print("Processing unit ID " .. id .. " with name " .. name_new) + if old_units[id] then + unit = old_units[id] +-- print(" Unit already exists") + if old_units[id].name == name_new then +-- print(" Name not changed") + else +-- print(" Name changed, updating") + old_units[id].name = name_new + old_units[id]:save() + end + else +-- print(" Creating as new unit") + local u = Unit:new() + u.name = name_new + u.attr = json.object() + u.attr.firstlife_id = id + u:save() + local area = Area:new() + area.unit_id = u.id + area.name = config.firstlife_groups.area_name + area:save() + local allowed_policy = AllowedPolicy:new() + allowed_policy.area_id = area.id + allowed_policy.policy_id = config.firstlife_groups.policy_id + allowed_policy.default_policy = true + allowed_policy:save() + unit = u + end + firstlife_mirror_group_users(unit) + end + +end +