Support multiple allowed users for write access

MAPTOOL_ALLOWED_GITEA_USER now accepts a comma-separated list of
Gitea usernames instead of just one, for when more than one person
needs upload/delete/move access.
This commit is contained in:
randy committed 2026-08-27 18:25:31 +02:00
1 parent e13d1a1e97
commit 260006ad65
3 files changed
+23 -16

No files matched your search

+7 -7
View File
@@ -24,13 +24,13 @@ module Maptool
# Login delegates to the Gitea instance the user already has an account
# on, rather than maintaining a local username/password — see
# docs/architecture.adoc. Only ALLOWED_GITEA_USER may write; anyone else
# can authenticate against Gitea but is still refused. No defaults for
# the OAuth2 client id/secret/user: blank values just mean login (and
# thus writing) doesn't work, which is fine outside production — nothing
# here is eagerly validated at load time.
# docs/architecture.adoc. Only users listed in ALLOWED_GITEA_USERS may
# write; anyone else can authenticate against Gitea but is still
# refused. No defaults for the OAuth2 client id/secret/user list: blank
# values just mean login (and thus writing) doesn't work, which is fine
# outside production — nothing here is eagerly validated at load time.
GITEA_URL = ENV.fetch("GITEA_URL", "https://git.priesol.net")
ALLOWED_GITEA_USER = ENV.fetch("MAPTOOL_ALLOWED_GITEA_USER", "")
ALLOWED_GITEA_USERS = ENV.fetch("MAPTOOL_ALLOWED_GITEA_USER", "").split(",").map(&:strip)
OAUTH_CLIENT = OAuth2::Client.new(
ENV.fetch("GITEA_OAUTH_CLIENT_ID", ""),
ENV.fetch("GITEA_OAUTH_CLIENT_SECRET", ""),
@@ -67,7 +67,7 @@ module Maptool
token = OAUTH_CLIENT.auth_code.get_token(params[:code], redirect_uri: callback_url)
user = token.get("/api/v1/user").parsed
halt 403, "not authorized" unless user["login"] == ALLOWED_GITEA_USER
halt 403, "not authorized" unless ALLOWED_GITEA_USERS.include?(user["login"])
session[:user] = user["login"]
redirect "/"