loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: remove deadcode in `models/user` (#6728)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6728
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>

Otto dfcf3f11 2ba8946c

-81
-4
.deadcode-out
··· 81 81 WatchRepoMode 82 82 83 83 code.gitea.io/gitea/models/user 84 - ErrUserInactive.Error 85 - ErrUserInactive.Unwrap 86 84 IsErrExternalLoginUserAlreadyExist 87 85 IsErrExternalLoginUserNotExist 88 86 NewFederatedUser 89 87 IsErrUserSettingIsNotExist 90 88 GetUserAllSettings 91 89 DeleteUserSetting 92 - GetUserEmailsByNames 93 - GetUserNamesByIDs 94 90 95 91 code.gitea.io/gitea/modules/activitypub 96 92 NewContext
-21
models/user/error.go
··· 71 71 return util.ErrPermissionDenied 72 72 } 73 73 74 - // ErrUserInactive represents a "ErrUserInactive" kind of error. 75 - type ErrUserInactive struct { 76 - UID int64 77 - Name string 78 - } 79 - 80 - // IsErrUserInactive checks if an error is a ErrUserInactive 81 - func IsErrUserInactive(err error) bool { 82 - _, ok := err.(ErrUserInactive) 83 - return ok 84 - } 85 - 86 - func (err ErrUserInactive) Error() string { 87 - return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name) 88 - } 89 - 90 - // Unwrap unwraps this error as a ErrPermission error 91 - func (err ErrUserInactive) Unwrap() error { 92 - return util.ErrPermissionDenied 93 - } 94 - 95 74 // ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error. 96 75 type ErrUserIsNotLocal struct { 97 76 UID int64
-27
models/user/user.go
··· 1043 1043 return u, nil 1044 1044 } 1045 1045 1046 - // GetUserEmailsByNames returns a list of e-mails corresponds to names of users 1047 - // that have their email notifications set to enabled or onmention. 1048 - func GetUserEmailsByNames(ctx context.Context, names []string) []string { 1049 - mails := make([]string, 0, len(names)) 1050 - for _, name := range names { 1051 - u, err := GetUserByName(ctx, name) 1052 - if err != nil { 1053 - continue 1054 - } 1055 - if u.IsMailable() && u.EmailNotificationsPreference != EmailNotificationsDisabled { 1056 - mails = append(mails, u.Email) 1057 - } 1058 - } 1059 - return mails 1060 - } 1061 - 1062 1046 // GetMaileableUsersByIDs gets users from ids, but only if they can receive mails 1063 1047 func GetMaileableUsersByIDs(ctx context.Context, ids []int64, isMention bool) ([]*User, error) { 1064 1048 if len(ids) == 0 { ··· 1083 1067 And("`is_active` = ?", true). 1084 1068 In("`email_notifications_preference`", EmailNotificationsEnabled, EmailNotificationsAndYourOwn). 1085 1069 Find(&ous) 1086 - } 1087 - 1088 - // GetUserNamesByIDs returns usernames for all resolved users from a list of Ids. 1089 - func GetUserNamesByIDs(ctx context.Context, ids []int64) ([]string, error) { 1090 - unames := make([]string, 0, len(ids)) 1091 - err := db.GetEngine(ctx).In("id", ids). 1092 - Table("user"). 1093 - Asc("name"). 1094 - Cols("name"). 1095 - Find(&unames) 1096 - return unames, err 1097 1070 } 1098 1071 1099 1072 // GetUserNameByID returns username for the id
-10
models/user/user_test.go
··· 102 102 } 103 103 } 104 104 105 - func TestGetUserEmailsByNames(t *testing.T) { 106 - require.NoError(t, unittest.PrepareTestDatabase()) 107 - 108 - // ignore none active user email 109 - assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"})) 110 - assert.ElementsMatch(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"})) 111 - 112 - assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "org7"})) 113 - } 114 - 115 105 func TestCanCreateOrganization(t *testing.T) { 116 106 require.NoError(t, unittest.PrepareTestDatabase()) 117 107
-9
routers/web/auth/auth.go
··· 225 225 log.Warn("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err) 226 226 ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") 227 227 ctx.HTML(http.StatusOK, "user/auth/prohibit_login") 228 - } else if user_model.IsErrUserInactive(err) { 229 - if setting.Service.RegisterEmailConfirm { 230 - ctx.Data["Title"] = ctx.Tr("auth.active_your_account") 231 - ctx.HTML(http.StatusOK, TplActivate) 232 - } else { 233 - log.Warn("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err) 234 - ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") 235 - ctx.HTML(http.StatusOK, "user/auth/prohibit_login") 236 - } 237 228 } else { 238 229 ctx.ServerError("UserSignIn", err) 239 230 }
-10
routers/web/auth/linkaccount.go
··· 99 99 log.Info("Failed authentication attempt for %s from %s: %v", userName, ctx.RemoteAddr(), err) 100 100 ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") 101 101 ctx.HTML(http.StatusOK, "user/auth/prohibit_login") 102 - } else if user_model.IsErrUserInactive(err) { 103 - ctx.Data["user_exists"] = true 104 - if setting.Service.RegisterEmailConfirm { 105 - ctx.Data["Title"] = ctx.Tr("auth.active_your_account") 106 - ctx.HTML(http.StatusOK, TplActivate) 107 - } else { 108 - log.Info("Failed authentication attempt for %s from %s: %v", userName, ctx.RemoteAddr(), err) 109 - ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") 110 - ctx.HTML(http.StatusOK, "user/auth/prohibit_login") 111 - } 112 102 } else { 113 103 ctx.ServerError(invoker, err) 114 104 }