Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Feb 24, 2022
2 parents 0362638 + f1b1472 commit 311bf54
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ clean:
.PHONY: fmt
fmt:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt@latest; \
$(GO) install mvdan.cc/gofumpt@v0.3.0; \
fi
@echo "Running gitea-fmt (with gofumpt)..."
@$(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
Expand Down Expand Up @@ -287,7 +287,7 @@ errcheck:
.PHONY: fmt-check
fmt-check:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt@latest; \
$(GO) install mvdan.cc/gofumpt@0.3.0; \
fi
# get all go files and run gitea-fmt (with gofmt) on them
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \
Expand Down
3 changes: 2 additions & 1 deletion models/issue_xref.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ func (issue *Issue) updateCrossReferenceList(list []*crossReference, xref *cross

// verifyReferencedIssue will check if the referenced issue exists, and whether the doer has permission to do what
func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossReferencesContext, repo *repo_model.Repository,
ref references.IssueReference) (*Issue, references.XRefAction, error) {
ref references.IssueReference,
) (*Issue, references.XRefAction, error) {
refIssue := &Issue{RepoID: repo.ID, Index: ref.Index}
refAction := ref.Action
e := db.GetEngine(stdCtx)
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v210.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"

"code.gitea.io/gitea/modules/timeutil"
"github.com/tstranex/u2f"

"github.com/tstranex/u2f"
"xorm.io/xorm"
"xorm.io/xorm/schemas"
)
Expand Down
1 change: 1 addition & 0 deletions models/migrations/v210_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"code.gitea.io/gitea/modules/timeutil"

"github.com/stretchr/testify/assert"
"xorm.io/xorm/schemas"
)
Expand Down
51 changes: 40 additions & 11 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,56 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
}

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

// Leave a seat for owner itself to append later, but if owner is an organization
// and just waste 1 unit is cheaper than re-allocate memory once.
users := make([]*user_model.User, 0, len(accesses)+1)
if len(accesses) > 0 {
userIDs := make([]int64, len(accesses))
for i := 0; i < len(accesses); i++ {
userIDs[i] = accesses[i].UserID
additionalUserIDs := make([]int64, 0, 10)
if err = e.Table("team_user").
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite).
Distinct("`team_user`.uid").
Select("`team_user`.uid").
Find(&additionalUserIDs); err != nil {
return nil, err
}

uidMap := map[int64]bool{}
i := 0
for _, uid := range userIDs {
if uidMap[uid] {
continue
}
uidMap[uid] = true
userIDs[i] = uid
i++
}
userIDs = userIDs[:i]
userIDs = append(userIDs, additionalUserIDs...)

for _, uid := range additionalUserIDs {
if uidMap[uid] {
continue
}
userIDs[i] = uid
i++
}
userIDs = userIDs[:i]

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

Expand Down
30 changes: 25 additions & 5 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,9 @@ func validateUser(u *User) error {
return ValidateEmail(u.Email)
}

func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error {
if err := validateUser(u); err != nil {
func updateUser(ctx context.Context, u *User, changePrimaryEmail bool, cols ...string) error {
err := validateUser(u)
if err != nil {
return err
}

Expand Down Expand Up @@ -860,15 +861,34 @@ func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error {
}); err != nil {
return err
}
} else { // check if primary email in email_address table
primaryEmailExist, err := e.Where("uid=? AND is_primary=?", u.ID, true).Exist(&EmailAddress{})
if err != nil {
return err
}

if !primaryEmailExist {
_, err = e.Insert(&EmailAddress{
Email: u.Email,
UID: u.ID,
IsActivated: true,
IsPrimary: true,
})
return err
}
}

_, err := e.ID(u.ID).AllCols().Update(u)
if len(cols) == 0 {
_, err = e.ID(u.ID).AllCols().Update(u)
} else {
_, err = e.ID(u.ID).Cols(cols...).Update(u)
}
return err
}

// UpdateUser updates user's information.
func UpdateUser(u *User, emailChanged bool) error {
return updateUser(db.DefaultContext, u, emailChanged)
func UpdateUser(u *User, emailChanged bool, cols ...string) error {
return updateUser(db.DefaultContext, u, emailChanged, cols...)
}

// UpdateUserCols update user according special columns
Expand Down
3 changes: 2 additions & 1 deletion modules/indexer/code/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) {
}

func (b *BleveIndexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string,
update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch) error {
update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch,
) error {
// Ignore vendored files in code search
if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) {
return nil
Expand Down
3 changes: 2 additions & 1 deletion modules/notification/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *m

// NotifyCreateIssueComment notifies comment on an issue to notifiers
func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
) {
act := &models.Action{
ActUserID: doer.ID,
ActUser: doer,
Expand Down
3 changes: 2 additions & 1 deletion modules/notification/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func NewNotifier() base.Notifier {
}

func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
) {
if comment.Type == models.CommentTypeComment {
if issue.Comments == nil {
if err := issue.LoadDiscussComments(); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion modules/notification/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func NewNotifier() base.Notifier {
}

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

Expand Down
6 changes: 4 additions & 2 deletions modules/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func NewContext() {

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

// NotifyIssueChangeLabels notifies change labels to notifiers
func NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
addedLabels, removedLabels []*models.Label) {
addedLabels, removedLabels []*models.Label,
) {
for _, notifier := range notifiers {
notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
}
Expand Down
3 changes: 2 additions & 1 deletion modules/notification/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (ns *notificationService) Run() {
}

func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
issue *models.Issue, comment *models.Comment, mentions []*user_model.User) {
issue *models.Issue, comment *models.Comment, mentions []*user_model.User,
) {
opts := issueNotificationOpts{
IssueID: issue.ID,
NotificationAuthorID: doer.ID,
Expand Down
6 changes: 4 additions & 2 deletions modules/notification/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *models.C
}

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

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

func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue,
addedLabels, removedLabels []*models.Label) {
addedLabels, removedLabels []*models.Label,
) {
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))
defer finished()

Expand Down
1 change: 0 additions & 1 deletion modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ type GenerateRepoOption struct {
// CreateBranchRepoOption options when creating a branch in a repository
// swagger:model
type CreateBranchRepoOption struct {

// Name of the branch to create
//
// required: true
Expand Down
2 changes: 2 additions & 0 deletions routers/web/org/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func TeamMembers(ctx *context.Context) {
ctx.ServerError("GetMembers", err)
return
}
ctx.Data["Units"] = unit_model.Units
ctx.HTML(http.StatusOK, tplTeamMembers)
}

Expand All @@ -323,6 +324,7 @@ func TeamRepositories(ctx *context.Context) {
ctx.ServerError("GetRepositories", err)
return
}
ctx.Data["Units"] = unit_model.Units
ctx.HTML(http.StatusOK, tplTeamRepositories)
}

Expand Down
3 changes: 2 additions & 1 deletion routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in

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

commit, err := rawBranch.GetCommit()
Expand Down
3 changes: 2 additions & 1 deletion services/auth/source/ldap/source_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error {
log.Trace("SyncExternalUsers[%s]: Updating user %s", source.authSource.Name, usr.Name)

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

err = user_model.UpdateUserCols(db.DefaultContext, usr, "full_name", "email", "is_admin", "is_restricted", "is_active")
err = user_model.UpdateUser(usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active")
if err != nil {
log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.authSource.Name, usr.Name, err)
}
Expand Down
3 changes: 2 additions & 1 deletion services/mailer/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
// actionToTemplate returns the type and name of the action facing the user
// (slightly different from models.ActionType) and the name of the template to use (based on availability)
func actionToTemplate(issue *models.Issue, actionType models.ActionType,
commentType models.CommentType, reviewType models.ReviewType) (typeName, name, template string) {
commentType models.CommentType, reviewType models.ReviewType,
) (typeName, name, template string) {
if issue.IsPull {
typeName = "pull"
} else {
Expand Down
3 changes: 2 additions & 1 deletion services/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
// delAttachmentUUIDs accept a slice of attachments' uuids which will be deleted from the release
// editAttachments accept a map of attachment uuid to new attachment name which will be updated with attachments.
func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *models.Release,
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string) (err error) {
addAttachmentUUIDs, delAttachmentUUIDs []string, editAttachments map[string]string,
) (err error) {
if rel.ID == 0 {
return errors.New("UpdateRelease only accepts an exist release")
}
Expand Down
Loading

0 comments on commit 311bf54

Please sign in to comment.