Skip to content

Commit

Permalink
Show list of existing media URLs in validation message when trying to…
Browse files Browse the repository at this point in the history
… import media from feed that already exist in the workspace. (#1895)

Fixes: CV2-4631.
  • Loading branch information
caiosba authored May 22, 2024
1 parent cf490f2 commit 98bdac2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/models/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def import_media_to_team(team, from_project_media, claim_title = nil, claim_cont

def import_medias_to_team(team, claim_title, claim_context, parent_id = nil)
# Find the first item in this cluster for which the media_id doesn't exist in the target team yet
from_project_media = self.project_medias.where.not(team_id: team.id).select(:id, :media_id).find { |item| !ProjectMedia.where(team_id: team.id, media_id: item.media_id).exists? }
raise 'No media to import. All media items from this item already exist in your workspace.' if from_project_media.nil?
# Should be fine to load these in memory since clusters don't contain thousands of media
existing_items = self.project_medias.where(team_id: team.id).to_a
from_project_media = self.project_medias.where.not(team_id: team.id).select(:id, :media_id).find do |item|
existing_item = ProjectMedia.where(team_id: team.id, media_id: item.media_id).first
existing_items << existing_item
existing_item.nil?
end
raise ActiveRecord::RecordNotUnique.new(I18n.t(:shared_feed_imported_media_already_exist, urls: existing_items.map(&:full_url).uniq.compact_blank.join(', '))) if from_project_media.nil?
parent = nil
if parent_id.nil?
parent = self.import_media_to_team(team, from_project_media, claim_title, claim_context)
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ en:
send_every_must_be_a_list_of_days_of_the_week: must be a list of days of the week.
send_on_must_be_in_the_future: can't be in the past.
cant_delete_default_folder: The default folder can't be deleted
shared_feed_imported_media_already_exist: "No media to import. All media items from this item already exist in your workspace: %{urls}"
info:
messages:
sent_to_trash_by_rule: '"%{item_title}" has been sent to trash by an automation
Expand Down

0 comments on commit 98bdac2

Please sign in to comment.