annotate src/admin/add.html.luan @ 21:b14073ab9d07

update luan
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 14 Sep 2024 22:17:26 -0600
parents a7187a447835
children 7c9a45368af2
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
5
a09d8bcdc0f9 lower case repos
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
3 local String = require "luan:String.luan"
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
4 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local header = Shared.admin_header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local get_user = Shared.get_user or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local admin_return = Shared.admin_return or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13
21
b14073ab9d07 update luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
14 local name_regex = String.regex("^[a-z0-9_][a-z0-9_-]*$")
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16 local function handle()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17 local user = get_user()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 local repo_name = Http.request.parameters.repo or error()
21
b14073ab9d07 update luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
19 name_regex.matches( repo_name ) or error "invalid regex name"
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 if repo_name=="_all" or repo_name=="_private" then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 return [[<p error>Invalid rep name</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 if raw_config.repos[repo_name] ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 raw_config.repos[repo_name] = {
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 mode = "public"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 users = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 admins = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 <title>Add Mercurial Repository</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 <h1>Add Repository</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 <%=handle()%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 end