Skip to content

Commit

Permalink
Fix shortlink references (decidim#12004)
Browse files Browse the repository at this point in the history
* Fix shortlink references

* Add rake task to fix data

* Add release notes
  • Loading branch information
alecslupu authored Nov 15, 2023
1 parent f4352e7 commit 79254ee
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ bundle exec rails decidim:upgrade:fix_duplicate_endorsements

You can see more details about this change on PR [\#11853](https://github.com/decidim/decidim/pull/11853)

### 3.13 Fix component short links

We have identified that some of the short links for components are not working properly. We have added a new task that helps you fix the short links for components.

```bash
bundle exec rails decidim:upgrade:fix_short_urls
```

You can see more details about this change on PR [\#12004](https://github.com/decidim/decidim/pull/12004)

## 4. Scheduled tasks

Implementers need to configure these changes it in your scheduler task system in the production server. We give the examples
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/helpers/decidim/short_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def short_url(**kwargs)
target ||= respond_to?(:current_organization) && current_organization
target ||= Rails.application

mounted_engine = EngineResolver.new(_routes).mounted_name
mounted_engine = target.try(:mounted_engine) || EngineResolver.new(_routes).mounted_name
ShortLink.to(target, mounted_engine, **kwargs).short_url
end
end
Expand Down
22 changes: 22 additions & 0 deletions decidim-core/lib/tasks/upgrade/decidim_fix_short_url_resolver.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

namespace :decidim do
namespace :upgrade do
desc "Fix wrongly mapped short links components"
task fix_short_urls: :environment do
logger = Logger.new($stdout)
logger.info("Fixing wrongly mapped short links...")

Decidim::ShortLink.where(target_type: "Decidim::Component").find_each do |short_url|
real_component = Decidim::Component.find_by(id: short_url.target_id)

next if real_component.nil?
next if short_url.mounted_engine_name == real_component.mounted_engine

logger.info("Fixing #{short_url.identifier}: #{short_url.mounted_engine_name} to #{real_component.mounted_engine}")
short_url.update(mounted_engine_name: real_component.mounted_engine)
end
logger.info("Done fixing wrongly mapped short links.")
end
end
end
25 changes: 25 additions & 0 deletions decidim-meetings/spec/system/explore_meetings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@
end
end

context "when displaying calendar" do
let(:component) { create(:meeting_component, participatory_space:) }
let(:link) { Decidim::ShortLink.find_by(target_type: "Decidim::Component", target_id: component.id) }

before do
visit_component
end

context "when meetings mounted under paraticipatory process" do
let(:participatory_space) { create(:participatory_process, organization:) }

it "properly saves the shortened link" do
expect(link.mounted_engine_name).to eq("decidim_participatory_process_meetings")
end
end

context "when meetings mounted under assemblies" do
let(:participatory_space) { create(:assembly, organization:) }

it "properly saves the shortened link" do
expect(link.mounted_engine_name).to eq("decidim_assembly_meetings")
end
end
end

context "with default filter" do
let!(:past_meeting) { create(:meeting, :published, start_time: 2.weeks.ago, component:) }
let!(:upcoming_meeting) { create(:meeting, :published, :not_official, component:) }
Expand Down

0 comments on commit 79254ee

Please sign in to comment.