aboutsummaryrefslogtreecommitdiffstats
path: root/services/context
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-04 10:08:23 +0800
committerGitHub <noreply@github.com>2023-04-04 10:08:23 +0800
commit17f23182ffdada3dee6a01ab2b49547e680bb02c (patch)
treefd0a62a042183da3dca5911440db68ab2f12b1bb /services/context
parent5115ffa90c959086704b6e3437214a192de7b8a7 (diff)
downloadgitea-17f23182ffdada3dee6a01ab2b49547e680bb02c.tar.gz
gitea-17f23182ffdada3dee6a01ab2b49547e680bb02c.zip
Use User.ID instead of User.Name in ActivityPub API for Person IRI (#23823)
Thanks to @trwnh Close #23802 The ActivityPub id is an HTTPS URI that should remain constant, even if the user changes their name.
Diffstat (limited to 'services/context')
-rw-r--r--services/context/user.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/services/context/user.go b/services/context/user.go
index 9dc84c3ac1..c713667bca 100644
--- a/services/context/user.go
+++ b/services/context/user.go
@@ -29,6 +29,27 @@ func UserAssignmentWeb() func(ctx *context.Context) {
}
}
+// UserIDAssignmentAPI returns a middleware to handle context-user assignment for api routes
+func UserIDAssignmentAPI() func(ctx *context.APIContext) {
+ return func(ctx *context.APIContext) {
+ userID := ctx.ParamsInt64(":user-id")
+
+ if ctx.IsSigned && ctx.Doer.ID == userID {
+ ctx.ContextUser = ctx.Doer
+ } else {
+ var err error
+ ctx.ContextUser, err = user_model.GetUserByID(ctx, userID)
+ if err != nil {
+ if user_model.IsErrUserNotExist(err) {
+ ctx.Error(http.StatusNotFound, "GetUserByID", err)
+ } else {
+ ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
+ }
+ }
+ }
+ }
+}
+
// UserAssignmentAPI returns a middleware to handle context-user assignment for api routes
func UserAssignmentAPI() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {