Skip to content

Commit a068462

Browse files
authored
Refactor context repository (#33202)
1 parent a7e7504 commit a068462

29 files changed

+125
-164
lines changed

modules/markup/asciicast/asciicast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (Renderer) Render(ctx *markup.RenderContext, _ io.Reader, output io.Writer)
4646
setting.AppSubURL,
4747
url.PathEscape(ctx.RenderOptions.Metas["user"]),
4848
url.PathEscape(ctx.RenderOptions.Metas["repo"]),
49-
ctx.RenderOptions.Metas["BranchNameSubURL"],
49+
ctx.RenderOptions.Metas["RefTypeNameSubURL"],
5050
url.PathEscape(ctx.RenderOptions.RelativePath),
5151
)
5252
return ctx.RenderInternal.FormatWithSafeAttrs(output, `<div class="%s" %s="%s"></div>`, playerClassName, playerSrcAttr, rawURL)

modules/markup/render.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type RenderOptions struct {
4444
MarkupType string
4545

4646
// user&repo, format&style&regexp (for external issue pattern), teams&org (for mention)
47-
// BranchNameSubURL (for iframe&asciicast)
47+
// RefTypeNameSubURL (for iframe&asciicast)
4848
// markupAllowShortIssuePattern
4949
// markdownLineBreakStyle (comment, document)
5050
Metas map[string]string
@@ -170,7 +170,7 @@ sandbox="allow-scripts"
170170
setting.AppSubURL,
171171
url.PathEscape(ctx.RenderOptions.Metas["user"]),
172172
url.PathEscape(ctx.RenderOptions.Metas["repo"]),
173-
ctx.RenderOptions.Metas["BranchNameSubURL"],
173+
ctx.RenderOptions.Metas["RefTypeNameSubURL"],
174174
url.PathEscape(ctx.RenderOptions.RelativePath),
175175
))
176176
return err

routers/web/feed/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType stri
2323
}
2424

2525
title := fmt.Sprintf("Latest commits for branch %s", ctx.Repo.BranchName)
26-
link := &feeds.Link{Href: repo.HTMLURL() + "/" + ctx.Repo.BranchNameSubURL()}
26+
link := &feeds.Link{Href: repo.HTMLURL() + "/" + ctx.Repo.RefTypeNameSubURL()}
2727

2828
feed := &feeds.Feed{
2929
Title: title,

routers/web/feed/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string
3535

3636
title := fmt.Sprintf("Latest commits for file %s", ctx.Repo.TreePath)
3737

38-
link := &feeds.Link{Href: repo.HTMLURL() + "/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)}
38+
link := &feeds.Link{Href: repo.HTMLURL() + "/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)}
3939

4040
feed := &feeds.Feed{
4141
Title: title,

routers/web/repo/blame.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func RefBlame(ctx *context.Context) {
4646
return
4747
}
4848

49-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
49+
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
5050
treeLink := branchLink
51-
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
51+
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL()
5252

5353
if len(ctx.Repo.TreePath) > 0 {
5454
treeLink += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)

routers/web/repo/branch.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func CreateBranch(ctx *context.Context) {
185185

186186
if ctx.HasError() {
187187
ctx.Flash.Error(ctx.GetErrMsg())
188-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
188+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
189189
return
190190
}
191191

@@ -205,25 +205,25 @@ func CreateBranch(ctx *context.Context) {
205205
if err != nil {
206206
if release_service.IsErrProtectedTagName(err) {
207207
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
208-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
208+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
209209
return
210210
}
211211

212212
if release_service.IsErrTagAlreadyExists(err) {
213213
e := err.(release_service.ErrTagAlreadyExists)
214214
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
215-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
215+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
216216
return
217217
}
218218
if git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
219219
ctx.Flash.Error(ctx.Tr("repo.branch.branch_already_exists", form.NewBranchName))
220-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
220+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
221221
return
222222
}
223223
if git_model.IsErrBranchNameConflict(err) {
224224
e := err.(git_model.ErrBranchNameConflict)
225225
ctx.Flash.Error(ctx.Tr("repo.branch.branch_name_conflict", form.NewBranchName, e.BranchName))
226-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
226+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
227227
return
228228
}
229229
if git.IsErrPushRejected(err) {
@@ -242,7 +242,7 @@ func CreateBranch(ctx *context.Context) {
242242
}
243243
ctx.Flash.Error(flashError)
244244
}
245-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
245+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
246246
return
247247
}
248248

routers/web/repo/cherry_pick.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func CherryPick(ctx *context.Context) {
5757
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
5858
ctx.Data["last_commit"] = ctx.Repo.CommitID
5959
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
60-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
60+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
6161

6262
ctx.HTML(200, tplCherryPick)
6363
}
@@ -85,7 +85,7 @@ func CherryPickPost(ctx *context.Context) {
8585
ctx.Data["new_branch_name"] = form.NewBranchName
8686
ctx.Data["last_commit"] = ctx.Repo.CommitID
8787
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
88-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
88+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
8989

9090
if ctx.HasError() {
9191
ctx.HTML(200, tplCherryPick)

routers/web/repo/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func SearchCommits(ctx *context.Context) {
191191

192192
query := ctx.FormTrim("q")
193193
if len(query) == 0 {
194-
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchNameSubURL())
194+
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.RefTypeNameSubURL())
195195
return
196196
}
197197

routers/web/repo/editor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
180180

181181
ctx.Data["TreeNames"] = treeNames
182182
ctx.Data["TreePaths"] = treePaths
183-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
183+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
184184
ctx.Data["commit_summary"] = ""
185185
ctx.Data["commit_message"] = ""
186186
if canCommit {
@@ -428,7 +428,7 @@ func DiffPreviewPost(ctx *context.Context) {
428428
// DeleteFile render delete file page
429429
func DeleteFile(ctx *context.Context) {
430430
ctx.Data["PageIsDelete"] = true
431-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
431+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
432432
treePath := cleanUploadFileName(ctx.Repo.TreePath)
433433

434434
if treePath != ctx.Repo.TreePath {
@@ -462,7 +462,7 @@ func DeleteFilePost(ctx *context.Context) {
462462
}
463463

464464
ctx.Data["PageIsDelete"] = true
465-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
465+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
466466
ctx.Data["TreePath"] = ctx.Repo.TreePath
467467
ctx.Data["commit_summary"] = form.CommitSummary
468468
ctx.Data["commit_message"] = form.CommitMessage
@@ -604,7 +604,7 @@ func UploadFile(ctx *context.Context) {
604604

605605
ctx.Data["TreeNames"] = treeNames
606606
ctx.Data["TreePaths"] = treePaths
607-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
607+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
608608
ctx.Data["commit_summary"] = ""
609609
ctx.Data["commit_message"] = ""
610610
if canCommit {

routers/web/repo/middlewares.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
package repo
55

66
import (
7-
"fmt"
87
"strconv"
98

10-
system_model "code.gitea.io/gitea/models/system"
119
user_model "code.gitea.io/gitea/models/user"
12-
"code.gitea.io/gitea/modules/git"
1310
"code.gitea.io/gitea/modules/optional"
1411
"code.gitea.io/gitea/services/context"
1512
user_service "code.gitea.io/gitea/services/user"
@@ -22,12 +19,9 @@ func SetEditorconfigIfExists(ctx *context.Context) {
2219
}
2320

2421
ec, _, err := ctx.Repo.GetEditorconfig()
25-
26-
if err != nil && !git.IsErrNotExist(err) {
27-
description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
28-
if err := system_model.CreateRepositoryNotice(description); err != nil {
29-
ctx.ServerError("ErrCreatingReporitoryNotice", err)
30-
}
22+
if err != nil {
23+
// it used to check `!git.IsErrNotExist(err)` and create a system notice, but it is quite annoying and useless
24+
// because network errors also happen frequently, so we just ignore it
3125
return
3226
}
3327

routers/web/repo/packages.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ func Packages(ctx *context.Context) {
6262
ctx.Data["PackageType"] = packageType
6363
ctx.Data["AvailableTypes"] = packages.TypeList
6464
ctx.Data["HasPackages"] = hasPackages
65-
if ctx.Repo != nil {
66-
ctx.Data["CanWritePackages"] = ctx.IsUserRepoWriter([]unit.Type{unit.TypePackages}) || ctx.IsUserSiteAdmin()
67-
}
65+
ctx.Data["CanWritePackages"] = ctx.Repo.CanWrite(unit.TypePackages) || ctx.IsUserSiteAdmin()
6866
ctx.Data["PackageDescriptors"] = pds
6967
ctx.Data["Total"] = total
7068
ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository

routers/web/repo/patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewDiffPatch(ctx *context.Context) {
3737
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
3838
ctx.Data["last_commit"] = ctx.Repo.CommitID
3939
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
40-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
40+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
4141

4242
ctx.HTML(200, tplPatchFile)
4343
}
@@ -52,7 +52,7 @@ func NewDiffPatchPost(ctx *context.Context) {
5252
branchName = form.NewBranchName
5353
}
5454
ctx.Data["PageIsPatch"] = true
55-
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
55+
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
5656
ctx.Data["FileContent"] = form.Content
5757
ctx.Data["commit_summary"] = form.CommitSummary
5858
ctx.Data["commit_message"] = form.CommitMessage

routers/web/repo/release.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,19 @@ func NewReleasePost(ctx *context.Context) {
435435
if release_service.IsErrTagAlreadyExists(err) {
436436
e := err.(release_service.ErrTagAlreadyExists)
437437
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
438-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
438+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
439439
return
440440
}
441441

442442
if release_service.IsErrInvalidTagName(err) {
443443
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_invalid"))
444-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
444+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
445445
return
446446
}
447447

448448
if release_service.IsErrProtectedTagName(err) {
449449
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
450-
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
450+
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL())
451451
return
452452
}
453453

routers/web/repo/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func RenderFile(ctx *context.Context) {
5858
}
5959

6060
rctx := renderhelper.NewRenderContextRepoFile(ctx, ctx.Repo.Repository, renderhelper.RepoFileOptions{
61-
CurrentRefPath: ctx.Repo.BranchNameSubURL(),
61+
CurrentRefPath: ctx.Repo.RefTypeNameSubURL(),
6262
CurrentTreePath: path.Dir(ctx.Repo.TreePath),
6363
}).WithRelativePath(ctx.Repo.TreePath).WithInStandalonePage(true)
6464

routers/web/repo/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func LastCommit(ctx *context.Context) {
243243
ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
244244
}
245245
}
246-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
246+
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
247247
ctx.Data["BranchLink"] = branchLink
248248

249249
ctx.HTML(http.StatusOK, tplRepoViewList)
@@ -301,7 +301,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
301301
return nil
302302
}
303303

304-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
304+
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
305305
treeLink := branchLink
306306

307307
if len(ctx.Repo.TreePath) > 0 {

routers/web/repo/view_file.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
4545
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefName)
4646
ctx.Data["FileIsSymlink"] = entry.IsLink()
4747
ctx.Data["FileName"] = blob.Name()
48-
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
48+
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
4949

5050
commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
5151
if err != nil {
@@ -92,7 +92,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
9292
isDisplayingRendered := !isDisplayingSource
9393

9494
if fInfo.isLFSFile {
95-
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/media/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
95+
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/media/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
9696
}
9797

9898
isRepresentableAsText := fInfo.st.IsRepresentableAsText()
@@ -170,9 +170,9 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
170170
ctx.Data["IsMarkup"] = true
171171
ctx.Data["MarkupType"] = markupType
172172
metas := ctx.Repo.Repository.ComposeDocumentMetas(ctx)
173-
metas["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
173+
metas["RefTypeNameSubURL"] = ctx.Repo.RefTypeNameSubURL()
174174
rctx := renderhelper.NewRenderContextRepoFile(ctx, ctx.Repo.Repository, renderhelper.RepoFileOptions{
175-
CurrentRefPath: ctx.Repo.BranchNameSubURL(),
175+
CurrentRefPath: ctx.Repo.RefTypeNameSubURL(),
176176
CurrentTreePath: path.Dir(ctx.Repo.TreePath),
177177
}).
178178
WithMarkupType(markupType).
@@ -262,7 +262,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
262262
ctx.Data["MarkupType"] = markupType
263263

264264
rctx := renderhelper.NewRenderContextRepoFile(ctx, ctx.Repo.Repository, renderhelper.RepoFileOptions{
265-
CurrentRefPath: ctx.Repo.BranchNameSubURL(),
265+
CurrentRefPath: ctx.Repo.RefTypeNameSubURL(),
266266
CurrentTreePath: path.Dir(ctx.Repo.TreePath),
267267
}).
268268
WithMarkupType(markupType).

routers/web/repo/view_home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func Home(ctx *context.Context) {
346346

347347
// prepare the tree path
348348
var treeNames, paths []string
349-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
349+
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
350350
treeLink := branchLink
351351
if ctx.Repo.TreePath != "" {
352352
treeLink += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)

routers/web/repo/view_readme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
189189
ctx.Data["MarkupType"] = markupType
190190

191191
rctx := renderhelper.NewRenderContextRepoFile(ctx, ctx.Repo.Repository, renderhelper.RepoFileOptions{
192-
CurrentRefPath: ctx.Repo.BranchNameSubURL(),
192+
CurrentRefPath: ctx.Repo.RefTypeNameSubURL(),
193193
CurrentTreePath: path.Join(ctx.Repo.TreePath, subfolder),
194194
}).
195195
WithMarkupType(markupType).

services/context/context_model.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,7 @@
33

44
package context
55

6-
import (
7-
"code.gitea.io/gitea/models/unit"
8-
)
9-
106
// IsUserSiteAdmin returns true if current user is a site admin
117
func (ctx *Context) IsUserSiteAdmin() bool {
128
return ctx.IsSigned && ctx.Doer.IsAdmin
139
}
14-
15-
// IsUserRepoAdmin returns true if current user is admin in current repo
16-
func (ctx *Context) IsUserRepoAdmin() bool {
17-
return ctx.Repo.IsAdmin()
18-
}
19-
20-
// IsUserRepoWriter returns true if current user has write privilege in current repo
21-
func (ctx *Context) IsUserRepoWriter(unitTypes []unit.Type) bool {
22-
for _, unitType := range unitTypes {
23-
if ctx.Repo.CanWrite(unitType) {
24-
return true
25-
}
26-
}
27-
28-
return false
29-
}

0 commit comments

Comments
 (0)