Skip to content

Commit a10c911

Browse files
committed
Use constants
1 parent a84950a commit a10c911

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

routers/web/user/setting/keys.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import (
2020

2121
const (
2222
tplSettingsKeys base.TplName = "user/settings/keys"
23+
24+
UserPasswordKey = "password"
25+
UserGPGKeysKey = "gpg keys"
26+
UserDeletionKey = "deletion"
27+
UserSecurityKey = "security"
28+
UserApplicationKey = "applications"
29+
UserOrganizations = "organizations"
2330
)
2431

2532
// Keys render user's SSH/GPG public keys page
@@ -78,7 +85,7 @@ func KeysPost(ctx *context.Context) {
7885
ctx.Flash.Success(ctx.Tr("settings.add_principal_success", form.Content))
7986
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
8087
case "gpg":
81-
if !setting.User.Enabled("gpg keys") {
88+
if !setting.User.Enabled(UserGPGKeysKey) {
8289
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting are not allowed"))
8390
return
8491
}
@@ -222,7 +229,7 @@ func KeysPost(ctx *context.Context) {
222229
func DeleteKey(ctx *context.Context) {
223230
switch ctx.FormString("type") {
224231
case "gpg":
225-
if !setting.User.Enabled("gpg keys") {
232+
if !setting.User.Enabled(UserGPGKeysKey) {
226233
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting are not allowed"))
227234
return
228235
}

routers/web/web.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,15 @@ func RegisterRoutes(m *web.Route) {
414414
m.Group("/user/settings", func() {
415415
m.Get("", user_setting.Profile)
416416
m.Post("", bindIgnErr(forms.UpdateProfileForm{}), user_setting.ProfilePost)
417-
m.Get("/change_password", userSettingModuleEnabled("password"), auth.MustChangePassword)
418-
m.Post("/change_password", userSettingModuleEnabled("password"), bindIgnErr(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
417+
m.Get("/change_password", userSettingModuleEnabled(user_setting.UserPasswordKey), auth.MustChangePassword)
418+
m.Post("/change_password", userSettingModuleEnabled(user_setting.UserPasswordKey), bindIgnErr(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
419419
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), user_setting.AvatarPost)
420420
m.Post("/avatar/delete", user_setting.DeleteAvatar)
421421
m.Group("/account", func() {
422422
m.Combo("").Get(user_setting.Account).Post(bindIgnErr(forms.ChangePasswordForm{}), user_setting.AccountPost)
423423
m.Post("/email", bindIgnErr(forms.AddEmailForm{}), user_setting.EmailPost)
424424
m.Post("/email/delete", user_setting.DeleteEmail)
425-
m.Post("/delete", userSettingModuleEnabled("deletion"), user_setting.DeleteAccount)
425+
m.Post("/delete", userSettingModuleEnabled(user_setting.UserDeletionKey), user_setting.DeleteAccount)
426426
})
427427
m.Group("/appearance", func() {
428428
m.Get("", user_setting.Appearance)
@@ -449,18 +449,18 @@ func RegisterRoutes(m *web.Route) {
449449
m.Post("/toggle_visibility", security.ToggleOpenIDVisibility)
450450
}, openIDSignInEnabled)
451451
m.Post("/account_link", linkAccountEnabled, security.DeleteAccountLink)
452-
}, userSettingModuleEnabled("security"))
452+
}, userSettingModuleEnabled(user_setting.UserSecurityKey))
453453
m.Group("/applications/oauth2", func() {
454454
m.Get("/{id}", user_setting.OAuth2ApplicationShow)
455455
m.Post("/{id}", bindIgnErr(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsEdit)
456456
m.Post("/{id}/regenerate_secret", user_setting.OAuthApplicationsRegenerateSecret)
457457
m.Post("", bindIgnErr(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsPost)
458458
m.Post("/{id}/delete", user_setting.DeleteOAuth2Application)
459459
m.Post("/{id}/revoke/{grantId}", user_setting.RevokeOAuth2Grant)
460-
}, userSettingModuleEnabled("applications"))
461-
m.Combo("/applications").Get(userSettingModuleEnabled("applications"), user_setting.Applications).
462-
Post(userSettingModuleEnabled("applications"), bindIgnErr(forms.NewAccessTokenForm{}), user_setting.ApplicationsPost)
463-
m.Post("/applications/delete", userSettingModuleEnabled("applications"), user_setting.DeleteApplication)
460+
}, userSettingModuleEnabled(user_setting.UserApplicationKey))
461+
m.Combo("/applications").Get(userSettingModuleEnabled(user_setting.UserApplicationKey), user_setting.Applications).
462+
Post(userSettingModuleEnabled(user_setting.UserApplicationKey), bindIgnErr(forms.NewAccessTokenForm{}), user_setting.ApplicationsPost)
463+
m.Post("/applications/delete", userSettingModuleEnabled(user_setting.UserApplicationKey), user_setting.DeleteApplication)
464464
m.Combo("/keys").Get(user_setting.Keys).
465465
Post(bindIgnErr(forms.AddKeyForm{}), user_setting.KeysPost)
466466
m.Post("/keys/delete", user_setting.DeleteKey)
@@ -478,7 +478,7 @@ func RegisterRoutes(m *web.Route) {
478478
})
479479
})
480480
}, packagesEnabled)
481-
m.Get("/organization", userSettingModuleEnabled("organizations"), user_setting.Organization)
481+
m.Get("/organization", userSettingModuleEnabled(user_setting.UserOrganizations), user_setting.Organization)
482482
m.Get("/repos", user_setting.Repos)
483483
m.Post("/repos/unadopted", user_setting.AdoptOrDeleteRepository)
484484
}, reqSignIn, func(ctx *context.Context) {

0 commit comments

Comments
 (0)