Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository level enable package or disable #19323

Merged
merged 3 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions integrations/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h

[lfs]
PATH = integrations/gitea-integration-mssql/data/lfs

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ DISABLE_GIT_HOOKS = false
INSTALL_LOCK = true
SECRET_KEY = 9pCviYTWSb
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions integrations/mysql8.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h

[lfs]
PATH = integrations/gitea-integration-mysql8/data/lfs

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h

[lfs]
PATH = integrations/gitea-integration-pgsql/data/lfs

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions integrations/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko

[lfs]
PATH = integrations/gitea-integration-sqlite/data/lfs

[packages]
ENABLED = true
2 changes: 1 addition & 1 deletion models/repo/repo_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(PullRequestsConfig)
case unit.TypeIssues:
r.Config = new(IssuesConfig)
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects:
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages:
fallthrough
default:
r.Config = new(UnitConfig)
Expand Down
15 changes: 15 additions & 0 deletions models/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
TypeExternalWiki // 6 ExternalWiki
TypeExternalTracker // 7 ExternalTracker
TypeProjects // 8 Kanban board
TypePackages // 9 Packages
)

// Value returns integer value for unit type
Expand All @@ -52,6 +53,8 @@ func (u Type) String() string {
return "TypeExternalTracker"
case TypeProjects:
return "TypeProjects"
case TypePackages:
return "TypePackages"
}
return fmt.Sprintf("Unknown Type %d", u)
}
Expand All @@ -74,6 +77,7 @@ var (
TypeExternalWiki,
TypeExternalTracker,
TypeProjects,
TypePackages,
}

// DefaultRepoUnits contains the default unit types
Expand All @@ -84,6 +88,7 @@ var (
TypeReleases,
TypeWiki,
TypeProjects,
TypePackages,
}

// NotAllowedDefaultRepoUnits contains units that can't be default
Expand Down Expand Up @@ -275,6 +280,15 @@ var (
perm.AccessModeOwner,
}

UnitPackages = Unit{
TypePackages,
"repo.packages",
"/packages",
"repo.packages.desc",
6,
perm.AccessModeRead,
}

// Units contains all the units
Units = map[Type]Unit{
TypeCode: UnitCode,
Expand All @@ -285,6 +299,7 @@ var (
TypeWiki: UnitWiki,
TypeExternalWiki: UnitExternalWiki,
TypeProjects: UnitProjects,
TypePackages: UnitPackages,
}
)

Expand Down
1 change: 1 addition & 0 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ func UnitTypes() func(ctx *Context) {
ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
ctx.Data["UnitTypePackages"] = unit_model.TypePackages
}
}

Expand Down
4 changes: 4 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ func newRepository() {
log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
}

if !Cfg.Section("packages").Key("ENABLED").MustBool(false) {
Repository.DisabledRepoUnits = append(Repository.DisabledRepoUnits, "repo.packages")
}

// Handle default trustmodel settings
Repository.Signing.DefaultTrustModel = strings.ToLower(strings.TrimSpace(Repository.Signing.DefaultTrustModel))
if Repository.Signing.DefaultTrustModel == "default" {
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ tags = Tags
issues = Issues
pulls = Pull Requests
project_board = Projects
packages = Packages
labels = Labels
org_labels_desc = Organization level labels that can be used with <strong>all repositories</strong> under this organization
org_labels_desc_manage = manage
Expand Down
9 changes: 9 additions & 0 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ func SettingsPost(ctx *context.Context) {
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects)
}

if form.EnablePackages && !unit_model.TypeProjects.UnitGlobalDisabled() {
units = append(units, repo_model.RepoUnit{
RepoID: repo.ID,
Type: unit_model.TypePackages,
})
} else if !unit_model.TypePackages.UnitGlobalDisabled() {
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
}

if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() {
units = append(units, repo_model.RepoUnit{
RepoID: repo.ID,
Expand Down
1 change: 1 addition & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type RepoSettingForm struct {
TrackerIssueStyle string
EnableCloseIssuesViaCommitInAnyBranch bool
EnableProjects bool
EnablePackages bool
EnablePulls bool
PullsIgnoreWhitespace bool
PullsAllowMerge bool
Expand Down
8 changes: 5 additions & 3 deletions templates/repo/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@
</a>
{{end}}

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

{{ if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead $.UnitTypeProjects)}}
<a href="{{.RepoLink}}/projects" class="{{ if .IsProjectsPage }}active{{end}} item">
Expand Down
13 changes: 13 additions & 0 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@
</div>
</div>

{{$isPackagesEnabled := .Repository.UnitEnabled $.UnitTypePackages}}
<div class="inline field">
<label>{{.i18n.Tr "repo.packages"}}</label>
{{if .UnitTypePackages.UnitGlobalDisabled}}
<div class="ui checkbox tooltip disabled" data-content="{{.i18n.Tr "repo.unit_disabled"}}">
{{else}}
<div class="ui checkbox">
{{end}}
<input class="enable-system" name="enable_packages" type="checkbox" {{if $isPackagesEnabled}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.packages_desc"}}</label>
</div>
</div>

{{if not .IsMirror}}
<div class="ui divider"></div>
{{$pullRequestEnabled := .Repository.UnitEnabled $.UnitTypePullRequests}}
Expand Down