Skip to content

Commit 311bf54

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix ldap user sync missed email in email_address table (go-gitea#18786) Update assignees check to include any writing team and change org sidebar (go-gitea#18680) Set max text height to prevent overflow (go-gitea#18862) Lock gofumpt to v0.3.0 and run it (go-gitea#18866)
2 parents 0362638 + f1b1472 commit 311bf54

File tree

21 files changed

+146
-57
lines changed

21 files changed

+146
-57
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ clean:
235235
.PHONY: fmt
236236
fmt:
237237
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
238-
$(GO) install mvdan.cc/gofumpt@latest; \
238+
$(GO) install mvdan.cc/gofumpt@v0.3.0; \
239239
fi
240240
@echo "Running gitea-fmt (with gofumpt)..."
241241
@$(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
@@ -287,7 +287,7 @@ errcheck:
287287
.PHONY: fmt-check
288288
fmt-check:
289289
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
290-
$(GO) install mvdan.cc/gofumpt@latest; \
290+
$(GO) install mvdan.cc/gofumpt@0.3.0; \
291291
fi
292292
# get all go files and run gitea-fmt (with gofmt) on them
293293
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \

models/issue_xref.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ func (issue *Issue) updateCrossReferenceList(list []*crossReference, xref *cross
195195

196196
// verifyReferencedIssue will check if the referenced issue exists, and whether the doer has permission to do what
197197
func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossReferencesContext, repo *repo_model.Repository,
198-
ref references.IssueReference) (*Issue, references.XRefAction, error) {
198+
ref references.IssueReference,
199+
) (*Issue, references.XRefAction, error) {
199200
refIssue := &Issue{RepoID: repo.ID, Index: ref.Index}
200201
refAction := ref.Action
201202
e := db.GetEngine(stdCtx)

models/migrations/v210.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"strings"
1212

1313
"code.gitea.io/gitea/modules/timeutil"
14-
"github.com/tstranex/u2f"
1514

15+
"github.com/tstranex/u2f"
1616
"xorm.io/xorm"
1717
"xorm.io/xorm/schemas"
1818
)

models/migrations/v210_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"code.gitea.io/gitea/modules/timeutil"
11+
1112
"github.com/stretchr/testify/assert"
1213
"xorm.io/xorm/schemas"
1314
)

models/repo.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,27 +150,56 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
150150
}
151151

152152
e := db.GetEngine(ctx)
153-
accesses := make([]*Access, 0, 10)
154-
if err = e.
153+
userIDs := make([]int64, 0, 10)
154+
if err = e.Table("access").
155155
Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite).
156-
Find(&accesses); err != nil {
156+
Select("id").
157+
Find(&userIDs); err != nil {
157158
return nil, err
158159
}
159160

160-
// Leave a seat for owner itself to append later, but if owner is an organization
161-
// and just waste 1 unit is cheaper than re-allocate memory once.
162-
users := make([]*user_model.User, 0, len(accesses)+1)
163-
if len(accesses) > 0 {
164-
userIDs := make([]int64, len(accesses))
165-
for i := 0; i < len(accesses); i++ {
166-
userIDs[i] = accesses[i].UserID
161+
additionalUserIDs := make([]int64, 0, 10)
162+
if err = e.Table("team_user").
163+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
164+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
165+
Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite).
166+
Distinct("`team_user`.uid").
167+
Select("`team_user`.uid").
168+
Find(&additionalUserIDs); err != nil {
169+
return nil, err
170+
}
171+
172+
uidMap := map[int64]bool{}
173+
i := 0
174+
for _, uid := range userIDs {
175+
if uidMap[uid] {
176+
continue
177+
}
178+
uidMap[uid] = true
179+
userIDs[i] = uid
180+
i++
181+
}
182+
userIDs = userIDs[:i]
183+
userIDs = append(userIDs, additionalUserIDs...)
184+
185+
for _, uid := range additionalUserIDs {
186+
if uidMap[uid] {
187+
continue
167188
}
189+
userIDs[i] = uid
190+
i++
191+
}
192+
userIDs = userIDs[:i]
168193

194+
// Leave a seat for owner itself to append later, but if owner is an organization
195+
// and just waste 1 unit is cheaper than re-allocate memory once.
196+
users := make([]*user_model.User, 0, len(userIDs)+1)
197+
if len(userIDs) > 0 {
169198
if err = e.In("id", userIDs).Find(&users); err != nil {
170199
return nil, err
171200
}
172201
}
173-
if !repo.Owner.IsOrganization() {
202+
if !repo.Owner.IsOrganization() && !uidMap[repo.OwnerID] {
174203
users = append(users, repo.Owner)
175204
}
176205

models/user/user.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,9 @@ func validateUser(u *User) error {
827827
return ValidateEmail(u.Email)
828828
}
829829

830-
func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error {
831-
if err := validateUser(u); err != nil {
830+
func updateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...string) error {
831+
err := validateUser(u)
832+
if err != nil {
832833
return err
833834
}
834835

@@ -860,15 +861,34 @@ func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error {
860861
}); err != nil {
861862
return err
862863
}
864+
} else { // check if primary email in email_address table
865+
primaryEmailExist, err := e.Where("uid=? AND is_primary=?", u.ID, true).Exist(&EmailAddress{})
866+
if err != nil {
867+
return err
868+
}
869+
870+
if !primaryEmailExist {
871+
_, err = e.Insert(&EmailAddress{
872+
Email: u.Email,
873+
UID: u.ID,
874+
IsActivated: true,
875+
IsPrimary: true,
876+
})
877+
return err
878+
}
863879
}
864880

865-
_, err := e.ID(u.ID).AllCols().Update(u)
881+
if len(cols) == 0 {
882+
_, err = e.ID(u.ID).AllCols().Update(u)
883+
} else {
884+
_, err = e.ID(u.ID).Cols(cols...).Update(u)
885+
}
866886
return err
867887
}
868888

869889
// UpdateUser updates user's information.
870-
func UpdateUser(u *User, emailChanged bool) error {
871-
return updateUser(db.DefaultContext, u, emailChanged)
890+
func UpdateUser(u *User, emailChanged bool, cols ...string) error {
891+
return updateUser(db.DefaultContext, u, emailChanged, cols...)
872892
}
873893

874894
// UpdateUserCols update user according special columns

modules/indexer/code/bleve.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) {
182182
}
183183

184184
func (b *BleveIndexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string,
185-
update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch) error {
185+
update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch,
186+
) error {
186187
// Ignore vendored files in code search
187188
if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) {
188189
return nil

modules/notification/action/action.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *m
9191

9292
// NotifyCreateIssueComment notifies comment on an issue to notifiers
9393
func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
94-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
94+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
95+
) {
9596
act := &models.Action{
9697
ActUserID: doer.ID,
9798
ActUser: doer,

modules/notification/indexer/indexer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func NewNotifier() base.Notifier {
3030
}
3131

3232
func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
33-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
33+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
34+
) {
3435
if comment.Type == models.CommentTypeComment {
3536
if issue.Comments == nil {
3637
if err := issue.LoadDiscussComments(); err != nil {

modules/notification/mail/mail.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func NewNotifier() base.Notifier {
2929
}
3030

3131
func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
32-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
32+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
33+
) {
3334
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyCreateIssueComment Issue[%d] #%d in [%d]", issue.ID, issue.Index, issue.RepoID))
3435
defer finished()
3536

0 commit comments

Comments
 (0)