Skip to content

Commit

Permalink
Merge pull request #379 from OpenSourcePolitics/develop
Browse files Browse the repository at this point in the history
Co-authored-by: Quentin Champenois <[email protected]>
Co-authored-by: moustachu <[email protected]>
Co-authored-by: eliegaboriau <[email protected]>
fix Sentry (#369)
fix: Assets in docker-compose (#370)
fix: Fix rubocop (#371)
Fix interactive map wrong version (#383)
  • Loading branch information
armandfardeau authored Jul 31, 2023
2 parents d040fed + af7b093 commit 808246b
Show file tree
Hide file tree
Showing 46 changed files with 172 additions and 98 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ jobs:
key: asset-cache-${{ runner.os }}-${{ steps.cache-hash.outputs.hash }}
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/[email protected]

# TODO: Use latest version
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: "114.0.5735.90"
- run: bundle exec rake "test:run[exclude, spec/system/**/*_spec.rb, ${{ matrix.slice }}]"
name: RSpec
- run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
Expand Down Expand Up @@ -153,7 +157,10 @@ jobs:
key: asset-cache-${{ runner.os }}-${{ steps.cache-hash.outputs.hash }}
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/[email protected]
# TODO: Use latest version
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: "114.0.5735.90"
- run: bundle exec rake "test:run[include, spec/system/**/*_spec.rb, ${{ matrix.slice }}]"
name: RSpec
- run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
Expand Down
2 changes: 2 additions & 0 deletions .rubocop_rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Rails/ScopeArgs:

Rails/SkipsModelValidations:
Enabled: true
Exclude:
- db/migrate/*.rb

Rails/Validation:
Include:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GIT

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-homepage_interactive_map.git
revision: 3bbd5fff51fbfa94ff6e784baa73af190b1c679d
revision: 4e6b7a1a5fcfa0661ba93d1bedb2e09da66d5326
branch: release/0.26-stable
specs:
decidim-homepage_interactive_map (2.0.0)
Expand Down
45 changes: 45 additions & 0 deletions app/services/decidim/repair_comments_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module Decidim
class RepairCommentsService
include Decidim::TranslatableAttributes

def self.run
new.execute
end

def execute
return [] if ok?

update_comments!
end

def ok?
invalid_comments.empty?
end

def invalid_comments
return @invalid_comments if @invalid_comments

invalid_comments = []
Decidim::Comments::Comment.find_each do |comment|
next if translated_attribute(comment.body).is_a?(String)

invalid_comments << [comment, comment.body.values.first]
end
@invalid_comments = invalid_comments
end

private

# Update each users with new nickname
# Returns Array of updated User ID
def update_comments!
invalid_comments.map do |comment, new_body|
comment.body = new_body

comment.id if comment.save!(validate: false) # Validation is skipped to allow updating comments from root that don't accepts new comments
end.compact
end
end
end
2 changes: 1 addition & 1 deletion config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

require "initializers/sentry_setup"
require "decidim_app/sentry_setup"

SentrySetup.init
3 changes: 0 additions & 3 deletions db/migrate/20180611124846_fix_nickname_index.decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def change
.where(managed: false)
.find_each { |u| u.update(nickname: User.nicknamize(u.name)) }

# rubocop:disable Rails/SkipsModelValidations
User.where(nickname: nil).update_all("nickname = ''")
# rubocop:enable Rails/SkipsModelValidations

change_column_default :decidim_users, :nickname, ""
change_column_null(:decidim_users, :nickname, false)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def up
version_id = action_log.extra.dig("version", "id")
next unless version_id

# rubocop:disable Rails/SkipsModelValidations
action_log.update_column(:version_id, version_id)
# rubocop:enable Rails/SkipsModelValidations
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ def change
rename_index :decidim_components, "index_decidim_features_on_decidim_participatory_space", "index_decidim_components_on_decidim_participatory_space"
end

# rubocop:disable Rails/SkipsModelValidations
Version.where(item_type: "Decidim::Feature").update_all(item_type: "Decidim::Component")
ActionLog.where(resource_type: "Decidim::Feature").update_all(resource_type: "Decidim::Component")
# rubocop:enable Rails/SkipsModelValidations

ActionLog.find_each do |log|
new_extra = log.extra.dup
next if new_extra["component"].present?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

class ChangeEventNameAndClassToRenameToPublishProposalEvent < ActiveRecord::Migration[5.1]
def up
# rubocop:disable Rails/SkipsModelValidations
Decidim::Notification.where(event_name: "decidim.events.proposals.proposal_created")
.update_all(event_name: "decidim.events.proposals.proposal_published", event_class: "Decidim::Proposals::PublishProposalEvent")
# rubocop:enable Rails/SkipsModelValidations
end

def down
# rubocop:disable Rails/SkipsModelValidations
Decidim::Notification.where(event_name: "decidim.events.proposals.proposal_published")
.update_all(event_name: "decidim.events.proposals.proposal_created", event_class: "Decidim::Proposals::CreateProposalEvent")
# rubocop:enable Rails/SkipsModelValidations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class User < ApplicationRecord
def up
add_column :decidim_users, :accepted_tos_version, :datetime
Organization.find_each do |organization|
# rubocop:disable Rails/SkipsModelValidations
organization.users.update_all(accepted_tos_version: organization.tos_version)
# rubocop:enable Rails/SkipsModelValidations
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

class UpdateRootCommentableForComments < ActiveRecord::Migration[5.0]
def up
# rubocop:disable Rails/SkipsModelValidations
Decidim::Comments::Comment.where(depth: 0).update_all(
"decidim_root_commentable_id = decidim_commentable_id, decidim_root_commentable_type = decidim_commentable_type"
)
# rubocop:enable Rails/SkipsModelValidations

Decidim::Comments::Comment.where("depth > 0").find_each do |comment|
comment.root_commentable = root_commentable(comment)
comment.save(validate: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
class AddPublishedAtToProposals < ActiveRecord::Migration[5.1]
def up
add_column :decidim_proposals_proposals, :published_at, :datetime, index: true
# rubocop:disable Rails/SkipsModelValidations
Decidim::Proposals::Proposal.update_all("published_at = updated_at")
# rubocop:enable Rails/SkipsModelValidations
end

def down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ResourceLink < ApplicationRecord
def up
return unless ActiveRecord::Base.connection.data_source_exists? :decidim_results_results

# rubocop:disable Rails/SkipsModelValidations
OldResult.find_each do |old_result|
Result.create!(
id: old_result.id,
Expand All @@ -51,5 +50,4 @@ def up

drop_table :decidim_results_results
end
# rubocop:enable Rails/SkipsModelValidations
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class Notification < ApplicationRecord
end

def up
# rubocop:disable Rails/SkipsModelValidations
Notification.where(decidim_resource_type: "Decidim::Feature").update_all(decidim_resource_type: "Decidim::Component")
Notification.where(event_class: "Decidim::FeaturePublishedEvent").update_all(event_class: "Decidim::ComponentPublishedEvent")
Notification.where(event_name: "decidim.events.features.feature_published").update_all(event_name: "decidim.events.components.component_published")
# rubocop:enable Rails/SkipsModelValidations
end
end
2 changes: 0 additions & 2 deletions db/migrate/20181012230419_fix_result_follows.decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

class FixResultFollows < ActiveRecord::Migration[5.2]
def change
# rubocop:disable Rails/SkipsModelValidations
Decidim::Follow.where(decidim_followable_type: "Decidim::Results::Result").update_all(decidim_followable_type: "Decidim::Accountability::Result")
# rubocop:enable Rails/SkipsModelValidations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Coauthorship < ApplicationRecord
self.table_name = "decidim_coauthorships"
end

# rubocop:disable Rails/SkipsModelValidations
def change
add_column :decidim_users, :type, :string
User.update_all(type: "Decidim::User")
Expand Down Expand Up @@ -82,5 +81,4 @@ def change

drop_table :decidim_user_groups
end
# rubocop:enable Rails/SkipsModelValidations
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This migration comes from decidim_comments (originally 20181003080320)

class FixUserGroupsIdsInComments < ActiveRecord::Migration[5.2]
# rubocop:disable Rails/SkipsModelValidations
def change
Decidim::UserGroup.find_each do |group|
old_id = group.extended_data["old_user_group_id"]
Expand All @@ -14,5 +13,4 @@ def change
.update_all(decidim_user_group_id: group.id)
end
end
# rubocop:enable Rails/SkipsModelValidations
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This migration comes from decidim_proposals (originally 20181003074440)

class FixUserGroupsIdsInProposalsEndorsements < ActiveRecord::Migration[5.2]
# rubocop:disable Rails/SkipsModelValidations
def change
Decidim::UserGroup.find_each do |group|
old_id = group.extended_data["old_user_group_id"]
Expand All @@ -14,5 +13,4 @@ def change
.update_all(decidim_user_group_id: group.id)
end
end
# rubocop:enable Rails/SkipsModelValidations
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This migration comes from decidim_debates (originally 20181003081235)

class FixUserGroupsIdsOnDebates < ActiveRecord::Migration[5.2]
# rubocop:disable Rails/SkipsModelValidations
def change
Decidim::UserGroup.find_each do |group|
old_id = group.extended_data["old_user_group_id"]
Expand All @@ -14,5 +13,4 @@ def change
.update_all(decidim_user_group_id: group.id)
end
end
# rubocop:enable Rails/SkipsModelValidations
end
2 changes: 0 additions & 2 deletions db/migrate/20181220220346_add_columns_to_pages.decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class StaticPage < ApplicationRecord
self.table_name = :decidim_static_pages
end

# rubocop:disable Rails/SkipsModelValidations
def change
change_table :decidim_static_pages do |t|
t.column :weight, :integer, default: nil, null: true
Expand All @@ -17,6 +16,5 @@ def change
Decidim::StaticPage.where(
slug: ["faq", "terms-and-conditions", "accessibility"]
).update_all(show_in_footer: true)
# rubocop:enable Rails/SkipsModelValidations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
class AddTimestampsToComponents < ActiveRecord::Migration[5.2]
def change
add_timestamps :decidim_components, null: true
# rubocop:disable Rails/SkipsModelValidations
Decidim::Component.update_all(created_at: Time.current, updated_at: Time.current)
# rubocop:enable Rails/SkipsModelValidations
change_column_null :decidim_components, :created_at, false
change_column_null :decidim_components, :updated_at, false
end
Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20181220220349_fix_user_follows.decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class Follow < ApplicationRecord
end

def change
# rubocop:disable Rails/SkipsModelValidations
Follow.where(
decidim_followable_type: "Decidim::User"
).update_all(decidim_followable_type: "Decidim::UserBaseEntity")
# rubocop:enable Rails/SkipsModelValidations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def change
add_column :decidim_organizations, :id_documents_methods, :string, array: true, default: ["online"]
add_column :decidim_organizations, :id_documents_explanation_text, :jsonb, default: {}

# rubocop:disable Rails/SkipsModelValidations
Decidim::Organization.reset_column_information
Decidim::Organization.update_all(id_documents_methods: ["online"])
# rubocop:enable Rails/SkipsModelValidations
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
class AddNotificationTypesToUsers < ActiveRecord::Migration[5.2]
def change
add_column :decidim_users, :notification_types, :string, default: "all"
# rubocop:disable Rails/SkipsModelValidations
Decidim::UserBaseEntity.update_all(notification_types: "all")
# rubocop:enable Rails/SkipsModelValidations

change_column_null :decidim_users, :notification_types, false
end
end
2 changes: 0 additions & 2 deletions db/migrate/20190717132653_fix_user_names.decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def change

entity.name = entity.name.delete(characters_to_remove).strip
sanitized_nickname = entity.nickname.delete(characters_to_remove).strip
# rubocop:disable Rails/SkipsModelValidations
entity.update_columns(nickname: Decidim::UserBaseEntity.nicknamize(sanitized_nickname, organization: entity.organization))
# rubocop:enable Rails/SkipsModelValidations
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
class AddDirectMessageTypesToUsers < ActiveRecord::Migration[5.2]
def change
add_column :decidim_users, :direct_message_types, :string, default: "all"
# rubocop:disable Rails/SkipsModelValidations
Decidim::UserBaseEntity.update_all(direct_message_types: "all")
# rubocop:enable Rails/SkipsModelValidations

change_column_null :decidim_users, :direct_message_types, false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def change
add_column :decidim_organizations, :machine_translation_display_priority, :string

Organization.reset_column_information
Organization.update_all(machine_translation_display_priority: :original) # rubocop:disable Rails/SkipsModelValidations
Organization.update_all(machine_translation_display_priority: :original)

change_column_default :decidim_organizations, :machine_translation_display_priority, "original"
change_column_null :decidim_organizations, :machine_translation_display_priority, false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ def create_budget_resource_from(component)
end

def add_budget_references_to_projects(resource)
# rubocop:disable Rails/SkipsModelValidations
Project.where(decidim_component_id: resource.decidim_component_id)
.update_all(decidim_budgets_budget_id: resource.id)
# rubocop:enable Rails/SkipsModelValidations
end

def add_budget_reference_to_orders(resource)
# rubocop:disable Rails/SkipsModelValidations
Order.where(decidim_component_id: resource.decidim_component_id)
.update_all(decidim_budgets_budget_id: resource.id)
# rubocop:enable Rails/SkipsModelValidations
end

# down methods
Expand All @@ -96,16 +92,12 @@ def revert_budget_to_component(resource)
end

def add_component_reference_to_orders(resource)
# rubocop:disable Rails/SkipsModelValidations
Order.where(decidim_budgets_budget_id: resource.id)
.update_all(decidim_component_id: resource.decidim_component_id)
# rubocop:enable Rails/SkipsModelValidations
end

def add_component_reference_to_projects(resource)
# rubocop:disable Rails/SkipsModelValidations
Project.where(decidim_budgets_budget_id: resource.id)
.update_all(decidim_component_id: resource.decidim_component_id)
# rubocop:enable Rails/SkipsModelValidations
end
end
Loading

0 comments on commit 808246b

Please sign in to comment.