Skip to content

Commit dff6be8

Browse files
committed
Merge remote-tracking branch 'origin/main' into forgefriends-mr46
2 parents 35dfe22 + f1b1472 commit dff6be8

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

modules/notification/notification.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func NewContext() {
3939

4040
// NotifyCreateIssueComment notifies issue comment related message to notifiers
4141
func NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
42-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
42+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
43+
) {
4344
for _, notifier := range notifiers {
4445
notifier.NotifyCreateIssueComment(doer, repo, issue, comment, mentions)
4546
}
@@ -201,7 +202,8 @@ func NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef str
201202

202203
// NotifyIssueChangeLabels notifies change labels to notifiers
203204
func NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
204-
addedLabels, removedLabels []*models.Label) {
205+
addedLabels, removedLabels []*models.Label,
206+
) {
205207
for _, notifier := range notifiers {
206208
notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
207209
}

modules/notification/ui/ui.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func (ns *notificationService) Run() {
5353
}
5454

5555
func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
56-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
56+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
57+
) {
5758
opts := issueNotificationOpts{
5859
IssueID: issue.ID,
5960
NotificationAuthorID: doer.ID,

modules/notification/webhook/webhook.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *models.C
424424
}
425425

426426
func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
427-
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
427+
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
428+
) {
428429
mode, _ := models.AccessLevel(doer, repo)
429430

430431
var err error
@@ -498,7 +499,8 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *mo
498499
}
499500

500501
func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
501-
addedLabels, removedLabels []*models.Label) {
502+
addedLabels, removedLabels []*models.Label,
503+
) {
502504
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeLabels User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
503505
defer finished()
504506

modules/structs/repo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ type GenerateRepoOption struct {
220220
// CreateBranchRepoOption options when creating a branch in a repository
221221
// swagger:model
222222
type CreateBranchRepoOption struct {
223-
224223
// Name of the branch to create
225224
//
226225
// required: true

routers/web/org/teams.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func TeamMembers(ctx *context.Context) {
311311
ctx.ServerError("GetMembers", err)
312312
return
313313
}
314+
ctx.Data["Units"] = unit_model.Units
314315
ctx.HTML(http.StatusOK, tplTeamMembers)
315316
}
316317

@@ -323,6 +324,7 @@ func TeamRepositories(ctx *context.Context) {
323324
ctx.ServerError("GetRepositories", err)
324325
return
325326
}
327+
ctx.Data["Units"] = unit_model.Units
326328
ctx.HTML(http.StatusOK, tplTeamRepositories)
327329
}
328330

routers/web/repo/branch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in
233233

234234
func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, protectedBranches []*models.ProtectedBranch,
235235
repoIDToRepo map[int64]*repo_model.Repository,
236-
repoIDToGitRepo map[int64]*git.Repository) *Branch {
236+
repoIDToGitRepo map[int64]*git.Repository,
237+
) *Branch {
237238
log.Trace("loadOneBranch: '%s'", rawBranch.Name)
238239

239240
commit, err := rawBranch.GetCommit()

services/auth/source/ldap/source_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
146146
log.Trace("SyncExternalUsers[%s]: Updating user %s", source.authSource.Name, usr.Name)
147147

148148
usr.FullName = fullName
149+
emailChanged := usr.Email != su.Mail
149150
usr.Email = su.Mail
150151
// Change existing admin flag only if AdminFilter option is set
151152
if len(source.AdminFilter) > 0 {
@@ -157,7 +158,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
157158
}
158159
usr.IsActive = true
159160

160-
err = user_model.UpdateUserCols(db.DefaultContext, usr, "full_name", "email", "is_admin", "is_restricted", "is_active")
161+
err = user_model.UpdateUser(usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active")
161162
if err != nil {
162163
log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.authSource.Name, usr.Name, err)
163164
}

services/mailer/mail.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
427427
// actionToTemplate returns the type and name of the action facing the user
428428
// (slightly different from models.ActionType) and the name of the template to use (based on availability)
429429
func actionToTemplate(issue *models.Issue, actionType models.ActionType,
430-
commentType models.CommentType, reviewType models.ReviewType) (typeName, name, template string) {
430+
commentType models.CommentType, reviewType models.ReviewType,
431+
) (typeName, name, template string) {
431432
if issue.IsPull {
432433
typeName = "pull"
433434
} else {

services/release/release.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
186186
// delAttachmentUUIDs accept a slice of attachments' uuids which will be deleted from the release
187187
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
188188
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.Release,
189-
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string) (err error) {
189+
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
190+
) (err error) {
190191
if rel.ID == 0 {
191192
return errors.New("UpdateRelease only accepts an exist release")
192193
}

0 commit comments

Comments
 (0)