Skip to content

Commit 9ea3376

Browse files
committed
revert unnecessary change
1 parent 359e660 commit 9ea3376

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

models/organization/org.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,16 @@ func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.
508508
return false
509509
}
510510

511-
func orgAllowedCreatedRepoSubQuery(userID int64) *builder.Builder {
512-
return builder.Select("`user`.id").From("`user`").
513-
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
514-
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
515-
Where(builder.Eq{"`team_user`.uid": userID}).
516-
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true}))
517-
}
518-
519511
// GetOrgsCanCreateRepoByUserID returns a list of organizations where given user ID
520512
// are allowed to create repos.
521513
func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organization, error) {
522514
orgs := make([]*Organization, 0, 10)
523515

524-
return orgs, db.GetEngine(ctx).Where(builder.In("id", orgAllowedCreatedRepoSubQuery(userID))).
516+
return orgs, db.GetEngine(ctx).Where(builder.In("id", builder.Select("`user`.id").From("`user`").
517+
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
518+
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
519+
Where(builder.Eq{"`team_user`.uid": userID}).
520+
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
525521
Asc("`user`.name").
526522
Find(&orgs)
527523
}

routers/web/repo/branch.go

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -176,53 +176,6 @@ func redirect(ctx *context.Context) {
176176
ctx.JSONRedirect(ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page")))
177177
}
178178

179-
func handleCreateBranchError(ctx *context.Context, err error, form *forms.NewBranchForm) {
180-
if models.IsErrProtectedTagName(err) {
181-
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
182-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
183-
return
184-
}
185-
186-
if models.IsErrTagAlreadyExists(err) {
187-
e := err.(models.ErrTagAlreadyExists)
188-
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
189-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
190-
return
191-
}
192-
if git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
193-
ctx.Flash.Error(ctx.Tr("repo.branch.branch_already_exists", form.NewBranchName))
194-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
195-
return
196-
}
197-
if git_model.IsErrBranchNameConflict(err) {
198-
e := err.(git_model.ErrBranchNameConflict)
199-
ctx.Flash.Error(ctx.Tr("repo.branch.branch_name_conflict", form.NewBranchName, e.BranchName))
200-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
201-
return
202-
}
203-
if git.IsErrPushRejected(err) {
204-
e := err.(*git.ErrPushRejected)
205-
if len(e.Message) == 0 {
206-
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected_no_message"))
207-
} else {
208-
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
209-
"Message": ctx.Tr("repo.editor.push_rejected"),
210-
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
211-
"Details": utils.SanitizeFlashErrorString(e.Message),
212-
})
213-
if err != nil {
214-
ctx.ServerError("UpdatePullRequest.HTMLString", err)
215-
return
216-
}
217-
ctx.Flash.Error(flashError)
218-
}
219-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
220-
return
221-
}
222-
223-
ctx.ServerError("CreateNewBranch", err)
224-
}
225-
226179
// CreateBranch creates new branch in repository
227180
func CreateBranch(ctx *context.Context) {
228181
form := web.GetForm(ctx).(*forms.NewBranchForm)
@@ -251,7 +204,50 @@ func CreateBranch(ctx *context.Context) {
251204
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.CommitID, form.NewBranchName)
252205
}
253206
if err != nil {
254-
handleCreateBranchError(ctx, err, form)
207+
if models.IsErrProtectedTagName(err) {
208+
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
209+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
210+
return
211+
}
212+
213+
if models.IsErrTagAlreadyExists(err) {
214+
e := err.(models.ErrTagAlreadyExists)
215+
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
216+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
217+
return
218+
}
219+
if git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
220+
ctx.Flash.Error(ctx.Tr("repo.branch.branch_already_exists", form.NewBranchName))
221+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
222+
return
223+
}
224+
if git_model.IsErrBranchNameConflict(err) {
225+
e := err.(git_model.ErrBranchNameConflict)
226+
ctx.Flash.Error(ctx.Tr("repo.branch.branch_name_conflict", form.NewBranchName, e.BranchName))
227+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
228+
return
229+
}
230+
if git.IsErrPushRejected(err) {
231+
e := err.(*git.ErrPushRejected)
232+
if len(e.Message) == 0 {
233+
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected_no_message"))
234+
} else {
235+
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{
236+
"Message": ctx.Tr("repo.editor.push_rejected"),
237+
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
238+
"Details": utils.SanitizeFlashErrorString(e.Message),
239+
})
240+
if err != nil {
241+
ctx.ServerError("UpdatePullRequest.HTMLString", err)
242+
return
243+
}
244+
ctx.Flash.Error(flashError)
245+
}
246+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
247+
return
248+
}
249+
250+
ctx.ServerError("CreateNewBranch", err)
255251
return
256252
}
257253

0 commit comments

Comments
 (0)