From 34480bb8501eaf1c5b71284fc9cd2bcdbf04fdea Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 26 Sep 2018 11:58:58 +0100 Subject: [PATCH] Backport CE to changes to support group-level file templates When the feature is available, this setting allows admins to choose a project as a source of custom file templates. This is in addition to any instance-wide templates, whether custom or vendored into the GitLab codebase. --- .../javascripts/pages/groups/edit/index.js | 3 +++ app/views/groups/edit.html.haml | 2 ++ doc/api/groups.md | 7 +++++++ doc/api/project_templates.md | 16 ++++++++++------ doc/user/group/index.md | 7 +++++++ lib/gitlab/template/base_template.rb | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/pages/groups/edit/index.js b/app/assets/javascripts/pages/groups/edit/index.js index d0bce857029..32b55575f95 100644 --- a/app/assets/javascripts/pages/groups/edit/index.js +++ b/app/assets/javascripts/pages/groups/edit/index.js @@ -5,6 +5,7 @@ import initSettingsPanels from '~/settings_panels'; import dirtySubmitFactory from '~/dirty_submit/dirty_submit_factory'; import mountBadgeSettings from '~/pages/shared/mount_badge_settings'; import { GROUP_BADGE } from '~/badges/constants'; +import projectSelect from '~/project_select'; document.addEventListener('DOMContentLoaded', () => { groupAvatar(); @@ -15,4 +16,6 @@ document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('.js-general-settings-form, .js-general-permissions-form'), ); mountBadgeSettings(GROUP_BADGE); + + projectSelect(); }); diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml index f3792c5e397..869c54d89ea 100644 --- a/app/views/groups/edit.html.haml +++ b/app/views/groups/edit.html.haml @@ -37,6 +37,8 @@ .settings-content = render 'shared/badges/badge_settings' += render_if_exists 'groups/templates_setting', expanded: expanded + %section.settings.gs-advanced.no-animate#js-advanced-settings{ class: ('expanded' if expanded) } .settings-header %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only{ role: 'button' } diff --git a/doc/api/groups.md b/doc/api/groups.md index be75c363a40..a9462fc413f 100644 --- a/doc/api/groups.md +++ b/doc/api/groups.md @@ -37,6 +37,7 @@ GET /groups "request_access_enabled": false, "full_name": "Foobar Group", "full_path": "foo-bar", + "file_template_project_id": 1, "parent_id": null } ] @@ -62,6 +63,7 @@ GET /groups?statistics=true "request_access_enabled": false, "full_name": "Foobar Group", "full_path": "foo-bar", + "file_template_project_id": 1, "parent_id": null, "statistics": { "storage_size" : 212, @@ -122,6 +124,7 @@ GET /groups/:id/subgroups "request_access_enabled": false, "full_name": "Foobar Group", "full_path": "foo-bar", + "file_template_project_id": 1, "parent_id": 123 } ] @@ -232,6 +235,7 @@ Example response: "request_access_enabled": false, "full_name": "Twitter", "full_path": "twitter", + "file_template_project_id": 1, "parent_id": null, "projects": [ { @@ -386,6 +390,7 @@ Example response: "request_access_enabled": false, "full_name": "Twitter", "full_path": "twitter", + "file_template_project_id": 1, "parent_id": null } ``` @@ -442,6 +447,7 @@ PUT /groups/:id | `visibility` | string | no | The visibility level of the group. Can be `private`, `internal`, or `public`. | | `lfs_enabled` (optional) | boolean | no | Enable/disable Large File Storage (LFS) for the projects in this group | | `request_access_enabled` | boolean | no | Allow users to request member access. | +| `file_template_project_id` | integer | no | **(Premium)** The ID of a project to load custom file templates from | ```bash curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/5?name=Experimental" @@ -462,6 +468,7 @@ Example response: "request_access_enabled": false, "full_name": "Foobar Group", "full_path": "foo-bar", + "file_template_project_id": 1, "parent_id": null, "projects": [ { diff --git a/doc/api/project_templates.md b/doc/api/project_templates.md index ebdfa975849..ef98205cd68 100644 --- a/doc/api/project_templates.md +++ b/doc/api/project_templates.md @@ -1,19 +1,23 @@ # Project templates API -This API is a project-specific implementation of these endpoints: +This API is a project-specific version of these endpoints: - [Dockerfile templates](templates/dockerfiles.md) - [Gitignore templates](templates/gitignores.md) - [GitLab CI Config templates](templates/gitlab_ci_ymls.md) - [Open source license templates](templates/licenses.md) -It deprecates those endpoints, which will be removed for API version 5. +It deprecates these endpoints, which will be removed for API version 5. -Project-specific templates will be added to this API in time. This includes, but -is not limited to: +In addition to templates common to the entire instance, project-specific +templates are also available from this API endpoint. -- [Issue and Merge Request templates](../user/project/description_templates.html) -- [Group level file templates](https://gitlab.com/gitlab-org/gitlab-ee/issues/5987) **(Premium)** +Support will be added for [Issue and Merge Request templates](../user/project/description_templates.md) +in a future release. + +Support for [Group-level file templates](../user/group/index.md#group-level-file-templates-premium) +**[PREMIUM]** was [added](https://gitlab.com/gitlab-org/gitlab-ee/issues/5987) +in GitLab 11.5 ## Get all templates of a particular type diff --git a/doc/user/group/index.md b/doc/user/group/index.md index 7d01c6f2bf6..d673fa4d21a 100644 --- a/doc/user/group/index.md +++ b/doc/user/group/index.md @@ -252,6 +252,13 @@ level of members in group. Learn more about [Member Lock](https://docs.gitlab.com/ee/user/group/index.html#member-lock). +#### Group-level file templates **[PREMIUM]** + +Group-level file templates allow you to share a set of templates for common file +types with every project in a group. + +Learn more about [Group-level file templates](https://docs.gitlab.com/ee/user/group/index.html#group-level-file-templates-premium). + ### Advanced settings - **Projects**: view all projects within that group, add members to each project, diff --git a/lib/gitlab/template/base_template.rb b/lib/gitlab/template/base_template.rb index 4456217017f..699d747892c 100644 --- a/lib/gitlab/template/base_template.rb +++ b/lib/gitlab/template/base_template.rb @@ -1,7 +1,7 @@ module Gitlab module Template class BaseTemplate - attr_reader :category + attr_accessor :category def initialize(path, project = nil, category: nil) @path = path