Skip to content

Commit d483407

Browse files
authored
Repository level enable package or disable (#19323)
1 parent 6a96968 commit d483407

File tree

14 files changed

+65
-4
lines changed

14 files changed

+65
-4
lines changed

integrations/mssql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
102102

103103
[lfs]
104104
PATH = integrations/gitea-integration-mssql/data/lfs
105+
106+
[packages]
107+
ENABLED = true

integrations/mysql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ DISABLE_GIT_HOOKS = false
118118
INSTALL_LOCK = true
119119
SECRET_KEY = 9pCviYTWSb
120120
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
121+
122+
[packages]
123+
ENABLED = true

integrations/mysql8.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
9999

100100
[lfs]
101101
PATH = integrations/gitea-integration-mysql8/data/lfs
102+
103+
[packages]
104+
ENABLED = true

integrations/pgsql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
103103

104104
[lfs]
105105
PATH = integrations/gitea-integration-pgsql/data/lfs
106+
107+
[packages]
108+
ENABLED = true

integrations/sqlite.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko
101101

102102
[lfs]
103103
PATH = integrations/gitea-integration-sqlite/data/lfs
104+
105+
[packages]
106+
ENABLED = true

models/repo/repo_unit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
181181
r.Config = new(PullRequestsConfig)
182182
case unit.TypeIssues:
183183
r.Config = new(IssuesConfig)
184-
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects:
184+
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages:
185185
fallthrough
186186
default:
187187
r.Config = new(UnitConfig)

models/unit/unit.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
TypeExternalWiki // 6 ExternalWiki
2828
TypeExternalTracker // 7 ExternalTracker
2929
TypeProjects // 8 Kanban board
30+
TypePackages // 9 Packages
3031
)
3132

3233
// Value returns integer value for unit type
@@ -52,6 +53,8 @@ func (u Type) String() string {
5253
return "TypeExternalTracker"
5354
case TypeProjects:
5455
return "TypeProjects"
56+
case TypePackages:
57+
return "TypePackages"
5558
}
5659
return fmt.Sprintf("Unknown Type %d", u)
5760
}
@@ -74,6 +77,7 @@ var (
7477
TypeExternalWiki,
7578
TypeExternalTracker,
7679
TypeProjects,
80+
TypePackages,
7781
}
7882

7983
// DefaultRepoUnits contains the default unit types
@@ -84,6 +88,7 @@ var (
8488
TypeReleases,
8589
TypeWiki,
8690
TypeProjects,
91+
TypePackages,
8792
}
8893

8994
// NotAllowedDefaultRepoUnits contains units that can't be default
@@ -275,6 +280,15 @@ var (
275280
perm.AccessModeOwner,
276281
}
277282

283+
UnitPackages = Unit{
284+
TypePackages,
285+
"repo.packages",
286+
"/packages",
287+
"repo.packages.desc",
288+
6,
289+
perm.AccessModeRead,
290+
}
291+
278292
// Units contains all the units
279293
Units = map[Type]Unit{
280294
TypeCode: UnitCode,
@@ -285,6 +299,7 @@ var (
285299
TypeWiki: UnitWiki,
286300
TypeExternalWiki: UnitExternalWiki,
287301
TypeProjects: UnitProjects,
302+
TypePackages: UnitPackages,
288303
}
289304
)
290305

modules/context/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ func UnitTypes() func(ctx *Context) {
10191019
ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
10201020
ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
10211021
ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
1022+
ctx.Data["UnitTypePackages"] = unit_model.TypePackages
10221023
}
10231024
}
10241025

modules/setting/repository.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ func newRepository() {
295295
log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
296296
}
297297

298+
if !Cfg.Section("packages").Key("ENABLED").MustBool(false) {
299+
Repository.DisabledRepoUnits = append(Repository.DisabledRepoUnits, "repo.packages")
300+
}
301+
298302
// Handle default trustmodel settings
299303
Repository.Signing.DefaultTrustModel = strings.ToLower(strings.TrimSpace(Repository.Signing.DefaultTrustModel))
300304
if Repository.Signing.DefaultTrustModel == "default" {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ tags = Tags
10111011
issues = Issues
10121012
pulls = Pull Requests
10131013
project_board = Projects
1014+
packages = Packages
10141015
labels = Labels
10151016
org_labels_desc = Organization level labels that can be used with <strong>all repositories</strong> under this organization
10161017
org_labels_desc_manage = manage

routers/web/repo/setting.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ func SettingsPost(ctx *context.Context) {
456456
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects)
457457
}
458458

459+
if form.EnablePackages && !unit_model.TypeProjects.UnitGlobalDisabled() {
460+
units = append(units, repo_model.RepoUnit{
461+
RepoID: repo.ID,
462+
Type: unit_model.TypePackages,
463+
})
464+
} else if !unit_model.TypePackages.UnitGlobalDisabled() {
465+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
466+
}
467+
459468
if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() {
460469
units = append(units, repo_model.RepoUnit{
461470
RepoID: repo.ID,

services/forms/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ type RepoSettingForm struct {
143143
TrackerIssueStyle string
144144
EnableCloseIssuesViaCommitInAnyBranch bool
145145
EnableProjects bool
146+
EnablePackages bool
146147
EnablePulls bool
147148
PullsIgnoreWhitespace bool
148149
PullsAllowMerge bool

templates/repo/header.tmpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@
178178
</a>
179179
{{end}}
180180

181-
<a href="{{.RepoLink}}/packages" class="{{ if .IsPackagesPage }}active{{end}} item">
182-
{{svg "octicon-package"}} {{.i18n.Tr "packages.title"}}
183-
</a>
181+
{{if .Permission.CanRead $.UnitTypePackages}}
182+
<a href="{{.RepoLink}}/packages" class="{{ if .IsPackagesPage }}active{{end}} item">
183+
{{svg "octicon-package"}} {{.i18n.Tr "packages.title"}}
184+
</a>
185+
{{end}}
184186

185187
{{ if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead $.UnitTypeProjects)}}
186188
<a href="{{.RepoLink}}/projects" class="{{ if .IsProjectsPage }}active{{end}} item">

templates/repo/settings/options.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@
390390
</div>
391391
</div>
392392

393+
{{$isPackagesEnabled := .Repository.UnitEnabled $.UnitTypePackages}}
394+
<div class="inline field">
395+
<label>{{.i18n.Tr "repo.packages"}}</label>
396+
{{if .UnitTypePackages.UnitGlobalDisabled}}
397+
<div class="ui checkbox tooltip disabled" data-content="{{.i18n.Tr "repo.unit_disabled"}}">
398+
{{else}}
399+
<div class="ui checkbox">
400+
{{end}}
401+
<input class="enable-system" name="enable_packages" type="checkbox" {{if $isPackagesEnabled}}checked{{end}}>
402+
<label>{{.i18n.Tr "repo.settings.packages_desc"}}</label>
403+
</div>
404+
</div>
405+
393406
{{if not .IsMirror}}
394407
<div class="ui divider"></div>
395408
{{$pullRequestEnabled := .Repository.UnitEnabled $.UnitTypePullRequests}}

0 commit comments

Comments
 (0)