annotate src/admin/edit.html.luan @ 18:64eee582fec1

add move logs while restart
author Vadim Filimonov <fffilimonov@yandex.ru>
date Wed, 19 Jun 2024 11:45:10 +0300
parents dfc36e7ed22c
children
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 pairs = Luan.pairs or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
4 local ipairs = Luan.ipairs or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local stringify = Luan.stringify or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local header = Shared.admin_header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local get_user = Shared.get_user or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local text_to_list = Shared.text_to_list or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13 local config = Shared.config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14 local list_to_set = Shared.list_to_set or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17 local admin_return = Shared.admin_return or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 local Logging = require "luan:logging/Logging.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19 local logger = Logging.logger "admin/edit.html"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 local function response(name,content)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 <title>Edit Mercurial Repository</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 <h1>Edit Repository <a href="/repo/<%=name%>"><%=name%></a></h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 <%=content%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 local function posted(name)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 local mode = Http.request.parameters.mode or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 local users = Http.request.parameters.users or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 local admins = Http.request.parameters.admins or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 users = text_to_list(users)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 admins = text_to_list(admins)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 if #users == 0 then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 return "Users cannot be empty"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 if #admins == 0 then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 return "Users cannot be empty"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 for _, user in ipairs(users) do
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 if config.users[user] == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
55 return "user "..user.." is not a registered user"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
56 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
57 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
58 local user_set = list_to_set(users)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
59 for _, user in ipairs(admins) do
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
60 if config.users[user] == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
61 return "admin "..user.." is not a registered user"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
62 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
63 if not user_set[user] then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
64 return "admin "..user.." is not a user in this repo"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
65 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
66 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
67 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
68 raw_config.repos[name] = {
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
69 mode = mode
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
70 users = users
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
71 admins = admins
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
72 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
73 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
74 return nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
75 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
76
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
77 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
78 local name = Http.request.parameters.repo or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
79 local repo = config.repos[name] or error(name)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
80 repo.admins[get_user()] or error "not admin"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
81 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
82 local error_msg = ""
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
83 if Http.request.method == "POST" then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
84 local error_msg = posted(name)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
85 if error_msg == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
86 response(name,[[<p>Repository updated</p>]]..admin_return)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
87 else
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
88 response(name,[[<p error>]]..error_msg..[[</p>]])
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
89 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
90 return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
91 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
92 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
93 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
94 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
95 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
96 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
97 <title>Edit Mercurial Repository</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
98 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
99 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
100 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
101 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
102 <h1>Edit Repository <a href="/repo/<%=name%>/"><%=name%></a></h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
103 <form method=post>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
104 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
105 <select name=mode>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
106 <option <%= repo.mode=="public" and "selected" or "" %> >public</option>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
107 <option <%= repo.mode=="private" and "selected" or "" %> >private</option>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
108 </select>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
109 <label prompt>If private then only users access this repo.</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
110 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
111 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
112 <label prompt>Users (one per line)</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
113 <textarea name=users>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
114 <% for user in pairs(repo.users) do %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
115 <%=user%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
116 <% end %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
117 </textarea>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
118 <label prompt>Users can push to this repo.</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
119 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
120 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
121 <label prompt>Admins (one per line)</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
122 <textarea name=admins>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
123 <% for user in pairs(repo.admins) do %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
124 <%=user%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
125 <% end %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
126 </textarea>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
127 <label prompt>Admins can manage this repo.</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
128 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
129 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
130 <input type=submit value="Update Repo">
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
131 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
132 </form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
133 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
134 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
135 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
136 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
137 end