view src/admin/add.html.luan @ 5:a09d8bcdc0f9

lower case repos
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 18 May 2022 00:21:44 -0600
parents dfc36e7ed22c
children a7187a447835
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local String = require "luan:String.luan"
local to_lower = String.lower or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.admin_header or error()
local get_user = Shared.get_user or error()
local get_raw_config = Shared.get_raw_config or error()
local save_raw_config = Shared.save_raw_config or error()
local admin_return = Shared.admin_return or error()


local function handle()
	local user = get_user()
	local repo_name = Http.request.parameters.repo or error()
	repo_name = to_lower(repo_name)
	if repo_name=="_all" or repo_name=="_private" then
		return [[<p error>Invalid rep name</p>]]
	end
	local raw_config = get_raw_config()
	if raw_config.repos[repo_name] ~= nil then
		return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
	end
	raw_config.repos[repo_name] = {
		mode = "public"
		users = {user}
		admins = {user}
	}
	save_raw_config(raw_config)
	return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
end

return function()
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title>Add Mercurial Repository</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Add Repository</h1>
			<%=handle()%>
		</div>
	</body>
</html>
<%
end