Skip to content

Commit

Permalink
Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Dec 11, 2022
1 parent a84950a commit a10c911
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
11 changes: 9 additions & 2 deletions routers/web/user/setting/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (

const (
tplSettingsKeys base.TplName = "user/settings/keys"

UserPasswordKey = "password"
UserGPGKeysKey = "gpg keys"
UserDeletionKey = "deletion"
UserSecurityKey = "security"
UserApplicationKey = "applications"
UserOrganizations = "organizations"
)

// Keys render user's SSH/GPG public keys page
Expand Down Expand Up @@ -78,7 +85,7 @@ func KeysPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("settings.add_principal_success", form.Content))
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
case "gpg":
if !setting.User.Enabled("gpg keys") {
if !setting.User.Enabled(UserGPGKeysKey) {
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting are not allowed"))
return
}
Expand Down Expand Up @@ -222,7 +229,7 @@ func KeysPost(ctx *context.Context) {
func DeleteKey(ctx *context.Context) {
switch ctx.FormString("type") {
case "gpg":
if !setting.User.Enabled("gpg keys") {
if !setting.User.Enabled(UserGPGKeysKey) {
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting are not allowed"))
return
}
Expand Down
18 changes: 9 additions & 9 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ func RegisterRoutes(m *web.Route) {
m.Group("/user/settings", func() {
m.Get("", user_setting.Profile)
m.Post("", bindIgnErr(forms.UpdateProfileForm{}), user_setting.ProfilePost)
m.Get("/change_password", userSettingModuleEnabled("password"), auth.MustChangePassword)
m.Post("/change_password", userSettingModuleEnabled("password"), bindIgnErr(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
m.Get("/change_password", userSettingModuleEnabled(user_setting.UserPasswordKey), auth.MustChangePassword)
m.Post("/change_password", userSettingModuleEnabled(user_setting.UserPasswordKey), bindIgnErr(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), user_setting.AvatarPost)
m.Post("/avatar/delete", user_setting.DeleteAvatar)
m.Group("/account", func() {
m.Combo("").Get(user_setting.Account).Post(bindIgnErr(forms.ChangePasswordForm{}), user_setting.AccountPost)
m.Post("/email", bindIgnErr(forms.AddEmailForm{}), user_setting.EmailPost)
m.Post("/email/delete", user_setting.DeleteEmail)
m.Post("/delete", userSettingModuleEnabled("deletion"), user_setting.DeleteAccount)
m.Post("/delete", userSettingModuleEnabled(user_setting.UserDeletionKey), user_setting.DeleteAccount)
})
m.Group("/appearance", func() {
m.Get("", user_setting.Appearance)
Expand All @@ -449,18 +449,18 @@ func RegisterRoutes(m *web.Route) {
m.Post("/toggle_visibility", security.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
m.Post("/account_link", linkAccountEnabled, security.DeleteAccountLink)
}, userSettingModuleEnabled("security"))
}, userSettingModuleEnabled(user_setting.UserSecurityKey))
m.Group("/applications/oauth2", func() {
m.Get("/{id}", user_setting.OAuth2ApplicationShow)
m.Post("/{id}", bindIgnErr(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsEdit)
m.Post("/{id}/regenerate_secret", user_setting.OAuthApplicationsRegenerateSecret)
m.Post("", bindIgnErr(forms.EditOAuth2ApplicationForm{}), user_setting.OAuthApplicationsPost)
m.Post("/{id}/delete", user_setting.DeleteOAuth2Application)
m.Post("/{id}/revoke/{grantId}", user_setting.RevokeOAuth2Grant)
}, userSettingModuleEnabled("applications"))
m.Combo("/applications").Get(userSettingModuleEnabled("applications"), user_setting.Applications).
Post(userSettingModuleEnabled("applications"), bindIgnErr(forms.NewAccessTokenForm{}), user_setting.ApplicationsPost)
m.Post("/applications/delete", userSettingModuleEnabled("applications"), user_setting.DeleteApplication)
}, userSettingModuleEnabled(user_setting.UserApplicationKey))
m.Combo("/applications").Get(userSettingModuleEnabled(user_setting.UserApplicationKey), user_setting.Applications).
Post(userSettingModuleEnabled(user_setting.UserApplicationKey), bindIgnErr(forms.NewAccessTokenForm{}), user_setting.ApplicationsPost)
m.Post("/applications/delete", userSettingModuleEnabled(user_setting.UserApplicationKey), user_setting.DeleteApplication)
m.Combo("/keys").Get(user_setting.Keys).
Post(bindIgnErr(forms.AddKeyForm{}), user_setting.KeysPost)
m.Post("/keys/delete", user_setting.DeleteKey)
Expand All @@ -478,7 +478,7 @@ func RegisterRoutes(m *web.Route) {
})
})
}, packagesEnabled)
m.Get("/organization", userSettingModuleEnabled("organizations"), user_setting.Organization)
m.Get("/organization", userSettingModuleEnabled(user_setting.UserOrganizations), user_setting.Organization)
m.Get("/repos", user_setting.Repos)
m.Post("/repos/unadopted", user_setting.AdoptOrDeleteRepository)
}, reqSignIn, func(ctx *context.Context) {
Expand Down

0 comments on commit a10c911

Please sign in to comment.