Skip to content

Commit 80fd255

Browse files
KN4CK3R6543wxiaoguang
authored
Renamed ctx.User to ctx.Doer. (#19161)
Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 5495ba7 commit 80fd255

File tree

129 files changed

+881
-881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+881
-881
lines changed

integrations/repofiles_delete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) {
7777
test.LoadGitRepo(t, ctx)
7878
defer ctx.Repo.GitRepo.Close()
7979
repo := ctx.Repo.Repository
80-
doer := ctx.User
80+
doer := ctx.Doer
8181
opts := getDeleteRepoFileOptions(repo)
8282

8383
t.Run("Delete README.md file", func(t *testing.T) {
@@ -117,7 +117,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
117117
defer ctx.Repo.GitRepo.Close()
118118

119119
repo := ctx.Repo.Repository
120-
doer := ctx.User
120+
doer := ctx.Doer
121121
opts := getDeleteRepoFileOptions(repo)
122122
opts.OldBranch = ""
123123
opts.NewBranch = ""
@@ -147,7 +147,7 @@ func TestDeleteRepoFileErrors(t *testing.T) {
147147
defer ctx.Repo.GitRepo.Close()
148148

149149
repo := ctx.Repo.Repository
150-
doer := ctx.User
150+
doer := ctx.Doer
151151

152152
t.Run("Bad branch", func(t *testing.T) {
153153
opts := getDeleteRepoFileOptions(repo)

integrations/repofiles_update_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
194194
defer ctx.Repo.GitRepo.Close()
195195

196196
repo := ctx.Repo.Repository
197-
doer := ctx.User
197+
doer := ctx.Doer
198198
opts := getCreateRepoFileOptions(repo)
199199

200200
// test
@@ -230,7 +230,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
230230
defer ctx.Repo.GitRepo.Close()
231231

232232
repo := ctx.Repo.Repository
233-
doer := ctx.User
233+
doer := ctx.Doer
234234
opts := getUpdateRepoFileOptions(repo)
235235

236236
// test
@@ -263,7 +263,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
263263
defer ctx.Repo.GitRepo.Close()
264264

265265
repo := ctx.Repo.Repository
266-
doer := ctx.User
266+
doer := ctx.Doer
267267
opts := getUpdateRepoFileOptions(repo)
268268
opts.FromTreePath = "README.md"
269269
opts.TreePath = "README_new.md" // new file name, README_new.md
@@ -313,7 +313,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
313313
defer ctx.Repo.GitRepo.Close()
314314

315315
repo := ctx.Repo.Repository
316-
doer := ctx.User
316+
doer := ctx.Doer
317317
opts := getUpdateRepoFileOptions(repo)
318318
opts.OldBranch = ""
319319
opts.NewBranch = ""
@@ -344,7 +344,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
344344
defer ctx.Repo.GitRepo.Close()
345345

346346
repo := ctx.Repo.Repository
347-
doer := ctx.User
347+
doer := ctx.Doer
348348

349349
t.Run("bad branch", func(t *testing.T) {
350350
opts := getUpdateRepoFileOptions(repo)

modules/context/api.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
100100
if status == http.StatusInternalServerError {
101101
log.ErrorWithSkip(1, "%s: %s", title, message)
102102

103-
if setting.IsProd && !(ctx.User != nil && ctx.User.IsAdmin) {
103+
if setting.IsProd && !(ctx.Doer != nil && ctx.Doer.IsAdmin) {
104104
message = ""
105105
}
106106
}
@@ -117,7 +117,7 @@ func (ctx *APIContext) InternalServerError(err error) {
117117
log.ErrorWithSkip(1, "InternalServerError: %v", err)
118118

119119
var message string
120-
if !setting.IsProd || (ctx.User != nil && ctx.User.IsAdmin) {
120+
if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) {
121121
message = err.Error()
122122
}
123123

@@ -225,7 +225,7 @@ func (ctx *APIContext) CheckForOTP() {
225225
}
226226

227227
otpHeader := ctx.Req.Header.Get("X-Gitea-OTP")
228-
twofa, err := auth.GetTwoFactorByUID(ctx.Context.User.ID)
228+
twofa, err := auth.GetTwoFactorByUID(ctx.Context.Doer.ID)
229229
if err != nil {
230230
if auth.IsErrTwoFactorNotEnrolled(err) {
231231
return // No 2FA enrollment for this user
@@ -248,18 +248,18 @@ func (ctx *APIContext) CheckForOTP() {
248248
func APIAuth(authMethod auth_service.Method) func(*APIContext) {
249249
return func(ctx *APIContext) {
250250
// Get user from session if logged in.
251-
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
252-
if ctx.User != nil {
253-
if ctx.Locale.Language() != ctx.User.Language {
251+
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
252+
if ctx.Doer != nil {
253+
if ctx.Locale.Language() != ctx.Doer.Language {
254254
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
255255
}
256256
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth_service.BasicMethodName
257257
ctx.IsSigned = true
258258
ctx.Data["IsSigned"] = ctx.IsSigned
259-
ctx.Data["SignedUser"] = ctx.User
260-
ctx.Data["SignedUserID"] = ctx.User.ID
261-
ctx.Data["SignedUserName"] = ctx.User.Name
262-
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
259+
ctx.Data["SignedUser"] = ctx.Doer
260+
ctx.Data["SignedUserID"] = ctx.Doer.ID
261+
ctx.Data["SignedUserName"] = ctx.Doer.Name
262+
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
263263
} else {
264264
ctx.Data["SignedUserID"] = int64(0)
265265
ctx.Data["SignedUserName"] = ""

modules/context/auth.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
2727
return func(ctx *Context) {
2828
// Check prohibit login users.
2929
if ctx.IsSigned {
30-
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
30+
if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
3131
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
3232
ctx.HTML(http.StatusOK, "user/auth/activate")
3333
return
3434
}
35-
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
36-
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
35+
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
36+
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
3737
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
3838
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
3939
return
4040
}
4141

42-
if ctx.User.MustChangePassword {
42+
if ctx.Doer.MustChangePassword {
4343
if ctx.Req.URL.Path != "/user/settings/change_password" {
4444
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
4545
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
@@ -76,7 +76,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
7676
}
7777
ctx.Redirect(setting.AppSubURL + "/user/login")
7878
return
79-
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
79+
} else if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
8080
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
8181
ctx.HTML(http.StatusOK, "user/auth/activate")
8282
return
@@ -94,7 +94,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
9494
}
9595

9696
if options.AdminRequired {
97-
if !ctx.User.IsAdmin {
97+
if !ctx.Doer.IsAdmin {
9898
ctx.Error(http.StatusForbidden)
9999
return
100100
}
@@ -108,23 +108,23 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
108108
return func(ctx *APIContext) {
109109
// Check prohibit login users.
110110
if ctx.IsSigned {
111-
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
111+
if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
112112
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
113113
ctx.JSON(http.StatusForbidden, map[string]string{
114114
"message": "This account is not activated.",
115115
})
116116
return
117117
}
118-
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
119-
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
118+
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
119+
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
120120
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
121121
ctx.JSON(http.StatusForbidden, map[string]string{
122122
"message": "This account is prohibited from signing in, please contact your site administrator.",
123123
})
124124
return
125125
}
126126

127-
if ctx.User.MustChangePassword {
127+
if ctx.Doer.MustChangePassword {
128128
ctx.JSON(http.StatusForbidden, map[string]string{
129129
"message": "You must change your password. Change it at: " + setting.AppURL + "/user/change_password",
130130
})
@@ -145,7 +145,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
145145
"message": "Only signed in user is allowed to call APIs.",
146146
})
147147
return
148-
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
148+
} else if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
149149
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
150150
ctx.HTML(http.StatusOK, "user/auth/activate")
151151
return
@@ -154,7 +154,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
154154
if skip, ok := ctx.Data["SkipLocalTwoFA"]; ok && skip.(bool) {
155155
return // Skip 2FA
156156
}
157-
twofa, err := auth.GetTwoFactorByUID(ctx.User.ID)
157+
twofa, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
158158
if err != nil {
159159
if auth.IsErrTwoFactorNotEnrolled(err) {
160160
return // No 2FA enrollment for this user
@@ -178,7 +178,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
178178
}
179179

180180
if options.AdminRequired {
181-
if !ctx.User.IsAdmin {
181+
if !ctx.Doer.IsAdmin {
182182
ctx.JSON(http.StatusForbidden, map[string]string{
183183
"message": "You have no permission to request for this.",
184184
})

modules/context/context.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Context struct {
6363

6464
Link string // current request URL
6565
EscapedLink string
66-
User *user_model.User
66+
Doer *user_model.User
6767
IsSigned bool
6868
IsBasicAuth bool
6969

@@ -88,7 +88,7 @@ func (ctx *Context) GetData() map[string]interface{} {
8888

8989
// IsUserSiteAdmin returns true if current user is a site admin
9090
func (ctx *Context) IsUserSiteAdmin() bool {
91-
return ctx.IsSigned && ctx.User.IsAdmin
91+
return ctx.IsSigned && ctx.Doer.IsAdmin
9292
}
9393

9494
// IsUserRepoOwner returns true if current user owns current repo
@@ -574,10 +574,10 @@ func GetContext(req *http.Request) *Context {
574574
// GetContextUser returns context user
575575
func GetContextUser(req *http.Request) *user_model.User {
576576
if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
577-
return apiContext.User
577+
return apiContext.Doer
578578
}
579579
if ctx, ok := req.Context().Value(contextKey).(*Context); ok {
580-
return ctx.User
580+
return ctx.Doer
581581
}
582582
return nil
583583
}
@@ -599,18 +599,18 @@ func getCsrfOpts() CsrfOptions {
599599
// Auth converts auth.Auth as a middleware
600600
func Auth(authMethod auth.Method) func(*Context) {
601601
return func(ctx *Context) {
602-
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
603-
if ctx.User != nil {
604-
if ctx.Locale.Language() != ctx.User.Language {
602+
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
603+
if ctx.Doer != nil {
604+
if ctx.Locale.Language() != ctx.Doer.Language {
605605
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
606606
}
607607
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
608608
ctx.IsSigned = true
609609
ctx.Data["IsSigned"] = ctx.IsSigned
610-
ctx.Data["SignedUser"] = ctx.User
611-
ctx.Data["SignedUserID"] = ctx.User.ID
612-
ctx.Data["SignedUserName"] = ctx.User.Name
613-
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
610+
ctx.Data["SignedUser"] = ctx.Doer
611+
ctx.Data["SignedUserID"] = ctx.Doer.ID
612+
ctx.Data["SignedUserName"] = ctx.Doer.Name
613+
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
614614
} else {
615615
ctx.Data["SignedUserID"] = int64(0)
616616
ctx.Data["SignedUserName"] = ""

modules/context/org.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
7777
ctx.Data["OrgTeams"] = teams
7878

7979
// Admin has super access.
80-
if ctx.IsSigned && ctx.User.IsAdmin {
80+
if ctx.IsSigned && ctx.Doer.IsAdmin {
8181
ctx.Org.IsOwner = true
8282
ctx.Org.IsMember = true
8383
ctx.Org.IsTeamMember = true
8484
ctx.Org.IsTeamAdmin = true
8585
ctx.Org.CanCreateOrgRepo = true
8686
} else if ctx.IsSigned {
87-
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID)
87+
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
8888
if err != nil {
8989
ctx.ServerError("IsOwnedBy", err)
9090
return
@@ -96,12 +96,12 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
9696
ctx.Org.IsTeamAdmin = true
9797
ctx.Org.CanCreateOrgRepo = true
9898
} else {
99-
ctx.Org.IsMember, err = org.IsOrgMember(ctx.User.ID)
99+
ctx.Org.IsMember, err = org.IsOrgMember(ctx.Doer.ID)
100100
if err != nil {
101101
ctx.ServerError("IsOrgMember", err)
102102
return
103103
}
104-
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.User.ID)
104+
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.Doer.ID)
105105
if err != nil {
106106
ctx.ServerError("CanCreateOrgRepo", err)
107107
return
@@ -133,7 +133,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
133133
if ctx.Org.IsOwner {
134134
shouldSeeAllTeams = true
135135
} else {
136-
teams, err := org.GetUserTeams(ctx.User.ID)
136+
teams, err := org.GetUserTeams(ctx.Doer.ID)
137137
if err != nil {
138138
ctx.ServerError("GetUserTeams", err)
139139
return
@@ -152,7 +152,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
152152
return
153153
}
154154
} else {
155-
ctx.Org.Teams, err = org.GetUserTeams(ctx.User.ID)
155+
ctx.Org.Teams, err = org.GetUserTeams(ctx.Doer.ID)
156156
if err != nil {
157157
ctx.ServerError("GetUserTeams", err)
158158
return

modules/context/permission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func RequireRepoReader(unitType unit.Type) func(ctx *Context) {
4949
if ctx.IsSigned {
5050
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
5151
"User in Repo has Permissions: %-+v",
52-
ctx.User,
52+
ctx.Doer,
5353
unitType,
5454
ctx.Repo.Repository,
5555
ctx.Repo.Permission)
@@ -80,7 +80,7 @@ func RequireRepoReaderOr(unitTypes ...unit.Type) func(ctx *Context) {
8080
var args []interface{}
8181
if ctx.IsSigned {
8282
format = "Permission Denied: User %-v cannot read ["
83-
args = append(args, ctx.User)
83+
args = append(args, ctx.Doer)
8484
} else {
8585
format = "Permission Denied: Anonymous user cannot read ["
8686
}

0 commit comments

Comments
 (0)