Commit ec0199b8 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ce-5987-group-file-templates' into 'master'

CE backport of changes to suppport group file templates

See merge request gitlab-org/gitlab-ce!22310
parents da9e5fcd 34480bb8
...@@ -5,6 +5,7 @@ import initSettingsPanels from '~/settings_panels'; ...@@ -5,6 +5,7 @@ import initSettingsPanels from '~/settings_panels';
import dirtySubmitFactory from '~/dirty_submit/dirty_submit_factory'; import dirtySubmitFactory from '~/dirty_submit/dirty_submit_factory';
import mountBadgeSettings from '~/pages/shared/mount_badge_settings'; import mountBadgeSettings from '~/pages/shared/mount_badge_settings';
import { GROUP_BADGE } from '~/badges/constants'; import { GROUP_BADGE } from '~/badges/constants';
import projectSelect from '~/project_select';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
groupAvatar(); groupAvatar();
...@@ -15,4 +16,6 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -15,4 +16,6 @@ document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.js-general-settings-form, .js-general-permissions-form'), document.querySelectorAll('.js-general-settings-form, .js-general-permissions-form'),
); );
mountBadgeSettings(GROUP_BADGE); mountBadgeSettings(GROUP_BADGE);
projectSelect();
}); });
...@@ -183,23 +183,23 @@ module BlobHelper ...@@ -183,23 +183,23 @@ module BlobHelper
end end
private :template_dropdown_names private :template_dropdown_names
def licenses_for_select(project = @project) def licenses_for_select(project)
@licenses_for_select ||= template_dropdown_names(TemplateFinder.build(:licenses, project).execute) @licenses_for_select ||= template_dropdown_names(TemplateFinder.build(:licenses, project).execute)
end end
def gitignore_names(project = @project) def gitignore_names(project)
@gitignore_names ||= template_dropdown_names(TemplateFinder.build(:gitignores, project).execute) @gitignore_names ||= template_dropdown_names(TemplateFinder.build(:gitignores, project).execute)
end end
def gitlab_ci_ymls(project = @project) def gitlab_ci_ymls(project)
@gitlab_ci_ymls ||= template_dropdown_names(TemplateFinder.build(:gitlab_ci_ymls, project).execute) @gitlab_ci_ymls ||= template_dropdown_names(TemplateFinder.build(:gitlab_ci_ymls, project).execute)
end end
def dockerfile_names(project = @project) def dockerfile_names(project)
@dockerfile_names ||= template_dropdown_names(TemplateFinder.build(:dockerfiles, project).execute) @dockerfile_names ||= template_dropdown_names(TemplateFinder.build(:dockerfiles, project).execute)
end end
def blob_editor_paths(project = @project) def blob_editor_paths(project)
{ {
'relative-url-root' => Rails.application.config.relative_url_root, 'relative-url-root' => Rails.application.config.relative_url_root,
'assets-prefix' => Gitlab::Application.config.assets.prefix, 'assets-prefix' => Gitlab::Application.config.assets.prefix,
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
.settings-content .settings-content
= render 'shared/badges/badge_settings' = 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) } %section.settings.gs-advanced.no-animate#js-advanced-settings{ class: ('expanded' if expanded) }
.settings-header .settings-header
%h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only{ role: 'button' } %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only{ role: 'button' }
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
.template-type-selector.js-template-type-selector-wrap.hidden .template-type-selector.js-template-type-selector-wrap.hidden
= dropdown_tag("Choose type", options: { toggle_class: 'js-template-type-selector qa-template-type-dropdown', title: "Choose a template type" } ) = dropdown_tag("Choose type", options: { toggle_class: 'js-template-type-selector qa-template-type-dropdown', title: "Choose a template type" } )
.license-selector.js-license-selector-wrap.js-template-selector-wrap.hidden .license-selector.js-license-selector-wrap.js-template-selector-wrap.hidden
= dropdown_tag("Apply a license template", options: { toggle_class: 'js-license-selector qa-license-dropdown', title: "Apply a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select, project: @project.name, fullname: @project.namespace.human_name } } ) = dropdown_tag("Apply a license template", options: { toggle_class: 'js-license-selector qa-license-dropdown', title: "Apply a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select(@project), project: @project.name, fullname: @project.namespace.human_name } } )
.gitignore-selector.js-gitignore-selector-wrap.js-template-selector-wrap.hidden .gitignore-selector.js-gitignore-selector-wrap.js-template-selector-wrap.hidden
= dropdown_tag("Apply a .gitignore template", options: { toggle_class: 'js-gitignore-selector qa-gitignore-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } ) = dropdown_tag("Apply a .gitignore template", options: { toggle_class: 'js-gitignore-selector qa-gitignore-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitignore_names(@project) } } )
.gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.js-template-selector-wrap.hidden .gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.js-template-selector-wrap.hidden
= dropdown_tag("Apply a GitLab CI Yaml template", options: { toggle_class: 'js-gitlab-ci-yml-selector qa-gitlab-ci-yml-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } ) = dropdown_tag("Apply a GitLab CI Yaml template", options: { toggle_class: 'js-gitlab-ci-yml-selector qa-gitlab-ci-yml-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls(@project) } } )
.dockerfile-selector.js-dockerfile-selector-wrap.js-template-selector-wrap.hidden .dockerfile-selector.js-dockerfile-selector-wrap.js-template-selector-wrap.hidden
= dropdown_tag("Apply a Dockerfile template", options: { toggle_class: 'js-dockerfile-selector qa-dockerfile-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } ) = dropdown_tag("Apply a Dockerfile template", options: { toggle_class: 'js-dockerfile-selector qa-dockerfile-dropdown', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names(@project) } } )
.template-selectors-undo-menu.hidden .template-selectors-undo-menu.hidden
%span.text-info Template applied %span.text-info Template applied
%button.btn.btn-sm.btn-info Undo %button.btn.btn-sm.btn-info Undo
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
= link_to '#preview', 'data-preview-url' => project_preview_blob_path(@project, @id, legacy_render: params[:legacy_render]) do = link_to '#preview', 'data-preview-url' => project_preview_blob_path(@project, @id, legacy_render: params[:legacy_render]) do
= editing_preview_title(@blob.name) = editing_preview_title(@blob.name)
= form_tag(project_update_blob_path(@project, @id), method: :put, class: 'js-quick-submit js-requires-input js-edit-blob-form', data: blob_editor_paths) do = form_tag(project_update_blob_path(@project, @id), method: :put, class: 'js-quick-submit js-requires-input js-edit-blob-form', data: blob_editor_paths(@project)) do
= render 'projects/blob/editor', ref: @ref, path: @path, blob_data: @blob.data = render 'projects/blob/editor', ref: @ref, path: @path, blob_data: @blob.data
= render 'shared/new_commit_form', placeholder: "Update #{@blob.name}" = render 'shared/new_commit_form', placeholder: "Update #{@blob.name}"
= hidden_field_tag 'last_commit_sha', @last_commit_sha = hidden_field_tag 'last_commit_sha', @last_commit_sha
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
New file New file
= render 'template_selectors' = render 'template_selectors'
.file-editor .file-editor
= form_tag(project_create_blob_path(@project, @id), method: :post, class: 'js-edit-blob-form js-new-blob-form js-quick-submit js-requires-input', data: blob_editor_paths) do = form_tag(project_create_blob_path(@project, @id), method: :post, class: 'js-edit-blob-form js-new-blob-form js-quick-submit js-requires-input', data: blob_editor_paths(@project)) do
= render 'projects/blob/editor', ref: @ref = render 'projects/blob/editor', ref: @ref
= render 'shared/new_commit_form', placeholder: "Add new file" = render 'shared/new_commit_form', placeholder: "Add new file"
......
...@@ -37,6 +37,7 @@ GET /groups ...@@ -37,6 +37,7 @@ GET /groups
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Foobar Group", "full_name": "Foobar Group",
"full_path": "foo-bar", "full_path": "foo-bar",
"file_template_project_id": 1,
"parent_id": null "parent_id": null
} }
] ]
...@@ -62,6 +63,7 @@ GET /groups?statistics=true ...@@ -62,6 +63,7 @@ GET /groups?statistics=true
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Foobar Group", "full_name": "Foobar Group",
"full_path": "foo-bar", "full_path": "foo-bar",
"file_template_project_id": 1,
"parent_id": null, "parent_id": null,
"statistics": { "statistics": {
"storage_size" : 212, "storage_size" : 212,
...@@ -122,6 +124,7 @@ GET /groups/:id/subgroups ...@@ -122,6 +124,7 @@ GET /groups/:id/subgroups
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Foobar Group", "full_name": "Foobar Group",
"full_path": "foo-bar", "full_path": "foo-bar",
"file_template_project_id": 1,
"parent_id": 123 "parent_id": 123
} }
] ]
...@@ -232,6 +235,7 @@ Example response: ...@@ -232,6 +235,7 @@ Example response:
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Twitter", "full_name": "Twitter",
"full_path": "twitter", "full_path": "twitter",
"file_template_project_id": 1,
"parent_id": null, "parent_id": null,
"projects": [ "projects": [
{ {
...@@ -386,6 +390,7 @@ Example response: ...@@ -386,6 +390,7 @@ Example response:
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Twitter", "full_name": "Twitter",
"full_path": "twitter", "full_path": "twitter",
"file_template_project_id": 1,
"parent_id": null "parent_id": null
} }
``` ```
...@@ -442,6 +447,7 @@ PUT /groups/:id ...@@ -442,6 +447,7 @@ PUT /groups/:id
| `visibility` | string | no | The visibility level of the group. Can be `private`, `internal`, or `public`. | | `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 | | `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. | | `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 ```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/5?name=Experimental" curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/5?name=Experimental"
...@@ -462,6 +468,7 @@ Example response: ...@@ -462,6 +468,7 @@ Example response:
"request_access_enabled": false, "request_access_enabled": false,
"full_name": "Foobar Group", "full_name": "Foobar Group",
"full_path": "foo-bar", "full_path": "foo-bar",
"file_template_project_id": 1,
"parent_id": null, "parent_id": null,
"projects": [ "projects": [
{ {
......
# Project templates API # 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) - [Dockerfile templates](templates/dockerfiles.md)
- [Gitignore templates](templates/gitignores.md) - [Gitignore templates](templates/gitignores.md)
- [GitLab CI Config templates](templates/gitlab_ci_ymls.md) - [GitLab CI Config templates](templates/gitlab_ci_ymls.md)
- [Open source license templates](templates/licenses.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 In addition to templates common to the entire instance, project-specific
is not limited to: templates are also available from this API endpoint.
- [Issue and Merge Request templates](../user/project/description_templates.html) Support will be added for [Issue and Merge Request templates](../user/project/description_templates.md)
- [Group level file templates](https://gitlab.com/gitlab-org/gitlab-ee/issues/5987) **(Premium)** 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 ## Get all templates of a particular type
......
...@@ -252,6 +252,13 @@ level of members in group. ...@@ -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). 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 ### Advanced settings
- **Projects**: view all projects within that group, add members to each project, - **Projects**: view all projects within that group, add members to each project,
......
module Gitlab module Gitlab
module Template module Template
class BaseTemplate class BaseTemplate
attr_reader :category attr_accessor :category
def initialize(path, project = nil, category: nil) def initialize(path, project = nil, category: nil)
@path = path @path = path
......
...@@ -10,6 +10,9 @@ describe ApplicationSettings::UpdateService do ...@@ -10,6 +10,9 @@ describe ApplicationSettings::UpdateService do
before do before do
# So the caching behaves like it would in production # So the caching behaves like it would in production
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
# Creating these settings first ensures they're used by other factories
application_settings
end end
describe 'updating terms' do describe 'updating terms' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment