-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Feature/73109 sorting and uniqueness constraint in inbox and sprints #22393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
945b618
b5d88bb
cf5bd6a
0396a91
b93d45e
8ca5415
e5f9243
1bf4266
8b76956
226af7e
820d138
0459379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,11 @@ def update | |
| end | ||
|
|
||
| def rebuild_positions | ||
| @project.rebuild_positions | ||
| if OpenProject::FeatureDecisions.scrum_projects_active? | ||
| WorkPackages::RebuildPositionsService.new(project: @project).call | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have a return value here that indicates success or failure. Right now, we always show the flash notice - even if this service call would fail. This would additionally allow us to write a more unit-test-style spec for the service. But I don't see a way to do this easily, so this will remain a wish for now. Since this action is not expected to be called often, investing all this time seems to be not worth it. |
||
| else | ||
| @project.rebuild_positions | ||
| end | ||
| flash[:notice] = I18n.t("backlogs.positions_rebuilt_successfully") | ||
|
|
||
| redirect_to_backlogs_settings | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # -- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| # ++ | ||
|
|
||
| class WorkPackages::RebuildPositionsService | ||
| def initialize(project: nil) | ||
| @project = project | ||
| end | ||
|
|
||
| def call | ||
| condition = if @project | ||
| ::OpenProject::SqlSanitization.sanitize " AND work_packages.project_id = :project_id", | ||
| project_id: @project.id | ||
| end | ||
|
|
||
| WorkPackage.connection.execute <<~SQL.squish | ||
| UPDATE work_packages | ||
| SET position = mapping.new_position | ||
| FROM ( | ||
| SELECT | ||
| id, | ||
| ROW_NUMBER() OVER ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL about |
||
| PARTITION BY project_id, sprint_id | ||
| ORDER BY position, created_at | ||
| ) AS new_position | ||
| FROM work_packages | ||
| ) AS mapping | ||
| WHERE work_packages.id = mapping.id | ||
| #{condition} | ||
| SQL | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Well spotted 👍