diff --git a/models/unit/unit.go b/models/unit/unit.go index b83bd6183..c77be7f2b 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -18,16 +18,17 @@ type Type int // Enumerate all the unit types const ( - TypeInvalid Type = iota // 0 invalid - TypeCode // 1 code - TypeIssues // 2 issues - TypePullRequests // 3 PRs - TypeReleases // 4 Releases - TypeWiki // 5 Wiki - TypeExternalWiki // 6 ExternalWiki - TypeExternalTracker // 7 ExternalTracker - TypeProjects // 8 Kanban board - TypePackages // 9 Packages + TypeInvalid Type = iota // 00 invalid + TypeCode // 01 code + TypeIssues // 02 issues + TypePullRequests // 03 PRs + TypeReleases // 04 Releases + TypeWiki // 05 Wiki + TypeExternalWiki // 06 ExternalWiki + TypeExternalTracker // 07 ExternalTracker + TypeProjects // 08 Kanban board + TypePackages // 09 Packages + TypePolls // 10 Polls ) // Value returns integer value for unit type @@ -55,6 +56,8 @@ func (u Type) String() string { return "TypeProjects" case TypePackages: return "TypePackages" + case TypePolls: + return "TypePolls" } return fmt.Sprintf("Unknown Type %d", u) } @@ -78,6 +81,7 @@ var ( TypeExternalTracker, TypeProjects, TypePackages, + TypePolls, } // DefaultRepoUnits contains the default unit types @@ -89,6 +93,7 @@ var ( TypeWiki, TypeProjects, TypePackages, + TypePolls, } // NotAllowedDefaultRepoUnits contains units that can't be default @@ -284,11 +289,20 @@ var ( TypePackages, "repo.packages", "/packages", - "packages.desc", + "packages.desc", // why not repo.packages.desc ? 6, perm.AccessModeRead, } + UnitPolls = Unit{ + TypePolls, + "repo.polls", + "/polls", + "repo.polls.desc", + 7, + perm.AccessModeOwner, + } + // Units contains all the units Units = map[Type]Unit{ TypeCode: UnitCode, @@ -300,6 +314,7 @@ var ( TypeExternalWiki: UnitExternalWiki, TypeProjects: UnitProjects, TypePackages: UnitPackages, + TypePolls: UnitPolls, } ) @@ -349,7 +364,7 @@ func MinUnitAccessMode(unitsMap map[Type]perm.AccessMode) perm.AccessMode { continue } - // get the minial permission great than AccessModeNone except all are AccessModeNone + // get the minimal permission greater than AccessModeNone except all are AccessModeNone if mode > perm.AccessModeNone && (res == perm.AccessModeNone || mode < res) { res = mode } diff --git a/modules/context/repo.go b/modules/context/repo.go index f3d639675..03958c06b 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -556,7 +556,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.Data["CanWriteCode"] = ctx.Repo.CanWrite(unit_model.TypeCode) ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues) ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests) - ctx.Data["CanWritePolls"] = ctx.Repo.IsOwner() // todo: add a 'real' permission + ctx.Data["CanWritePolls"] = ctx.Repo.CanWrite(unit_model.TypePolls) canSignedUserFork, err := repo_module.CanUserForkRepo(ctx.Doer, ctx.Repo.Repository) if err != nil { @@ -1042,6 +1042,7 @@ func UnitTypes() func(ctx *Context) { ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects ctx.Data["UnitTypePackages"] = unit_model.TypePackages + ctx.Data["UnitTypePolls"] = unit_model.TypePolls } } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 44d84be69..6ebd62e56 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1881,6 +1881,7 @@ settings.pulls.allow_rebase_update = Enable updating pull request branch by reba settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default settings.packages_desc = Enable Repository Packages Registry settings.projects_desc = Enable Repository Projects +settings.polls_desc = Enable Repository Polls settings.admin_settings = Administrator Settings settings.admin_enable_health_check = Enable Repository Health Checks (git fsck) settings.admin_code_indexer = Code Indexer diff --git a/options/locale/locale_fr-FR.ini b/options/locale/locale_fr-FR.ini index 9a7e60968..6098b5bc9 100644 --- a/options/locale/locale_fr-FR.ini +++ b/options/locale/locale_fr-FR.ini @@ -1820,7 +1820,9 @@ settings.pulls.allow_manual_merge=Activer le marquage des demandes d'ajout comme settings.pulls.enable_autodetect_manual_merge=Activer la détection automatique de la fusion manuelle (Remarque : dans certains cas particuliers, des erreurs de détection peuvent se produire) settings.pulls.allow_rebase_update=Activer la mise à jour de demande d'ajout par rebase settings.pulls.default_delete_branch_after_merge=Supprimer la branche après la fusion par default -settings.projects_desc=Activer les projets de dépôt +settings.packages_desc=Activer les paquets du dépôt +settings.projects_desc=Activer les projets du dépôt +settings.polls_desc=Activer les scrutins du dépôt settings.admin_settings=Paramètres administrateur settings.admin_enable_health_check=Activer les vérifications de santé du dépôt (git fsck) settings.admin_enable_close_issues_via_commit_in_any_branch=Fermer un ticket via une révision faite sur une branche non par défaut diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 2b5691ce8..b8e644f8d 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -489,6 +489,15 @@ func SettingsPost(ctx *context.Context) { deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages) } + if form.EnablePolls && !unit_model.TypePolls.UnitGlobalDisabled() { + units = append(units, repo_model.RepoUnit{ + RepoID: repo.ID, + Type: unit_model.TypePolls, + }) + } else if !unit_model.TypePolls.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePolls) + } + if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() { units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c1e9cb319..4f0fb3362 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -145,6 +145,7 @@ type RepoSettingForm struct { TrackerIssueStyle string ExternalTrackerRegexpPattern string EnableCloseIssuesViaCommitInAnyBranch bool + EnablePolls bool EnableProjects bool EnablePackages bool EnablePulls bool diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 66b2361ce..384b62551 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -211,8 +211,7 @@ {{end}} - {{/* TODO: make a permission for reading polls and use it here */}} - {{ if (.Permission.CanReadAny $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) }} + {{ if .Permission.CanRead $.UnitTypePolls }} {{svg "octicon-law" 16}} {{.locale.Tr "repo.polls"}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 3c5996e90..b2007c24f 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -394,6 +394,19 @@
+ {{$isPollsEnabled := .Repository.UnitEnabled $.UnitTypePolls}} +
+ + {{if .UnitTypePolls.UnitGlobalDisabled}} +
+ {{else}} +
+ {{end}} + + +
+
+ {{$isProjectsEnabled := .Repository.UnitEnabled $.UnitTypeProjects}}