mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-14 03:01:48 +00:00
Record git repo URL in the principal when forge auth is used.
Resolves: https://codeberg.org/git-pages/git-pages/issues/167
This commit is contained in:
@@ -111,6 +111,9 @@ func (record *AuditRecord) DescribePrincipal() string {
|
||||
record.Principal.GetForgeUser().GetHandle(),
|
||||
record.Principal.GetForgeUser().GetId()))
|
||||
}
|
||||
if record.Principal.GetRepoUrl() != "" {
|
||||
items = append(items, record.Principal.GetRepoUrl())
|
||||
}
|
||||
if record.Principal.GetCliAdmin() {
|
||||
items = append(items, "<cli-admin>")
|
||||
}
|
||||
|
||||
32
src/pages.go
32
src/pages.go
@@ -65,6 +65,17 @@ func observeSiteUpdate(via string, result *UpdateResult) {
|
||||
}
|
||||
}
|
||||
|
||||
func copyForgeAuthToPrincipal(principal *Principal, auth *Authorization) {
|
||||
if auth.forgeUser != nil {
|
||||
principal.ForgeUser = auth.forgeUser
|
||||
}
|
||||
|
||||
repoURL := auth.ForgeRepoURL()
|
||||
if repoURL != "" {
|
||||
principal.RepoUrl = &repoURL
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeHost(host string) string {
|
||||
return strings.ToLower(host)
|
||||
}
|
||||
@@ -526,10 +537,11 @@ func putPage(w http.ResponseWriter, r *http.Request) error {
|
||||
auth, err := AuthorizeUpdateFromArchive(r)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if auth.forgeUser != nil {
|
||||
GetPrincipal(r.Context()).ForgeUser = auth.forgeUser
|
||||
}
|
||||
|
||||
principal := GetPrincipal(r.Context())
|
||||
copyForgeAuthToPrincipal(principal, auth)
|
||||
|
||||
repoURL := auth.ForgeRepoURL()
|
||||
|
||||
if checkDryRun(w, r) {
|
||||
@@ -559,12 +571,14 @@ func patchPage(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if auth, err := AuthorizeUpdateFromArchive(r); err != nil {
|
||||
auth, err := AuthorizeUpdateFromArchive(r)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if auth.forgeUser != nil {
|
||||
GetPrincipal(r.Context()).ForgeUser = auth.forgeUser
|
||||
}
|
||||
|
||||
principal := GetPrincipal(r.Context())
|
||||
copyForgeAuthToPrincipal(principal, auth)
|
||||
|
||||
if checkDryRun(w, r) {
|
||||
return nil
|
||||
}
|
||||
@@ -691,12 +705,14 @@ func deletePage(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if auth, err := AuthorizeDeletion(r); err != nil {
|
||||
auth, err := AuthorizeDeletion(r)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if auth.forgeUser != nil {
|
||||
GetPrincipal(r.Context()).ForgeUser = auth.forgeUser
|
||||
}
|
||||
|
||||
principal := GetPrincipal(r.Context())
|
||||
copyForgeAuthToPrincipal(principal, auth)
|
||||
|
||||
if checkDryRun(w, r) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -863,6 +863,7 @@ type Principal struct {
|
||||
IpAddress *string `protobuf:"bytes,1,opt,name=ip_address,json=ipAddress" json:"ip_address,omitempty"`
|
||||
CliAdmin *bool `protobuf:"varint,2,opt,name=cli_admin,json=cliAdmin" json:"cli_admin,omitempty"`
|
||||
ForgeUser *ForgeUser `protobuf:"bytes,3,opt,name=forge_user,json=forgeUser" json:"forge_user,omitempty"`
|
||||
RepoUrl *string `protobuf:"bytes,4,opt,name=repo_url,json=repoUrl" json:"repo_url,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -918,6 +919,13 @@ func (x *Principal) GetForgeUser() *ForgeUser {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Principal) GetRepoUrl() string {
|
||||
if x != nil && x.RepoUrl != nil {
|
||||
return *x.RepoUrl
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ForgeUser struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Origin *string `protobuf:"bytes,1,opt,name=origin" json:"origin,omitempty"`
|
||||
@@ -1041,14 +1049,15 @@ const file_schema_proto_rawDesc = "" +
|
||||
"\x06domain\x18\n" +
|
||||
" \x01(\tR\x06domain\x12\x18\n" +
|
||||
"\aproject\x18\v \x01(\tR\aproject\x12%\n" +
|
||||
"\bmanifest\x18\f \x01(\v2\t.ManifestR\bmanifest\"r\n" +
|
||||
"\bmanifest\x18\f \x01(\v2\t.ManifestR\bmanifest\"\x8d\x01\n" +
|
||||
"\tPrincipal\x12\x1d\n" +
|
||||
"\n" +
|
||||
"ip_address\x18\x01 \x01(\tR\tipAddress\x12\x1b\n" +
|
||||
"\tcli_admin\x18\x02 \x01(\bR\bcliAdmin\x12)\n" +
|
||||
"\n" +
|
||||
"forge_user\x18\x03 \x01(\v2\n" +
|
||||
".ForgeUserR\tforgeUser\"K\n" +
|
||||
".ForgeUserR\tforgeUser\x12\x19\n" +
|
||||
"\brepo_url\x18\x04 \x01(\tR\arepoUrl\"K\n" +
|
||||
"\tForgeUser\x12\x16\n" +
|
||||
"\x06origin\x18\x01 \x01(\tR\x06origin\x12\x0e\n" +
|
||||
"\x02id\x18\x02 \x01(\x03R\x02id\x12\x16\n" +
|
||||
|
||||
@@ -144,6 +144,7 @@ message Principal {
|
||||
string ip_address = 1;
|
||||
bool cli_admin = 2;
|
||||
ForgeUser forge_user = 3;
|
||||
string repo_url = 4;
|
||||
}
|
||||
|
||||
message ForgeUser {
|
||||
|
||||
Reference in New Issue
Block a user