Skip to content

Commit 2fd0b7a

Browse files
committed
fix
1 parent 58b204b commit 2fd0b7a

File tree

22 files changed

+369
-363
lines changed

22 files changed

+369
-363
lines changed

models/organization/team.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,27 @@ func (t *Team) LoadMembers(ctx context.Context) (err error) {
174174
return err
175175
}
176176

177-
// UnitEnabled returns if the team has the given unit type enabled
177+
// UnitEnabled returns true if the team has the given unit type enabled
178178
func (t *Team) UnitEnabled(ctx context.Context, tp unit.Type) bool {
179179
return t.UnitAccessMode(ctx, tp) > perm.AccessModeNone
180180
}
181181

182-
// UnitAccessMode returns if the team has the given unit type enabled
182+
// UnitAccessMode returns the access mode for the given unit type, "none" for non-existent units
183183
func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode {
184+
accessMode, _ := t.UnitAccessModeEx(ctx, tp)
185+
return accessMode
186+
}
187+
188+
func (t *Team) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
184189
if err := t.LoadUnits(ctx); err != nil {
185190
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
186191
}
187-
188-
for _, unit := range t.Units {
189-
if unit.Type == tp {
190-
return unit.AccessMode
192+
for _, u := range t.Units {
193+
if u.Type == tp {
194+
return u.AccessMode, true
191195
}
192196
}
193-
return perm.AccessModeNone
197+
return perm.AccessModeNone, false
194198
}
195199

196200
// IsUsableTeamName tests if a name could be as team name

models/perm/access/repo_permission.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,8 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
229229
for _, u := range repo.Units {
230230
var found bool
231231
for _, team := range teams {
232-
teamMode := team.UnitAccessMode(ctx, u.Type)
233-
if teamMode > perm_model.AccessModeNone {
234-
m := perm.UnitsMode[u.Type]
235-
if m < teamMode {
236-
perm.UnitsMode[u.Type] = teamMode
237-
}
232+
if teamMode, exist := team.UnitAccessModeEx(ctx, u.Type); exist {
233+
perm.UnitsMode[u.Type] = max(perm.UnitsMode[u.Type], teamMode)
238234
found = true
239235
}
240236
}

routers/web/web.go

Lines changed: 264 additions & 253 deletions
Large diffs are not rendered by default.

services/context/context.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
102102
tmplCtx["Locale"] = ctx.Base.Locale
103103
tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx)
104104
tmplCtx["RootData"] = ctx.Data
105+
tmplCtx["Consts"] = map[string]any{
106+
"RepoUnitTypeCode": unit.TypeCode,
107+
"RepoUnitTypeIssues": unit.TypeIssues,
108+
"RepoUnitTypePullRequests": unit.TypePullRequests,
109+
"RepoUnitTypeReleases": unit.TypeReleases,
110+
"RepoUnitTypeWiki": unit.TypeWiki,
111+
"RepoUnitTypeExternalWiki": unit.TypeExternalWiki,
112+
"RepoUnitTypeExternalTracker": unit.TypeExternalTracker,
113+
"RepoUnitTypeProjects": unit.TypeProjects,
114+
"RepoUnitTypePackages": unit.TypePackages,
115+
"RepoUnitTypeActions": unit.TypeActions,
116+
}
105117
return tmplCtx
106118
}
107119

services/context/repo.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
383383
ctx.NotFound("no access right", nil)
384384
return
385385
}
386-
ctx.Data["HasAccess"] = true
387386
ctx.Data["Permission"] = &ctx.Repo.Permission
388387

389388
if repo.IsMirror {
@@ -1052,19 +1051,3 @@ func GitHookService() func(ctx *Context) {
10521051
}
10531052
}
10541053
}
1055-
1056-
// UnitTypes returns a middleware to set unit types to context variables.
1057-
func UnitTypes() func(ctx *Context) {
1058-
return func(ctx *Context) {
1059-
ctx.Data["UnitTypeCode"] = unit_model.TypeCode
1060-
ctx.Data["UnitTypeIssues"] = unit_model.TypeIssues
1061-
ctx.Data["UnitTypePullRequests"] = unit_model.TypePullRequests
1062-
ctx.Data["UnitTypeReleases"] = unit_model.TypeReleases
1063-
ctx.Data["UnitTypeWiki"] = unit_model.TypeWiki
1064-
ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
1065-
ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
1066-
ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
1067-
ctx.Data["UnitTypePackages"] = unit_model.TypePackages
1068-
ctx.Data["UnitTypeActions"] = unit_model.TypeActions
1069-
}
1070-
}

templates/explore/navbar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a class="{{if .PageIsExploreOrganizations}}active {{end}}item" href="{{AppSubUrl}}/explore/organizations">
1212
{{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}}
1313
</a>
14-
{{if and (not $.UnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
14+
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
1515
<a class="{{if .PageIsExploreCode}}active {{end}}item" href="{{AppSubUrl}}/explore/code">
1616
{{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}}
1717
</a>

templates/repo/blame.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</table>
8181
{{end}}{{/* end if .IsFileTooLarge */}}
8282
<div class="code-line-menu tippy-target">
83-
{{if $.Permission.CanRead $.UnitTypeIssues}}
83+
{{if $.Permission.CanRead ctx.Consts.RepoUnitTypeIssues}}
8484
<a class="item ref-in-new-issue" role="menuitem" data-url-issue-new="{{.RepoLink}}/issues/new" data-url-param-body-link="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}" rel="nofollow noindex">{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}</a>
8585
{{end}}
8686
<a class="item copy-line-permalink" role="menuitem" data-url="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}">{{ctx.Locale.Tr "repo.file_copy_permalink"}}</a>

templates/repo/code_frequency.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{if .Permission.CanRead $.UnitTypeCode}}
1+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-code-frequency-chart"
33
data-locale-loading-title="{{ctx.Locale.Tr "graphs.component_loading" (ctx.Locale.Tr "graphs.code_frequency.what")}}"
44
data-locale-loading-title-failed="{{ctx.Locale.Tr "graphs.component_loading_failed" (ctx.Locale.Tr "graphs.code_frequency.what")}}"

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<a class="ui primary tiny button" href="{{.SourcePath}}">
2626
{{ctx.Locale.Tr "repo.diff.browse_source"}}
2727
</a>
28-
{{if and ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}{{- /* */ -}}
28+
{{if and ($.Permission.CanWrite ctx.Consts.RepoUnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}{{- /* */ -}}
2929
<div class="ui dropdown primary tiny button">
3030
{{ctx.Locale.Tr "repo.commit.operations"}}
3131
{{svg "octicon-triangle-down" 14 "dropdown icon"}}

templates/repo/contributors.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{if .Permission.CanRead $.UnitTypeCode}}
1+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-contributors-chart"
33
data-locale-filter-label="{{ctx.Locale.Tr "repo.contributors.contribution_type.filter_label"}}"
44
data-locale-contribution-type-commits="{{ctx.Locale.Tr "repo.contributors.contribution_type.commits"}}"

0 commit comments

Comments
 (0)