-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[STC-767] Release old semantic identifiers #23697
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/services/project_identifiers/release_reserved_identifier_service.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # 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. | ||
| #++ | ||
|
|
||
| module ProjectIdentifiers | ||
| # Releases a historically reserved project identifier slug. | ||
| # Additionally removes the WorkPackageSemanticAlias rows created for that | ||
| # slug prefix ("<slug>-<digits>") atomically with the slug destroy, so the | ||
| # released prefix no longer resolves work packages. In classic mode it also | ||
| # clears stale work package identifier columns carrying the prefix | ||
| # (leftovers from a previous semantic phase), which would otherwise keep old | ||
| # links resolving and shadow the alias rows of a new project claiming the | ||
| # identifier after a later re-conversion. | ||
| class ReleaseReservedIdentifierService | ||
| def initialize(slug) | ||
| @slug = slug | ||
| end | ||
|
|
||
| def call | ||
| FriendlyId::Slug.transaction do | ||
| delete_aliases | ||
| clear_stale_work_package_identifiers | ||
| @slug.destroy! | ||
| end | ||
|
|
||
| ServiceResult.success | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def delete_aliases | ||
| WorkPackageSemanticAlias.for_slug_prefix(@slug.slug).delete_all | ||
| end | ||
|
|
||
| # A historically reserved slug is no project's current identifier, so any | ||
| # work package still carrying "<slug>-<digits>" in its identifier column is | ||
| # stale (left over from a revert to classic mode). The finder resolves | ||
| # semantic identifiers against this column as well as the alias table, so | ||
| # clearing it severs resolution immediately instead of waiting for the next | ||
| # semantic conversion's reset_stale_identifiers to do the same. | ||
| # | ||
| # Only relevant in classic mode: in semantic mode the identifier column | ||
| # carries the live semantic identifiers of the projects currently using | ||
| # the mode, which must not be cleared. | ||
| def clear_stale_work_package_identifiers | ||
| return unless Setting::WorkPackageIdentifier.classic? | ||
|
|
||
| WorkPackage.for_slug_prefix(@slug.slug).update_all(identifier: nil, sequence_number: nil) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
spec/components/admin/settings/project_reserved_identifiers/release_dialog_component_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # 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. | ||
| #++ | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe Admin::Settings::ProjectReservedIdentifiers::ReleaseDialogComponent, type: :component do | ||
| let!(:project) { create(:project) } | ||
| let!(:slug) { FriendlyId::Slug.create!(sluggable: project, slug: "old-id") } | ||
|
|
||
| subject(:rendered_component) { render_inline(described_class.new(slug:)) } | ||
|
|
||
| it "renders the heading with the identifier" do | ||
| expect(rendered_component) | ||
| .to have_text(I18n.t("admin.reserved_identifiers.dialog.heading", identifier: "old-id")) | ||
| end | ||
|
|
||
| context "without affected work packages" do | ||
| it "renders the plain description" do | ||
| expect(rendered_component) | ||
| .to have_text(I18n.t("admin.reserved_identifiers.dialog.description")) | ||
| expect(rendered_component).to have_no_text("work package") | ||
| end | ||
| end | ||
|
|
||
| context "with one affected work package" do | ||
| before { create(:work_package_semantic_alias, identifier: "old-id-1") } | ||
|
|
||
| it "renders the singular description" do | ||
| expect(rendered_component) | ||
| .to have_text(I18n.t("admin.reserved_identifiers.dialog.description_with_work_packages", count: 1)) | ||
| end | ||
| end | ||
|
|
||
| context "with several affected work packages" do | ||
| before do | ||
| create(:work_package_semantic_alias, identifier: "old-id-1") | ||
| create(:work_package_semantic_alias, identifier: "old-id-2") | ||
| end | ||
|
|
||
| it "renders the pluralized description" do | ||
| expect(rendered_component) | ||
| .to have_text(I18n.t("admin.reserved_identifiers.dialog.description_with_work_packages", count: 2)) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.