Skip to content

Commit 81af77f

Browse files
authored
Merge branch 'main' into refactor-route
2 parents b4d1a60 + 254314b commit 81af77f

Some content is hidden

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

62 files changed

+1234
-788
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ module.exports = {
674674
'no-this-before-super': [2],
675675
'no-throw-literal': [2],
676676
'no-undef-init': [2],
677-
'no-undef': [0],
677+
'no-undef': [2], // it is still needed by eslint & IDE to prompt undefined names in real time
678678
'no-undefined': [0],
679679
'no-underscore-dangle': [0],
680680
'no-unexpected-multiline': [2],

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,9 @@ LEVEL = Info
13391339
;; Number of repos that are displayed on one page
13401340
;REPO_PAGING_NUM = 15
13411341

1342+
;; Number of orgs that are displayed on profile page
1343+
;ORG_PAGING_NUM = 15
1344+
13421345
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13431346
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13441347
;[ui.meta]

models/fixtures/label.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@
9696
num_issues: 0
9797
num_closed_issues: 0
9898
archived_unix: 0
99+
100+
-
101+
id: 10
102+
repo_id: 3
103+
org_id: 0
104+
name: repo3label1
105+
color: '#112233'
106+
exclusive: false
107+
num_issues: 0
108+
num_closed_issues: 0
109+
archived_unix: 0

models/issues/label.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,17 @@ func GetLabelIDsInRepoByNames(ctx context.Context, repoID int64, labelNames []st
349349
Find(&labelIDs)
350350
}
351351

352+
// GetLabelIDsInOrgByNames returns a list of labelIDs by names in a given org.
353+
func GetLabelIDsInOrgByNames(ctx context.Context, orgID int64, labelNames []string) ([]int64, error) {
354+
labelIDs := make([]int64, 0, len(labelNames))
355+
return labelIDs, db.GetEngine(ctx).Table("label").
356+
Where("org_id = ?", orgID).
357+
In("name", labelNames).
358+
Asc("name").
359+
Cols("id").
360+
Find(&labelIDs)
361+
}
362+
352363
// BuildLabelNamesIssueIDsCondition returns a builder where get issue ids match label names
353364
func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
354365
return builder.Select("issue_label.issue_id").

models/user/email_address.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ func VerifyActiveEmailCode(ctx context.Context, code, email string) *EmailAddres
357357
if user := GetVerifyUser(ctx, code); user != nil {
358358
// time limit code
359359
prefix := code[:base.TimeLimitCodeLength]
360-
data := fmt.Sprintf("%d%s%s%s%s", user.ID, email, user.LowerName, user.Passwd, user.Rands)
361-
360+
opts := &TimeLimitCodeOptions{Purpose: TimeLimitCodeActivateEmail, NewEmail: email}
361+
data := makeTimeLimitCodeHashData(opts, user)
362362
if base.VerifyTimeLimitCode(time.Now(), data, setting.Service.ActiveCodeLives, prefix) {
363363
emailAddress := &EmailAddress{UID: user.ID, Email: email}
364364
if has, _ := db.GetEngine(ctx).Get(emailAddress); has {
@@ -486,10 +486,10 @@ func ActivateUserEmail(ctx context.Context, userID int64, email string, activate
486486

487487
// Activate/deactivate a user's primary email address and account
488488
if addr.IsPrimary {
489-
user, exist, err := db.Get[User](ctx, builder.Eq{"id": userID, "email": email})
489+
user, exist, err := db.Get[User](ctx, builder.Eq{"id": userID})
490490
if err != nil {
491491
return err
492-
} else if !exist {
492+
} else if !exist || !strings.EqualFold(user.Email, email) {
493493
return fmt.Errorf("no user with ID: %d and Email: %s", userID, email)
494494
}
495495

models/user/user.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ func (u *User) BeforeUpdate() {
181181
u.MaxRepoCreation = -1
182182
}
183183

184-
// Organization does not need email
184+
// FIXME: this email doesn't need to be in lowercase, because the emails are mainly managed by the email table with lower_email field
185+
// This trick could be removed in new releases to display the user inputed email as-is.
185186
u.Email = strings.ToLower(u.Email)
186187
if !u.IsOrganization() {
187188
if len(u.AvatarEmail) == 0 {
@@ -310,17 +311,6 @@ func (u *User) OrganisationLink() string {
310311
return setting.AppSubURL + "/org/" + url.PathEscape(u.Name)
311312
}
312313

313-
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
314-
func (u *User) GenerateEmailActivateCode(email string) string {
315-
code := base.CreateTimeLimitCode(
316-
fmt.Sprintf("%d%s%s%s%s", u.ID, email, u.LowerName, u.Passwd, u.Rands),
317-
setting.Service.ActiveCodeLives, time.Now(), nil)
318-
319-
// Add tail hex username
320-
code += hex.EncodeToString([]byte(u.LowerName))
321-
return code
322-
}
323-
324314
// GetUserFollowers returns range of user's followers.
325315
func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListOptions) ([]*User, int64, error) {
326316
sess := db.GetEngine(ctx).
@@ -863,12 +853,38 @@ func GetVerifyUser(ctx context.Context, code string) (user *User) {
863853
return nil
864854
}
865855

866-
// VerifyUserActiveCode verifies active code when active account
867-
func VerifyUserActiveCode(ctx context.Context, code string) (user *User) {
856+
type TimeLimitCodePurpose string
857+
858+
const (
859+
TimeLimitCodeActivateAccount TimeLimitCodePurpose = "activate_account"
860+
TimeLimitCodeActivateEmail TimeLimitCodePurpose = "activate_email"
861+
TimeLimitCodeResetPassword TimeLimitCodePurpose = "reset_password"
862+
)
863+
864+
type TimeLimitCodeOptions struct {
865+
Purpose TimeLimitCodePurpose
866+
NewEmail string
867+
}
868+
869+
func makeTimeLimitCodeHashData(opts *TimeLimitCodeOptions, u *User) string {
870+
return fmt.Sprintf("%s|%d|%s|%s|%s|%s", opts.Purpose, u.ID, strings.ToLower(util.IfZero(opts.NewEmail, u.Email)), u.LowerName, u.Passwd, u.Rands)
871+
}
872+
873+
// GenerateUserTimeLimitCode generates a time-limit code based on user information and given e-mail.
874+
// TODO: need to use cache or db to store it to make sure a code can only be consumed once
875+
func GenerateUserTimeLimitCode(opts *TimeLimitCodeOptions, u *User) string {
876+
data := makeTimeLimitCodeHashData(opts, u)
877+
code := base.CreateTimeLimitCode(data, setting.Service.ActiveCodeLives, time.Now(), nil)
878+
code += hex.EncodeToString([]byte(u.LowerName)) // Add tail hex username
879+
return code
880+
}
881+
882+
// VerifyUserTimeLimitCode verifies the time-limit code
883+
func VerifyUserTimeLimitCode(ctx context.Context, opts *TimeLimitCodeOptions, code string) (user *User) {
868884
if user = GetVerifyUser(ctx, code); user != nil {
869885
// time limit code
870886
prefix := code[:base.TimeLimitCodeLength]
871-
data := fmt.Sprintf("%d%s%s%s%s", user.ID, user.Email, user.LowerName, user.Passwd, user.Rands)
887+
data := makeTimeLimitCodeHashData(opts, user)
872888
if base.VerifyTimeLimitCode(time.Now(), data, setting.Service.ActiveCodeLives, prefix) {
873889
return user
874890
}

modules/setting/ui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var UI = struct {
6363
} `ini:"ui.admin"`
6464
User struct {
6565
RepoPagingNum int
66+
OrgPagingNum int
6667
} `ini:"ui.user"`
6768
Meta struct {
6869
Author string
@@ -127,8 +128,10 @@ var UI = struct {
127128
},
128129
User: struct {
129130
RepoPagingNum int
131+
OrgPagingNum int
130132
}{
131133
RepoPagingNum: 15,
134+
OrgPagingNum: 15,
132135
},
133136
Meta: struct {
134137
Author string

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ joined_on=Přidal/a se %s
647647
repositories=Repozitáře
648648
activity=Veřejná aktivita
649649
followers=Sledující
650+
show_more=Zobrazit více
650651
starred=Oblíbené repozitáře
651652
watched=Sledované repozitáře
652653
code=Kód

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ joined_on=Beigetreten am %s
618618
repositories=Repositories
619619
activity=Öffentliche Aktivität
620620
followers=Follower
621+
show_more=Mehr anzeigen
621622
starred=Favoriten
622623
watched=Beobachtete Repositories
623624
code=Quelltext

options/locale/locale_el-GR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ joined_on=Εγγράφηκε την %s
580580
repositories=Αποθετήρια
581581
activity=Δημόσια Δραστηριότητα
582582
followers=Ακόλουθοι
583+
show_more=Εμφάνιση Περισσότερων
583584
starred=Αγαπημένα Αποθετήρια
584585
watched=Ακολουθούμενα Αποθετήρια
585586
code=Κώδικας

0 commit comments

Comments
 (0)