Skip to content

Commit

Permalink
Repository level enable package or disable
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed May 8, 2022
1 parent 5ca224a commit b9a8c9c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion models/repo/repo_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName {
case "type":
switch unit.Type(db.Cell2Int64(val)) {
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects:
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages:
r.Config = new(UnitConfig)
case unit.TypeExternalWiki:
r.Config = new(ExternalWikiConfig)
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 @@ -144,6 +144,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

0 comments on commit b9a8c9c

Please sign in to comment.