Mercurial Hosting > hghosting
changeset 4:028e74c8889d
add all_users
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 12 May 2022 16:54:11 -0600 |
parents | e3448053230a |
children | a09d8bcdc0f9 |
files | src/admin/index.html.luan src/lib/Shared.luan src/private/tools/all_users.html.luan src/private/tools/backup.html.luan src/private/tools/delete_user.html.luan src/private/tools/index.html.luan src/private/tools/private_users.html.luan src/private/tools/users.html.luan |
diffstat | 8 files changed, 206 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
diff -r e3448053230a -r 028e74c8889d src/admin/index.html.luan --- a/src/admin/index.html.luan Thu May 12 10:26:43 2022 -0600 +++ b/src/admin/index.html.luan Thu May 12 16:54:11 2022 -0600 @@ -1,6 +1,5 @@ local Luan = require "luan:Luan.luan" local error = Luan.error -local pairs = Luan.pairs or error() local ipairs = Luan.ipairs or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" @@ -9,19 +8,8 @@ local header = Shared.admin_header or error() local get_user = Shared.get_user or error() local config = Shared.config or error() - +local user_repos = Shared.user_repos or error() -local user_repos = {} -for _, repo in pairs(config.repos) do - for user in pairs(repo.users) do - local repos = user_repos[user] - if repos == nil then - repos = {} - user_repos[user] = repos - end - repos[#repos+1] = repo - end -end return function() local user = get_user()
diff -r e3448053230a -r 028e74c8889d src/lib/Shared.luan --- a/src/lib/Shared.luan Thu May 12 10:26:43 2022 -0600 +++ b/src/lib/Shared.luan Thu May 12 16:54:11 2022 -0600 @@ -141,6 +141,19 @@ config.private = config.private and list_to_set(config.private) Shared.config = config +local user_repos = {} +for _, repo in pairs(config.repos) do + for user in pairs(repo.users) do + local repos = user_repos[user] + if repos == nil then + repos = {} + user_repos[user] = repos + end + repos[#repos+1] = repo + end +end +Shared.user_repos = user_repos + function Shared.get_raw_config() return deep_copy(raw_config) end
diff -r e3448053230a -r 028e74c8889d src/private/tools/all_users.html.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/private/tools/all_users.html.luan Thu May 12 16:54:11 2022 -0600 @@ -0,0 +1,52 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local pairs = Luan.pairs or error() +local ipairs = Luan.ipairs 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.private_header or error() +local config = Shared.config or error() +local user_repos = Shared.user_repos or error() + + +return function() + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html> + <head> +<% head() %> + <title>Mercurial All Users</title> + <script> + function deleteUser(name) { + if( confirm('Are you sure that you want to delete user "'+name+'"?') ) + location = "delete_user.html?user="+name; + } + </script> + </head> + <body> +<% header() %> + <div content> + <h1>All Users</h1> +<% for user in pairs(config.users) do %> + <p> + <%=user%> +<% local repos = user_repos[user] + if repos == nil then %> + [] <a href="javascript:deleteUser('<%=user%>')">delete user</a> +<% else %> + [ +<% for _, repo in ipairs(repos) do %> + <a href="/repo/<%=repo.name%>/"><%=repo.name%></a> +<% end %> + ] +<% end %> + </p> +<% end %> + </div> + </body> +</html> +<% +end
diff -r e3448053230a -r 028e74c8889d src/private/tools/backup.html.luan --- a/src/private/tools/backup.html.luan Thu May 12 10:26:43 2022 -0600 +++ b/src/private/tools/backup.html.luan Thu May 12 16:54:11 2022 -0600 @@ -13,7 +13,7 @@ local get_raw_config = Shared.get_raw_config or error() local save_raw_config = Shared.save_raw_config or error() local Logging = require "luan:logging/Logging.luan" -local logger = Logging.logger "private-users.html" +local logger = Logging.logger "backup.html" local function response(content)
diff -r e3448053230a -r 028e74c8889d src/private/tools/delete_user.html.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/private/tools/delete_user.html.luan Thu May 12 16:54:11 2022 -0600 @@ -0,0 +1,41 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.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.private_header or error() +local config = Shared.config or error() +local user_repos = Shared.user_repos or error() +local get_raw_config = Shared.get_raw_config or error() +local save_raw_config = Shared.save_raw_config or error() + + +local function handle() + local user = Http.request.parameters.user or error() + user_repos[user] and error "has repos" + local raw_config = get_raw_config() + raw_config.users[user] = nil + save_raw_config(raw_config) + return [[<p>User <b>]]..user..[[</b> has been deleted</p>]] +end + +return function() + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html> + <head> +<% head() %> + <title>Delete Mercurial User</title> + </head> + <body> +<% header() %> + <div content> + <h1>Delete User</h1> + <%=handle()%> + </div> + </body> +</html> +<% +end
diff -r e3448053230a -r 028e74c8889d src/private/tools/index.html.luan --- a/src/private/tools/index.html.luan Thu May 12 10:26:43 2022 -0600 +++ b/src/private/tools/index.html.luan Thu May 12 16:54:11 2022 -0600 @@ -20,8 +20,9 @@ <% header() %> <div content> <h1>Private Tools</h1> - <p><a href="users.html">edit private users</a></p> + <p><a href="private_users.html">edit private users</a></p> <p><a href="backup.html">edit backup</a></p> + <p><a href="all_users.html">all users</a></p> <p><a href="links.txt">links.txt</a></p> </div> </body>
diff -r e3448053230a -r 028e74c8889d src/private/tools/private_users.html.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/private/tools/private_users.html.luan Thu May 12 16:54:11 2022 -0600 @@ -0,0 +1,96 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local pairs = Luan.pairs or error() +local ipairs = Luan.ipairs or error() +local stringify = Luan.stringify 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.private_header or error() +local text_to_list = Shared.text_to_list or error() +local config = Shared.config or error() +local get_raw_config = Shared.get_raw_config or error() +local save_raw_config = Shared.save_raw_config or error() +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "private_users.html" + + +local function response(content) +%> +<!doctype html> +<html> + <head> +<% head() %> + <title>Mercurial Private Users</title> + </head> + <body> +<% header() %> + <div content> + <h1>Private Users</h1> + <%=content%> + </div> + </body> +</html> +<% +end + +local function posted() + local users = Http.request.parameters.users or error() + users = text_to_list(users) + if #users == 0 then + return "Users cannot be empty" + end + for _, user in ipairs(users) do + if config.users[user] == nil then + return "user "..user.." is not a registered user" + end + end + local raw_config = get_raw_config() + raw_config.private = users + save_raw_config(raw_config) + return nil +end + +return function() + Io.stdout = Http.response.text_writer() + local error_msg = "" + if Http.request.method == "POST" then + local error_msg = posted() + if error_msg == nil then + response([[<p>Private updated</p>]]) + else + response([[<p error>]]..error_msg..[[</p>]]) + end + return + end +%> +<!doctype html> +<html> + <head> +<% head() %> + <title>Mercurial Private Users</title> + </head> + <body> +<% header() %> + <div content> + <h1>Private Users</h1> + <form method=post> + <p> + <label prompt>Users (one per line)</label> + <textarea name=users> +<% for user in pairs(config.private or {}) do %> +<%=user%> +<% end %> +</textarea> + <label prompt>Users who can access /private/</label> + </p> + <p> + <input type=submit value="Update Private"> + </p> + </form> + </div> + </body> +</html> +<% +end
diff -r e3448053230a -r 028e74c8889d src/private/tools/users.html.luan --- a/src/private/tools/users.html.luan Thu May 12 10:26:43 2022 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -local Luan = require "luan:Luan.luan" -local error = Luan.error -local pairs = Luan.pairs or error() -local ipairs = Luan.ipairs or error() -local stringify = Luan.stringify 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.private_header or error() -local text_to_list = Shared.text_to_list or error() -local config = Shared.config or error() -local get_raw_config = Shared.get_raw_config or error() -local save_raw_config = Shared.save_raw_config or error() -local Logging = require "luan:logging/Logging.luan" -local logger = Logging.logger "private-users.html" - - -local function response(content) -%> -<!doctype html> -<html> - <head> -<% head() %> - <title>Mercurial Private Users</title> - </head> - <body> -<% header() %> - <div content> - <h1>Private Users</h1> - <%=content%> - </div> - </body> -</html> -<% -end - -local function posted() - local users = Http.request.parameters.users or error() - users = text_to_list(users) - if #users == 0 then - return "Users cannot be empty" - end - for _, user in ipairs(users) do - if config.users[user] == nil then - return "user "..user.." is not a registered user" - end - end - local raw_config = get_raw_config() - raw_config.private = users - save_raw_config(raw_config) - return nil -end - -return function() - Io.stdout = Http.response.text_writer() - local error_msg = "" - if Http.request.method == "POST" then - local error_msg = posted() - if error_msg == nil then - response([[<p>Private updated</p>]]) - else - response([[<p error>]]..error_msg..[[</p>]]) - end - return - end -%> -<!doctype html> -<html> - <head> -<% head() %> - <title>Mercurial Private Users</title> - </head> - <body> -<% header() %> - <div content> - <h1>Private Users</h1> - <form method=post> - <p> - <label prompt>Users (one per line)</label> - <textarea name=users> -<% for user in pairs(config.private or {}) do %> -<%=user%> -<% end %> -</textarea> - <label prompt>Users who can access /private/</label> - </p> - <p> - <input type=submit value="Update Private"> - </p> - </form> - </div> - </body> -</html> -<% -end