annotate src/admin/add.html.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children a09d8bcdc0f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
2 local error = Luan.error
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local header = Shared.admin_header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local get_user = Shared.get_user or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local admin_return = Shared.admin_return or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14 local function handle()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15 local user = get_user()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16 local repo_name = Http.request.parameters.repo or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17 if repo_name=="_all" or repo_name=="_private" then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 return [[<p error>Invalid rep name</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 if raw_config.repos[repo_name] ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 raw_config.repos[repo_name] = {
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 mode = "public"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 users = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 admins = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 <title>Add Mercurial Repository</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 <h1>Add Repository</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 <%=handle()%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 end