Commit 352e3222 authored by Jan Beckmann's avatar Jan Beckmann Committed by Sean McGivern

Resolve "404 when trying to create a new issue from the group"

parent 1de68dc3
...@@ -150,14 +150,15 @@ const Api = { ...@@ -150,14 +150,15 @@ const Api = {
}, },
// Return group projects list. Filtered by query // Return group projects list. Filtered by query
groupProjects(groupId, query, callback) { groupProjects(groupId, query, options, callback) {
const url = Api.buildUrl(Api.groupProjectsPath).replace(':id', groupId); const url = Api.buildUrl(Api.groupProjectsPath).replace(':id', groupId);
const defaults = {
search: query,
per_page: 20,
};
return axios return axios
.get(url, { .get(url, {
params: { params: Object.assign({}, defaults, options),
search: query,
per_page: 20,
},
}) })
.then(({ data }) => callback(data)); .then(({ data }) => callback(data));
}, },
......
...@@ -105,7 +105,7 @@ export default class Search { ...@@ -105,7 +105,7 @@ export default class Search {
getProjectsData(term) { getProjectsData(term) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.groupId) { if (this.groupId) {
Api.groupProjects(this.groupId, term, resolve); Api.groupProjects(this.groupId, term, {}, resolve);
} else { } else {
Api.projects(term, { Api.projects(term, {
order_by: 'id', order_by: 'id',
......
...@@ -47,7 +47,10 @@ export default function projectSelect() { ...@@ -47,7 +47,10 @@ export default function projectSelect() {
projectsCallback = finalCallback; projectsCallback = finalCallback;
} }
if (_this.groupId) { if (_this.groupId) {
return Api.groupProjects(_this.groupId, query.term, projectsCallback); return Api.groupProjects(_this.groupId, query.term, {
with_issues_enabled: _this.withIssuesEnabled,
with_merge_requests_enabled: _this.withMergeRequestsEnabled,
}, projectsCallback);
} else { } else {
return Api.projects(query.term, { return Api.projects(query.term, {
order_by: _this.orderBy, order_by: _this.orderBy,
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
= render 'shared/issuable/nav', type: :issues = render 'shared/issuable/nav', type: :issues
.nav-controls .nav-controls
= render 'shared/issuable/feed_buttons' = render 'shared/issuable/feed_buttons'
= render 'shared/new_project_item_select', path: 'issues/new', label: "New issue", type: :issues = render 'shared/new_project_item_select', path: 'issues/new', label: "New issue", type: :issues, with_feature_enabled: 'issues'
= render 'shared/issuable/search_bar', type: :issues = render 'shared/issuable/search_bar', type: :issues
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
= render 'shared/issuable/nav', type: :merge_requests = render 'shared/issuable/nav', type: :merge_requests
- if current_user - if current_user
.nav-controls .nav-controls
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request", type: :merge_requests = render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request", type: :merge_requests, with_feature_enabled: 'merge_requests'
= render 'shared/issuable/search_bar', type: :merge_requests = render 'shared/issuable/search_bar', type: :merge_requests
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- if has_button - if has_button
.text-center .text-center
- if project_select_button - if project_select_button
= render 'shared/new_project_item_select', path: 'issues/new', label: 'New issue', type: :issues = render 'shared/new_project_item_select', path: 'issues/new', label: 'New issue', type: :issues, with_feature_enabled: 'issues'
- else - else
= link_to 'New issue', button_path, class: 'btn btn-success', title: 'New issue', id: 'new_issue_link' = link_to 'New issue', button_path, class: 'btn btn-success', title: 'New issue', id: 'new_issue_link'
- else - else
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
= _("Interested parties can even contribute by pushing commits if they want to.") = _("Interested parties can even contribute by pushing commits if they want to.")
.text-center .text-center
- if project_select_button - if project_select_button
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: _('New merge request'), type: :merge_requests = render 'shared/new_project_item_select', path: 'merge_requests/new', label: _('New merge request'), type: :merge_requests, with_feature_enabled: 'merge_requests'
- else - else
= link_to _('New merge request'), button_path, class: 'btn btn-new', title: _('New merge request'), id: 'new_merge_request_link' = link_to _('New merge request'), button_path, class: 'btn btn-new', title: _('New merge request'), id: 'new_merge_request_link'
- else - else
......
---
title: Only show new issue / new merge request on group page when issues / merge requests
are enabled
merge_request: 19869
author: Jan Beckmann
type: fixed
...@@ -147,6 +147,8 @@ Parameters: ...@@ -147,6 +147,8 @@ Parameters:
| `simple` | boolean | no | Return only the ID, URL, name, and path of each project | | `simple` | boolean | no | Return only the ID, URL, name, and path of each project |
| `owned` | boolean | no | Limit by projects owned by the current user | | `owned` | boolean | no | Limit by projects owned by the current user |
| `starred` | boolean | no | Limit by projects starred by the current user | | `starred` | boolean | no | Limit by projects starred by the current user |
| `with_issues_enabled` | boolean | no | Limit by enabled issues feature |
| `with_merge_requests_enabled` | boolean | no | Limit by enabled merge requests feature |
| `with_custom_attributes` | boolean | no | Include [custom attributes](custom_attributes.md) in response (admins only) | | `with_custom_attributes` | boolean | no | Include [custom attributes](custom_attributes.md) in response (admins only) |
Example response: Example response:
......
...@@ -56,6 +56,8 @@ module API ...@@ -56,6 +56,8 @@ module API
def find_group_projects(params) def find_group_projects(params)
group = find_group!(params[:id]) group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group: group, current_user: current_user, params: project_finder_params).execute projects = GroupProjectsFinder.new(group: group, current_user: current_user, params: project_finder_params).execute
projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
projects = reorder_projects(projects) projects = reorder_projects(projects)
paginate(projects) paginate(projects)
end end
...@@ -191,6 +193,8 @@ module API ...@@ -191,6 +193,8 @@ module API
desc: 'Return only the ID, URL, name, and path of each project' desc: 'Return only the ID, URL, name, and path of each project'
optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user' optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user'
optional :starred, type: Boolean, default: false, desc: 'Limit by starred status' optional :starred, type: Boolean, default: false, desc: 'Limit by starred status'
optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature'
optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature'
use :pagination use :pagination
use :with_custom_attributes use :with_custom_attributes
......
...@@ -59,6 +59,18 @@ feature 'Group empty states' do ...@@ -59,6 +59,18 @@ feature 'Group empty states' do
end end
end end
shared_examples "no projects" do
it 'displays an empty state' do
expect(page).to have_selector('.empty-state')
end
it "does not show a new #{issuable_name} button" do
within '.empty-state' do
expect(page).not_to have_link("create #{issuable_name}")
end
end
end
context 'group without a project' do context 'group without a project' do
context 'group has a subgroup', :nested_groups do context 'group has a subgroup', :nested_groups do
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
...@@ -92,16 +104,18 @@ feature 'Group empty states' do ...@@ -92,16 +104,18 @@ feature 'Group empty states' do
visit path visit path
end end
it 'displays an empty state' do it_behaves_like "no projects"
expect(page).to have_selector('.empty-state') end
end end
it "shows a new #{issuable_name} button" do context 'group has only a project with issues disabled' do
within '.empty-state' do let(:project_with_issues_disabled) { create(:empty_project, :issues_disabled, group: group) }
expect(page).not_to have_link("create #{issuable_name}")
end before do
end visit path
end end
it_behaves_like "no projects"
end end
end end
end end
......
...@@ -5,6 +5,7 @@ feature 'Group issues page' do ...@@ -5,6 +5,7 @@ feature 'Group issues page' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, :public, group: group)} let(:project) { create(:project, :public, group: group)}
let(:project_with_issues_disabled) { create(:project, :issues_disabled, group: group) }
let(:path) { issues_group_path(group) } let(:path) { issues_group_path(group) }
context 'with shared examples' do context 'with shared examples' do
...@@ -76,4 +77,25 @@ feature 'Group issues page' do ...@@ -76,4 +77,25 @@ feature 'Group issues page' do
end end
end end
end end
context 'projects with issues disabled' do
describe 'issue dropdown' do
let(:user_in_group) { create(:group_member, :master, user: create(:user), group: group ).user }
before do
[project, project_with_issues_disabled].each { |project| project.add_master(user_in_group) }
sign_in(user_in_group)
visit issues_group_path(group)
end
it 'shows projects only with issues feature enabled', :js do
find('.new-project-item-link').click
page.within('.select2-results') do
expect(page).to have_content(project.full_name)
expect(page).not_to have_content(project_with_issues_disabled.full_name)
end
end
end
end
end end
...@@ -56,4 +56,21 @@ feature 'Group merge requests page' do ...@@ -56,4 +56,21 @@ feature 'Group merge requests page' do
expect(find('#js-dropdown-assignee .filter-dropdown')).not_to have_content(user2.name) expect(find('#js-dropdown-assignee .filter-dropdown')).not_to have_content(user2.name)
end end
end end
describe 'new merge request dropdown' do
let(:project_with_merge_requests_disabled) { create(:project, :merge_requests_disabled, group: group) }
before do
visit path
end
it 'shows projects only with merge requests feature enabled', :js do
find('.new-project-item-link').click
page.within('.select2-results') do
expect(page).to have_content(project.name_with_namespace)
expect(page).not_to have_content(project_with_merge_requests_disabled.name_with_namespace)
end
end
end
end end
...@@ -242,7 +242,7 @@ describe('Api', () => { ...@@ -242,7 +242,7 @@ describe('Api', () => {
}, },
]); ]);
Api.groupProjects(groupId, query, response => { Api.groupProjects(groupId, query, {}, response => {
expect(response.length).toBe(1); expect(response.length).toBe(1);
expect(response[0].name).toBe('test'); expect(response[0].name).toBe('test');
done(); done();
......
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