Skip to content

Commit eaebf8c

Browse files
committed
move Backlog scope into WorkPackage scope
1 parent 44ab6af commit eaebf8c

7 files changed

Lines changed: 98 additions & 127 deletions

File tree

modules/backlogs/app/controllers/backlogs/backlog_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def load_backlogs
7979
.order_by_position
8080
.group_by(&:sprint_id)
8181
@active_sprint_ids = @sprints.select(&:active?).map(&:id)
82-
@inbox_work_packages = Backlog.inbox_for(project: @project)
82+
@inbox_work_packages = WorkPackage.backlogs_inbox_for(project: @project)
8383
end
8484
end
8585
end

modules/backlogs/app/controllers/backlogs/inbox_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def menu
4040
backlog_items_scope = if OpenProject::FeatureDecisions.backlog_buckets_active? && @work_package.backlog_bucket_id
4141
@work_package.backlog_bucket.work_packages
4242
else
43-
Backlog.inbox_for(project: @project)
43+
WorkPackage.backlogs_inbox_for(project: @project)
4444
end
4545

4646
max_position = backlog_items_scope.maximum(:position) || 0
@@ -99,7 +99,7 @@ def load_work_package
9999
end
100100

101101
def replace_inbox_component_via_turbo_stream
102-
inbox_work_packages = Backlog.inbox_for(project: @project)
102+
inbox_work_packages = WorkPackage.backlogs_inbox_for(project: @project)
103103
backlog_buckets = if OpenProject::FeatureDecisions.backlog_buckets_active?
104104
Agile::BacklogBucket.for_project(@project)
105105
end

modules/backlogs/app/controllers/backlogs/work_packages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def moved_to_inbox
125125
render_success_flash_message_via_turbo_stream(
126126
message: I18n.t(:notice_successful_move, from: @sprint.name, to: I18n.t(:label_inbox))
127127
)
128-
inbox_work_packages = Backlog.inbox_for(project: @project)
128+
inbox_work_packages = WorkPackage.backlogs_inbox_for(project: @project)
129129
backlog_buckets = if OpenProject::FeatureDecisions.backlog_buckets_active?
130130
Agile::BacklogBucket.for_project(@project)
131131
end

modules/backlogs/app/models/backlog.rb renamed to modules/backlogs/app/models/work_packages/scopes/backlogs_inbox_for.rb

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#-- copyright
1+
# frozen_string_literal: true
2+
3+
# -- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
46
#
@@ -24,37 +26,26 @@
2426
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2527
#
2628
# See COPYRIGHT and LICENSE files for more details.
27-
#++
28-
29-
class Backlog
30-
extend ActiveModel::Naming
31-
32-
attr_accessor :sprint, :stories
33-
34-
delegate :id, to: :sprint, prefix: true
29+
# ++
3530

36-
def self.inbox_for(project:)
37-
inbox_condition = if OpenProject::FeatureDecisions.backlog_buckets_active?
38-
{ sprint_id: nil, backlog_bucket_id: nil }
39-
else
40-
{ sprint_id: nil }
41-
end
31+
module WorkPackages::Scopes::BacklogsInboxFor
32+
extend ActiveSupport::Concern
4233

43-
WorkPackage
44-
.visible
45-
.with_status_open
46-
.where(project:, **inbox_condition)
47-
.includes(:type)
48-
.order_by_position
49-
.order(WorkPackage.arel_table[:id].asc)
50-
end
51-
52-
def initialize(sprint:, stories:)
53-
@sprint = sprint
54-
@stories = stories
55-
end
34+
class_methods do
35+
def backlogs_inbox_for(project:)
36+
inbox_condition = if OpenProject::FeatureDecisions.backlog_buckets_active?
37+
{ sprint_id: nil, backlog_bucket_id: nil }
38+
else
39+
{ sprint_id: nil }
40+
end
5641

57-
def to_key
58-
[sprint_id]
42+
WorkPackage
43+
.visible
44+
.with_status_open
45+
.where(project:, **inbox_condition)
46+
.includes(:type)
47+
.order_by_position
48+
.order(WorkPackage.arel_table[:id].asc)
49+
end
5950
end
6051
end

modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch
4747
belongs_to :sprint, optional: true
4848

4949
include OpenProject::Backlogs::List
50+
51+
scopes :backlogs_inbox_for
5052
end
5153

5254
module ClassMethods

modules/backlogs/spec/models/backlog_spec.rb

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# frozen_string_literal: true
2+
3+
# -- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
# ++
30+
31+
require "spec_helper"
32+
33+
RSpec.describe WorkPackages::Scopes::BacklogsInboxFor do
34+
let(:project) { create(:project) }
35+
let(:open_status) { create(:status, is_closed: false) }
36+
let(:closed_status) { create(:status, is_closed: true) }
37+
let(:sprint) { create(:sprint, project:) }
38+
39+
before { login_as create(:admin) }
40+
41+
subject(:inbox) { WorkPackage.backlogs_inbox_for(project:) }
42+
43+
describe ".backlogs_inbox_for" do
44+
it "returns work packages with no sprint assigned and open status" do
45+
inbox_wp = create(:work_package, project:, status: open_status)
46+
create(:work_package, project:, status: closed_status)
47+
create(:work_package, project:, status: open_status, sprint:)
48+
49+
expect(inbox).to contain_exactly(inbox_wp)
50+
end
51+
52+
it "excludes work packages from other projects" do
53+
create(:work_package, status: open_status)
54+
own_wp = create(:work_package, project:, status: open_status)
55+
56+
expect(inbox).to contain_exactly(own_wp)
57+
end
58+
59+
it "orders by position ascending, falling back to id for unpositioned items" do
60+
wp1 = create(:work_package, project:, status: open_status, position: 2)
61+
wp2 = create(:work_package, project:, status: open_status, position: 1)
62+
wp3 = create(:work_package, project:, status: open_status, position: nil)
63+
wp4 = create(:work_package, project:, status: open_status, position: nil)
64+
65+
wp3.update_column(:position, nil)
66+
wp4.update_column(:position, nil)
67+
68+
expect(inbox).to eq([wp2, wp1, wp3, wp4])
69+
end
70+
end
71+
end

0 commit comments

Comments
 (0)