Skip to content

Commit 861b3b2

Browse files
committed
fix bug
1 parent 3620109 commit 861b3b2

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

models/repo_permission.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func (p *Permission) UnitAccessMode(unitType UnitType) AccessMode {
4242
return p.UnitsMode[unitType]
4343
}
4444

45-
// CanAccess returns true if user has read access to the unit of the repository
45+
// CanAccess returns true if user has mode access to the unit of the repository
4646
func (p *Permission) CanAccess(mode AccessMode, unitType UnitType) bool {
4747
return p.UnitAccessMode(unitType) >= mode
4848
}
4949

50-
// CanAccessAny returns true if user has read access to any of the units of the repository
50+
// CanAccessAny returns true if user has mode access to any of the units of the repository
5151
func (p *Permission) CanAccessAny(mode AccessMode, unitTypes ...UnitType) bool {
5252
for _, u := range unitTypes {
5353
if p.CanAccess(mode, u) {
@@ -62,6 +62,20 @@ func (p *Permission) CanRead(unitType UnitType) bool {
6262
return p.CanAccess(AccessModeRead, unitType)
6363
}
6464

65+
// CanReadAny returns true if user has read access to any of the units of the repository
66+
func (p *Permission) CanReadAny(unitTypes ...UnitType) bool {
67+
return p.CanAccessAny(AccessModeRead, unitTypes...)
68+
}
69+
70+
// CanReadIssuesOrPulls returns true if isPull is true and user could read pull requests and
71+
// returns true if isPull is false and user could read to issues
72+
func (p *Permission) CanReadIssuesOrPulls(isPull bool) bool {
73+
if isPull {
74+
return p.CanRead(UnitTypePullRequests)
75+
}
76+
return p.CanRead(UnitTypeIssues)
77+
}
78+
6579
// CanWrite returns true if user could write to this unit
6680
func (p *Permission) CanWrite(unitType UnitType) bool {
6781
return p.CanAccess(AccessModeWrite, unitType)
@@ -76,15 +90,6 @@ func (p *Permission) CanWriteIssuesOrPulls(isPull bool) bool {
7690
return p.CanWrite(UnitTypeIssues)
7791
}
7892

79-
// CanReadIssuesOrPulls returns true if isPull is true and user could read pull requests and
80-
// returns true if isPull is false and user could read to issues
81-
func (p *Permission) CanReadIssuesOrPulls(isPull bool) bool {
82-
if isPull {
83-
return p.CanRead(UnitTypePullRequests)
84-
}
85-
return p.CanRead(UnitTypeIssues)
86-
}
87-
8893
// GetUserRepoPermission returns the user permissions to the repository
8994
func GetUserRepoPermission(repo *Repository, user *User) (Permission, error) {
9095
return getUserRepoPermission(x, repo, user)

templates/repo/activity.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
</h2>
2424
<div class="ui divider"></div>
2525

26-
{{if (or (.Permission.CanAccess $.UnitTypeIssues) (.Permission.CanAccess $.UnitTypePullRequests))}}
26+
{{if (or (.Permission.CanRead $.UnitTypeIssues) (.Permission.CanRead $.UnitTypePullRequests))}}
2727
<h4 class="ui top attached header">{{.i18n.Tr "repo.activity.overview"}}</h4>
2828
<div class="ui attached segment two column grid">
29-
{{if .Permission.CanAccess $.UnitTypePullRequests}}
29+
{{if .Permission.CanRead $.UnitTypePullRequests}}
3030
<div class="column">
3131
{{if gt .Activity.ActivePRCount 0}}
3232
<div class="stats-table">
@@ -41,7 +41,7 @@
4141
{{.i18n.Tr (TrN .i18n.Lang .Activity.ActivePRCount "repo.activity.active_prs_count_1" "repo.activity.active_prs_count_n") .Activity.ActivePRCount | Safe }}
4242
</div>
4343
{{end}}
44-
{{if .Permission.CanAccess $.UnitTypeIssues}}
44+
{{if .Permission.CanRead $.UnitTypeIssues}}
4545
<div class="column">
4646
{{if gt .Activity.ActiveIssueCount 0}}
4747
<div class="stats-table">
@@ -58,7 +58,7 @@
5858
{{end}}
5959
</div>
6060
<div class="ui attached segment horizontal segments">
61-
{{if .Permission.CanAccess $.UnitTypePullRequests}}
61+
{{if .Permission.CanRead $.UnitTypePullRequests}}
6262
<a href="#merged-pull-requests" class="ui attached segment text center">
6363
<i class="text purple octicon octicon-git-pull-request"></i> <strong>{{.Activity.MergedPRCount}}</strong><br>
6464
{{.i18n.Tr (TrN .i18n.Lang .Activity.MergedPRCount "repo.activity.merged_prs_count_1" "repo.activity.merged_prs_count_n") }}
@@ -68,7 +68,7 @@
6868
{{.i18n.Tr (TrN .i18n.Lang .Activity.OpenedPRCount "repo.activity.opened_prs_count_1" "repo.activity.opened_prs_count_n") }}
6969
</a>
7070
{{end}}
71-
{{if .Permission.CanAccess $.UnitTypeIssues}}
71+
{{if .Permission.CanRead $.UnitTypeIssues}}
7272
<a href="#closed-issues" class="ui attached segment text center">
7373
<i class="text red octicon octicon-issue-closed"></i> <strong>{{.Activity.ClosedIssueCount}}</strong><br>
7474
{{.i18n.Tr (TrN .i18n.Lang .Activity.ClosedIssueCount "repo.activity.closed_issues_count_1" "repo.activity.closed_issues_count_n") }}

templates/repo/header.tmpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{.NumStars}}
3131
</a>
3232
</div>
33-
{{if and (not .IsBare) ($.Permission.CanAccess $.UnitTypeCode)}}
33+
{{if and (not .IsBare) ($.Permission.CanRead $.UnitTypeCode)}}
3434
<div class="ui compact labeled button" tabindex="0">
3535
<a class="ui compact button {{if not $.CanSignedUserFork}}poping up{{end}}" {{if $.CanSignedUserFork}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else if $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" data-position="top center" data-variation="tiny"{{end}}>
3636
<i class="octicon octicon-repo-forked"></i>{{$.i18n.Tr "repo.fork"}}
@@ -47,43 +47,43 @@
4747
{{if not .IsDiffCompare}}
4848
<div class="ui tabs container">
4949
<div class="ui tabular stackable menu navbar">
50-
{{if .Permission.CanAccess $.UnitTypeCode}}
50+
{{if .Permission.CanRead $.UnitTypeCode}}
5151
<a class="{{if .PageIsViewCode}}active{{end}} item" href="{{.RepoLink}}{{if (ne .BranchName .Repository.DefaultBranch)}}/src/{{.BranchNameSubURL | EscapePound}}{{end}}">
5252
<i class="octicon octicon-code"></i> {{.i18n.Tr "repo.code"}}
5353
</a>
5454
{{end}}
5555

56-
{{if .Permission.CanAccess $.UnitTypeIssues}}
56+
{{if .Permission.CanRead $.UnitTypeIssues}}
5757
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
5858
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} <span class="ui {{if not .Repository.NumOpenIssues}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenIssues}}</span>
5959
</a>
6060
{{end}}
6161

62-
{{if .Permission.CanAccess $.UnitTypeExternalTracker}}
62+
{{if .Permission.CanRead $.UnitTypeExternalTracker}}
6363
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues" target="_blank" rel="noopener noreferrer">
6464
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
6565
</a>
6666
{{end}}
6767

68-
{{if and .Repository.CanEnablePulls (.Permission.CanAccess $.UnitTypePullRequests)}}
68+
{{if and .Repository.CanEnablePulls (.Permission.CanRead $.UnitTypePullRequests)}}
6969
<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls">
7070
<i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span>
7171
</a>
7272
{{end}}
7373

74-
{{if and (.Permission.CanAccess $.UnitTypeReleases) (not .IsBareRepo) }}
74+
{{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsBareRepo) }}
7575
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
7676
<i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumReleases}}gray{{else}}blue{{end}} small label">{{.Repository.NumReleases}}</span>
7777
</a>
7878
{{end}}
7979

80-
{{if or (.Permission.CanAccess $.UnitTypeUncyclo) (.Permission.CanAccess $.UnitTypeExternalUncyclo)}}
81-
<a class="{{if .PageIsUncyclo}}active{{end}} item" href="{{.RepoLink}}/wiki" {{if (.Permission.CanAccess $.UnitTypeExternalUncyclo)}} target="_blank" rel="noopener noreferrer" {{end}}>
80+
{{if or (.Permission.CanRead $.UnitTypeUncyclo) (.Permission.CanRead $.UnitTypeExternalUncyclo)}}
81+
<a class="{{if .PageIsUncyclo}}active{{end}} item" href="{{.RepoLink}}/wiki" {{if (.Permission.CanRead $.UnitTypeExternalUncyclo)}} target="_blank" rel="noopener noreferrer" {{end}}>
8282
<i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}
8383
</a>
8484
{{end}}
8585

86-
{{if and (.Permission.CanAccessAny $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) (not .IsBareRepo)}}
86+
{{if and (.Permission.CanReadAny $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) (not .IsBareRepo)}}
8787
<a class="{{if .PageIsActivity}}active{{end}} item" href="{{.RepoLink}}/activity">
8888
<i class="octicon octicon-pulse"></i> {{.i18n.Tr "repo.activity"}}
8989
</a>

templates/repo/release/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<a href="{{$.RepoLink}}/src/tag/{{.TagName | EscapePound}}" rel="nofollow"><i class="tag icon"></i> {{.TagName}}</a>
4242
</h4>
4343
<div class="download">
44-
{{if $.Permission.CanAccess $.UnitTypeCode}}
44+
{{if $.Permission.CanRead $.UnitTypeCode}}
4545
<a href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow"><i class="code icon"></i> {{ShortSha .Sha1}}</a>
4646
<a href="{{$.RepoLink}}/archive/{{.TagName | EscapePound}}.zip" rel="nofollow"><i class="octicon octicon-file-zip"></i> ZIP</a>
4747
<a href="{{$.RepoLink}}/archive/{{.TagName | EscapePound}}.tar.gz"><i class="octicon octicon-file-zip"></i> TAR.GZ</a>
@@ -66,7 +66,7 @@
6666
<div class="download">
6767
<h2>{{$.i18n.Tr "repo.release.downloads"}}</h2>
6868
<ul class="list">
69-
{{if $.Permission.CanAccess $.UnitTypeCode}}
69+
{{if $.Permission.CanRead $.UnitTypeCode}}
7070
<li>
7171
<a href="{{$.RepoLink}}/archive/{{.TagName | EscapePound}}.zip" rel="nofollow"><strong><i class="octicon octicon-file-zip"></i> {{$.i18n.Tr "repo.release.source_code"}} (ZIP)</strong></a>
7272
</li>

templates/repo/settings/options.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
</div>
295295
</div>
296296

297-
{{if .Permission.CanAccess $.UnitTypeUncyclo}}
297+
{{if .Permission.CanRead $.UnitTypeUncyclo}}
298298
<div class="ui divider"></div>
299299

300300
<div class="item">

templates/repo/sub_menu.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div class="ui segment sub-menu">
22
<div class="ui two horizontal center link list">
3-
{{if and (.Permission.CanAccess $.UnitTypeCode) (not .IsBareRepo)}}
3+
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsBareRepo)}}
44
<div class="item{{if .PageIsCommits}} active{{end}}">
55
<a href="{{.RepoLink}}/commits{{if .IsViewBranch}}/branch{{else if .IsViewTag}}/tag{{else if .IsViewCommit}}/commit{{end}}/{{EscapePound .BranchName}}"><i class="octicon octicon-history"></i> <b>{{.CommitsCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .CommitsCount "repo.commit" "repo.commits") }}</a>
66
</div>
77
{{end}}
8-
{{if and (.Permission.CanAccess $.UnitTypeCode) (not .IsBareRepo) }}
8+
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsBareRepo) }}
99
<div class="item{{if .PageIsBranches}} active{{end}}">
1010
<a href="{{.RepoLink}}/branches/"><i class="octicon octicon-git-branch"></i> <b>{{.BranchesCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .BranchesCount "repo.branch" "repo.branches") }}</a>
1111
</div>

0 commit comments

Comments
 (0)