parsav  Artifact [6e08f785f6]

Artifact 6e08f785f6877a8b410810099167471dc1578d2f9c9e4991e7c6fc0b18aed386:


-- vim: ft=terra
local pstr = lib.mem.ptr(int8)
local pref = lib.mem.ref(int8)

local mappings = {
	{url = 'profile', title = 'account profile', render = 'profile'};
	{url = 'avi', title = 'avatar', render = 'avatar'};
	{url = 'sec', title = 'security', render = 'sec'};
	{url = 'rel', title = 'relationships', render = 'rel'};
	{url = 'qnt', title = 'quarantine', render = 'quarantine'};
	{url = 'acl', title = 'access control shortcuts', render = 'acl'};
	{url = 'rooms', title = 'chatrooms', render = 'rooms'};
	{url = 'circles', title = 'circles', render = 'circles'};

	{url = 'srv', title = 'server settings', render = 'srv'};
	{url = 'brand', title = 'instance branding', render = 'rebrand'};
	{url = 'censor', title = 'censorship & badthink suppression', render = 'rebrand'};
	{url = 'users', title = 'user accounting', render = 'users'};

}

local path = symbol(lib.mem.ptr(pref))
local co = symbol(&lib.srv.convo)
local panel = symbol(pstr)
local invoker = quote co:complain(404,'not found','no such control panel is available in this version of parsav') end

for i, m in ipairs(mappings) do
	if lib.render.conf[m.render] then
		invoker = quote
			if path(1):cmp(lib.str.lit([m.url])) then
				var body = [lib.render.conf[m.render]] (co, path)
				var a: lib.str.acc a:init(body.ct+48)
				a:lpush(['<h1>' .. m.title .. '</h1>']):ppush(body)
				panel = a:finalize()
				body:free()
			else [invoker] end
		end
	end
end

local terra 
render_conf([co], [path])
	var menu: lib.str.acc menu:init(64):lpush('<hr>') defer menu:free()

	-- build menu
	do var p = co.who.rights.powers
		if p.config() then menu:lpush '<a href="/conf/srv">server settings</a>' end
		if p.rebrand() then menu:lpush '<a href="/conf/brand">instance branding</a>' end
		if p.censor() then menu:lpush '<a href="/conf/censor">badthink alerts</a>' end
		if p:affect_users() then menu:lpush '<a href="/conf/users">users</a>' end
	end

	-- select the appropriate panel
	var [panel] = pstr { ptr = ''; ct = 0 }
	if path.ct >= 2 then [invoker] end

	-- avoid the hr if we didn't add any elements
	var mptr = pstr { ptr = menu.buf, ct = menu.sz }
	if menu.sz <= 4 then mptr.ct = 0 end -- 🙄
	var pg = data.view.conf {
		menu = mptr;
		panel = panel;
	}

	var pgt = pg:tostr() defer pgt:free()
	co:stdpage([lib.srv.convo.page] {
		title = 'configure'; body = pgt;
		class = lib.str.plit 'conf';
	})

	if panel.ct ~= 0 then panel:free() end
end

return render_conf