diff --git a/CHANGELOG.md b/CHANGELOG.md index 6db401fa..36f1e686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch ### New +- Limit shown statuses to the one available in the project (#121, #127, #130) - Store dashboard settings in user preferences (#39) ### Changes diff --git a/app/models/rdb_dashboard.rb b/app/models/rdb_dashboard.rb index f48a216a..c7bfd593 100644 --- a/app/models/rdb_dashboard.rb +++ b/app/models/rdb_dashboard.rb @@ -63,6 +63,17 @@ def issues .includes(:assigned_to, :time_entries, :tracker, :status, :priority, :fixed_version) end + def statuses + ids = WorkflowTransition + .where(tracker: trackers) + .distinct + .pluck(:old_status_id, :new_status_id) + .flatten + .uniq + + IssueStatus.where(id: ids).sorted + end + def versions @versions ||= Version.where(project_id: project_ids).distinct end diff --git a/app/models/rdb_taskboard.rb b/app/models/rdb_taskboard.rb index 2fc81f3c..d7405b5e 100644 --- a/app/models/rdb_taskboard.rb +++ b/app/models/rdb_taskboard.rb @@ -34,7 +34,7 @@ def build # Init columns options[:hide_columns] ||= [] - done_statuses = IssueStatus.sorted.select do |status| + done_statuses = statuses.select do |status| next true if status.is_closed? add_column RdbColumn.new( diff --git a/spec/models/rdb_dashboard/statuses_spec.rb b/spec/models/rdb_dashboard/statuses_spec.rb new file mode 100644 index 00000000..bc9d6717 --- /dev/null +++ b/spec/models/rdb_dashboard/statuses_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require File.expand_path('../../spec_helper', __dir__) + +describe RdbDashboard do + fixtures %i[ + enabled_modules + issue_statuses + projects + projects_trackers + trackers + workflows + ] + + subject(:dashboard) { RdbDashboard.new(project, options, params) } + + let(:project) { Project.find(1) } + let(:options) { {} } + let(:params) { {} } + + describe '#statuses' do + subject(:statuses) { dashboard.statuses } + + before do + # Delete all workflow rules related to status 6 (Rejected). We will test, + # that this now unused issue status does not appear on the board. + WorkflowTransition.where('new_status_id = :id OR old_status_id = :id', id: 6).delete_all + end + + it 'returns the project' do + expect(statuses.map(&:id)).to eq [1, 2, 3, 4, 5] + end + end +end