Skip to content

Commit 099372d

Browse files
daviianlafriks
authored andcommitted
Refactor User Settings (#3900)
* moved avatar to profile page * combined password change, email and account deletion into account settings page * combined totp, access tokens, linked accounts and openid into security settings page * move access tokens to applications settings page * small change to restart drone build * fix change avatar url on profile page * redirect old settings urls to new ones * enforce only one autofocus attribute on settings pages * set correct redirect status code * fmt fix
1 parent 1546458 commit 099372d

25 files changed

+582
-688
lines changed

integrations/delete_user_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func TestUserDeleteAccount(t *testing.T) {
4343
prepareTestEnv(t)
4444

4545
session := loginUser(t, "user8")
46-
csrf := GetCSRF(t, session, "/user/settings/delete")
47-
urlStr := fmt.Sprintf("/user/settings/delete?password=%s", userPassword)
46+
csrf := GetCSRF(t, session, "/user/settings/account")
47+
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
4848
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
4949
"_csrf": csrf,
5050
})
@@ -58,8 +58,8 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
5858
prepareTestEnv(t)
5959

6060
session := loginUser(t, "user2")
61-
csrf := GetCSRF(t, session, "/user/settings/delete")
62-
urlStr := fmt.Sprintf("/user/settings/delete?password=%s", userPassword)
61+
csrf := GetCSRF(t, session, "/user/settings/account")
62+
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
6363
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
6464
"_csrf": csrf,
6565
})

integrations/links_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,12 @@ func testLinksAsUser(userName string, t *testing.T) {
9393
"/user2?tab=stars",
9494
"/user2?tab=activity",
9595
"/user/settings",
96-
"/user/settings/avatar",
96+
"/user/settings/account",
9797
"/user/settings/security",
9898
"/user/settings/security/two_factor/enroll",
99-
"/user/settings/email",
10099
"/user/settings/keys",
101-
"/user/settings/applications",
102-
"/user/settings/account_link",
103100
"/user/settings/organization",
104-
"/user/settings/delete",
101+
"/user/settings/repos",
105102
}
106103

107104
session := loginUser(t, userName)

options/locale/locale_en-US.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,13 @@ form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username.
306306
307307
[settings]
308308
profile = Profile
309+
account = Account
309310
password = Password
310311
security = Security
311312
avatar = Avatar
312313
ssh_gpg_keys = SSH / GPG Keys
313314
social = Social Accounts
314-
applications = Access Tokens
315+
applications = Applications
315316
orgs = Manage Organizations
316317
repos = Repositories
317318
delete = Delete Account

routers/routes/routes.go

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/go-macaron/session"
3838
"github.com/go-macaron/toolbox"
3939
"gopkg.in/macaron.v1"
40+
"net/http"
4041
)
4142

4243
// NewMacaron initializes Macaron instance.
@@ -217,35 +218,54 @@ func RegisterRoutes(m *macaron.Macaron) {
217218
m.Group("/user/settings", func() {
218219
m.Get("", user.Settings)
219220
m.Post("", bindIgnErr(auth.UpdateProfileForm{}), user.SettingsPost)
220-
m.Combo("/avatar").Get(user.SettingsAvatar).
221-
Post(binding.MultipartForm(auth.AvatarForm{}), user.SettingsAvatarPost)
221+
m.Post("/avatar", binding.MultipartForm(auth.AvatarForm{}), user.SettingsAvatarPost)
222222
m.Post("/avatar/delete", user.SettingsDeleteAvatar)
223-
m.Combo("/email").Get(user.SettingsEmails).
224-
Post(bindIgnErr(auth.AddEmailForm{}), user.SettingsEmailPost)
225-
m.Post("/email/delete", user.DeleteEmail)
226-
m.Get("/security", user.SettingsSecurity)
227-
m.Post("/security", bindIgnErr(auth.ChangePasswordForm{}), user.SettingsSecurityPost)
228-
m.Group("/openid", func() {
229-
m.Combo("").Get(user.SettingsOpenID).
230-
Post(bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
231-
m.Post("/delete", user.DeleteOpenID)
232-
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
233-
}, openIDSignInEnabled)
234-
m.Combo("/keys").Get(user.SettingsKeys).
235-
Post(bindIgnErr(auth.AddKeyForm{}), user.SettingsKeysPost)
236-
m.Post("/keys/delete", user.DeleteKey)
223+
m.Group("/account", func() {
224+
m.Combo("").Get(user.SettingsAccount).Post(bindIgnErr(auth.ChangePasswordForm{}), user.SettingsAccountPost)
225+
m.Post("/email", bindIgnErr(auth.AddEmailForm{}), user.SettingsEmailPost)
226+
m.Post("/email/delete", user.DeleteEmail)
227+
m.Post("/delete", user.SettingsDelete)
228+
})
229+
m.Group("/security", func() {
230+
m.Get("", user.SettingsSecurity)
231+
m.Group("/two_factor", func() {
232+
m.Post("/regenerate_scratch", user.SettingsTwoFactorRegenerateScratch)
233+
m.Post("/disable", user.SettingsTwoFactorDisable)
234+
m.Get("/enroll", user.SettingsTwoFactorEnroll)
235+
m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), user.SettingsTwoFactorEnrollPost)
236+
})
237+
m.Group("/openid", func() {
238+
m.Post("", bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
239+
m.Post("/delete", user.DeleteOpenID)
240+
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
241+
}, openIDSignInEnabled)
242+
m.Post("/account_link", user.SettingsDeleteAccountLink)
243+
})
237244
m.Combo("/applications").Get(user.SettingsApplications).
238245
Post(bindIgnErr(auth.NewAccessTokenForm{}), user.SettingsApplicationsPost)
239246
m.Post("/applications/delete", user.SettingsDeleteApplication)
240-
m.Route("/delete", "GET,POST", user.SettingsDelete)
241-
m.Combo("/account_link").Get(user.SettingsAccountLinks).Post(user.SettingsDeleteAccountLink)
247+
m.Combo("/keys").Get(user.SettingsKeys).
248+
Post(bindIgnErr(auth.AddKeyForm{}), user.SettingsKeysPost)
249+
m.Post("/keys/delete", user.DeleteKey)
242250
m.Get("/organization", user.SettingsOrganization)
243251
m.Get("/repos", user.SettingsRepos)
244-
m.Group("/security/two_factor", func() {
245-
m.Post("/regenerate_scratch", user.SettingsTwoFactorRegenerateScratch)
246-
m.Post("/disable", user.SettingsTwoFactorDisable)
247-
m.Get("/enroll", user.SettingsTwoFactorEnroll)
248-
m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), user.SettingsTwoFactorEnrollPost)
252+
253+
// redirects from old settings urls to new ones
254+
// TODO: can be removed on next major version
255+
m.Get("/avatar", func(ctx *context.Context) {
256+
ctx.Redirect(setting.AppSubURL+"/user/settings", http.StatusMovedPermanently)
257+
})
258+
m.Get("/email", func(ctx *context.Context) {
259+
ctx.Redirect(setting.AppSubURL+"/user/settings/account", http.StatusMovedPermanently)
260+
})
261+
m.Get("/delete", func(ctx *context.Context) {
262+
ctx.Redirect(setting.AppSubURL+"/user/settings/account", http.StatusMovedPermanently)
263+
})
264+
m.Get("/openid", func(ctx *context.Context) {
265+
ctx.Redirect(setting.AppSubURL+"/user/settings/security", http.StatusMovedPermanently)
266+
})
267+
m.Get("/account_link", func(ctx *context.Context) {
268+
ctx.Redirect(setting.AppSubURL+"/user/settings/security", http.StatusMovedPermanently)
249269
})
250270
}, reqSignIn, func(ctx *context.Context) {
251271
ctx.Data["PageIsUserSettings"] = true

0 commit comments

Comments
 (0)