Commit 52a3d437 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch '19107-404-when-creating-new-milestone-or-issue-for-project-that-has-issues-disabled' into 'master'

'New issue'/'New merge request' dropdowns should show only projects with issues/merge requests feature enabled

Closes #19107

See merge request !11754
parents 83550c02 a7349560
...@@ -51,6 +51,9 @@ import Api from './api'; ...@@ -51,6 +51,9 @@ import Api from './api';
this.groupId = $(select).data('group-id'); this.groupId = $(select).data('group-id');
this.includeGroups = $(select).data('include-groups'); this.includeGroups = $(select).data('include-groups');
this.orderBy = $(select).data('order-by') || 'id'; this.orderBy = $(select).data('order-by') || 'id';
this.withIssuesEnabled = $(select).data('with-issues-enabled');
this.withMergeRequestsEnabled = $(select).data('with-merge-requests-enabled');
placeholder = "Search for project"; placeholder = "Search for project";
if (this.includeGroups) { if (this.includeGroups) {
placeholder += " or group"; placeholder += " or group";
...@@ -84,7 +87,11 @@ import Api from './api'; ...@@ -84,7 +87,11 @@ import Api from './api';
if (_this.groupId) { if (_this.groupId) {
return Api.groupProjects(_this.groupId, query.term, projectsCallback); return Api.groupProjects(_this.groupId, query.term, projectsCallback);
} else { } else {
return Api.projects(query.term, { order_by: _this.orderBy }, projectsCallback); return Api.projects(query.term, {
order_by: _this.orderBy,
with_issues_enabled: _this.withIssuesEnabled,
with_merge_requests_enabled: _this.withMergeRequestsEnabled
}, projectsCallback);
} }
}; };
})(this), })(this),
......
...@@ -45,6 +45,14 @@ module SelectsHelper ...@@ -45,6 +45,14 @@ module SelectsHelper
end end
end end
with_feature_enabled_data_attribute =
case opts.delete(:with_feature_enabled)
when 'issues' then 'data-with-issues-enabled'
when 'merge_requests' then 'data-with-merge-requests-enabled'
end
opts[with_feature_enabled_data_attribute] = true
hidden_field_tag(id, opts[:selected], opts) hidden_field_tag(id, opts[:selected], opts)
end end
......
...@@ -271,6 +271,7 @@ class Project < ActiveRecord::Base ...@@ -271,6 +271,7 @@ class Project < ActiveRecord::Base
scope :with_builds_enabled, -> { with_feature_enabled(:builds) } scope :with_builds_enabled, -> { with_feature_enabled(:builds) }
scope :with_issues_enabled, -> { with_feature_enabled(:issues) } scope :with_issues_enabled, -> { with_feature_enabled(:issues) }
scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) }
enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 } enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
.nav-controls .nav-controls
= link_to params.merge(rss_url_options), class: 'btn has-tooltip', title: 'Subscribe' do = link_to params.merge(rss_url_options), class: 'btn has-tooltip', title: 'Subscribe' do
= icon('rss') = icon('rss')
= render 'shared/new_project_item_select', path: 'issues/new', label: "New issue" = render 'shared/new_project_item_select', path: 'issues/new', label: "New issue", with_feature_enabled: 'issues'
= render 'shared/issuable/filter', type: :issues = render 'shared/issuable/filter', type: :issues
= render 'shared/issues' = render 'shared/issues'
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.top-area .top-area
= render 'shared/issuable/nav', type: :merge_requests = render 'shared/issuable/nav', type: :merge_requests
.nav-controls .nav-controls
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request" = render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request", with_feature_enabled: 'merge_requests'
= render 'shared/issuable/filter', type: :merge_requests = render 'shared/issuable/filter', type: :merge_requests
= render 'shared/merge_requests' = render 'shared/merge_requests'
- if @projects.any? - if @projects.any?
.project-item-select-holder .project-item-select-holder
= project_select_tag :project_path, class: "project-item-select", data: { include_groups: local_assigns[:include_groups], order_by: 'last_activity_at' } = project_select_tag :project_path, class: "project-item-select", data: { include_groups: local_assigns[:include_groups], order_by: 'last_activity_at' }, with_feature_enabled: local_assigns[:with_feature_enabled]
%a.btn.btn-new.new-project-item-select-button %a.btn.btn-new.new-project-item-select-button
= local_assigns[:label] = local_assigns[:label]
= icon('caret-down') = icon('caret-down')
......
---
title: 'New issue'/'New merge request' dropdowns should show only projects with issues/merge requests feature enabled
merge_request: 19107
author: blackst0ne
...@@ -38,6 +38,8 @@ Parameters: ...@@ -38,6 +38,8 @@ Parameters:
| `membership` | boolean | no | Limit by projects that the current user is a member of | | `membership` | boolean | no | Limit by projects that the current user is a member of |
| `starred` | boolean | no | Limit by projects starred by the current user | | `starred` | boolean | no | Limit by projects starred by the current user |
| `statistics` | boolean | no | Include project statistics | | `statistics` | boolean | no | Include project statistics |
| `with_issues_enabled` | boolean | no | Limit by enabled issues feature |
| `with_merge_requests_enabled` | boolean | no | Limit by enabled merge requests feature |
```json ```json
[ [
......
...@@ -58,6 +58,8 @@ module API ...@@ -58,6 +58,8 @@ module API
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 :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of' optional :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of'
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'
end end
params :create_params do params :create_params do
...@@ -69,11 +71,15 @@ module API ...@@ -69,11 +71,15 @@ module API
options = options.reverse_merge( options = options.reverse_merge(
with: Entities::Project, with: Entities::Project,
current_user: current_user, current_user: current_user,
simple: params[:simple] simple: params[:simple],
with_issues_enabled: params[:with_issues_enabled],
with_merge_requests_enabled: params[:with_merge_requests_enabled]
) )
projects = filter_projects(projects) projects = filter_projects(projects)
projects = projects.with_statistics if options[:statistics] projects = projects.with_statistics if options[:statistics]
projects = projects.with_issues_enabled if options[:with_issues_enabled]
projects = projects.with_merge_requests_enabled if options[:with_merge_requests_enabled]
options[:with] = Entities::BasicProjectDetails if options[:simple] options[:with] = Entities::BasicProjectDetails if options[:simple]
present paginate(projects), options present paginate(projects), options
......
...@@ -2,66 +2,75 @@ require 'spec_helper' ...@@ -2,66 +2,75 @@ require 'spec_helper'
RSpec.describe 'Dashboard Issues', feature: true do RSpec.describe 'Dashboard Issues', feature: true do
let(:current_user) { create :user } let(:current_user) { create :user }
let(:public_project) { create(:empty_project, :public) } let!(:public_project) { create(:empty_project, :public) }
let(:project) do let(:project) { create(:empty_project) }
create(:empty_project) do |project| let(:project_with_issues_disabled) { create(:empty_project, :issues_disabled) }
project.team << [current_user, :master]
end
end
let!(:authored_issue) { create :issue, author: current_user, project: project } let!(:authored_issue) { create :issue, author: current_user, project: project }
let!(:authored_issue_on_public_project) { create :issue, author: current_user, project: public_project } let!(:authored_issue_on_public_project) { create :issue, author: current_user, project: public_project }
let!(:assigned_issue) { create :issue, assignees: [current_user], project: project } let!(:assigned_issue) { create :issue, assignees: [current_user], project: project }
let!(:other_issue) { create :issue, project: project } let!(:other_issue) { create :issue, project: project }
before do before do
[project, project_with_issues_disabled].each { |project| project.team << [current_user, :master] }
login_as(current_user) login_as(current_user)
visit issues_dashboard_path(assignee_id: current_user.id) visit issues_dashboard_path(assignee_id: current_user.id)
end end
it 'shows issues assigned to current user' do describe 'issues' do
expect(page).to have_content(assigned_issue.title) it 'shows issues assigned to current user' do
expect(page).not_to have_content(authored_issue.title) expect(page).to have_content(assigned_issue.title)
expect(page).not_to have_content(other_issue.title) expect(page).not_to have_content(authored_issue.title)
end expect(page).not_to have_content(other_issue.title)
end
it 'shows checkmark when unassigned is selected for assignee', js: true do it 'shows checkmark when unassigned is selected for assignee', js: true do
find('.js-assignee-search').click find('.js-assignee-search').click
find('li', text: 'Unassigned').click find('li', text: 'Unassigned').click
find('.js-assignee-search').click find('.js-assignee-search').click
expect(find('li[data-user-id="0"] a.is-active')).to be_visible expect(find('li[data-user-id="0"] a.is-active')).to be_visible
end end
it 'shows issues when current user is author', js: true do
find('#assignee_id', visible: false).set('')
find('.js-author-search', match: :first).click
it 'shows issues when current user is author', js: true do expect(find('li[data-user-id="null"] a.is-active')).to be_visible
find('#assignee_id', visible: false).set('')
find('.js-author-search', match: :first).click
expect(find('li[data-user-id="null"] a.is-active')).to be_visible find('.dropdown-menu-author li a', match: :first, text: current_user.to_reference).click
find('.js-author-search', match: :first).click
find('.dropdown-menu-author li a', match: :first, text: current_user.to_reference).click page.within '.dropdown-menu-user' do
find('.js-author-search', match: :first).click expect(find('.dropdown-menu-author li a.is-active', match: :first, text: current_user.to_reference)).to be_visible
end
page.within '.dropdown-menu-user' do expect(page).to have_content(authored_issue.title)
expect(find('.dropdown-menu-author li a.is-active', match: :first, text: current_user.to_reference)).to be_visible expect(page).to have_content(authored_issue_on_public_project.title)
expect(page).not_to have_content(assigned_issue.title)
expect(page).not_to have_content(other_issue.title)
end end
expect(page).to have_content(authored_issue.title) it 'shows all issues' do
expect(page).to have_content(authored_issue_on_public_project.title) click_link('Reset filters')
expect(page).not_to have_content(assigned_issue.title)
expect(page).not_to have_content(other_issue.title)
end
it 'shows all issues' do expect(page).to have_content(authored_issue.title)
click_link('Reset filters') expect(page).to have_content(authored_issue_on_public_project.title)
expect(page).to have_content(assigned_issue.title)
expect(page).to have_content(other_issue.title)
end
expect(page).to have_content(authored_issue.title) it_behaves_like "it has an RSS button with current_user's RSS token"
expect(page).to have_content(authored_issue_on_public_project.title) it_behaves_like "an autodiscoverable RSS feed with current_user's RSS token"
expect(page).to have_content(assigned_issue.title)
expect(page).to have_content(other_issue.title)
end end
it_behaves_like "it has an RSS button with current_user's RSS token" describe 'new issue dropdown' do
it_behaves_like "an autodiscoverable RSS feed with current_user's RSS token" it 'shows projects only with issues feature enabled', js: true do
find('.new-project-item-select-button').trigger('click')
page.within('.select2-results') do
expect(page).to have_content(project.name_with_namespace)
expect(page).not_to have_content(project_with_issues_disabled.name_with_namespace)
end
end
end
end end
...@@ -2,16 +2,28 @@ require 'spec_helper' ...@@ -2,16 +2,28 @@ require 'spec_helper'
describe 'Dashboard Merge Requests' do describe 'Dashboard Merge Requests' do
let(:current_user) { create :user } let(:current_user) { create :user }
let(:project) do let(:project) { create(:empty_project) }
create(:empty_project) do |project| let(:project_with_merge_requests_disabled) { create(:empty_project, :merge_requests_disabled) }
project.add_master(current_user)
end
end
before do before do
[project, project_with_merge_requests_disabled].each { |project| project.team << [current_user, :master] }
login_as(current_user) login_as(current_user)
end end
describe 'new merge request dropdown' do
before { visit merge_requests_dashboard_path }
it 'shows projects only with merge requests feature enabled', js: true do
find('.new-project-item-select-button').trigger('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
it 'should show an empty state' do it 'should show an empty state' do
visit merge_requests_dashboard_path(assignee_id: current_user.id) visit merge_requests_dashboard_path(assignee_id: current_user.id)
......
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