diff --git a/app/models/map.rb b/app/models/map.rb index dd5e5604..cad2c360 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -86,10 +86,14 @@ class Map < ApplicationRecord user&.stars&.where(map: self)&.exists? || false # return false, not nil end + def fork_children_ids + Map.where(source_id: id).map(&:id) + end + def as_json(_options = {}) json = super( methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count, - :contributor_count, :collaborator_ids, :screenshot_url], + :contributor_count, :collaborator_ids, :screenshot_url, :fork_children_ids], except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at] ) diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index 3f6fcd9c..f1714a41 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -362,26 +362,36 @@ const InfoBox = { event.stopPropagation() }, deleteActiveMap: function() { - var confirmString = 'Are you sure you want to delete this map? ' + let confirmString = 'Are you sure you want to delete this map? ' confirmString += 'This action is irreversible. It will not delete the topics and synapses on the map.' - var doIt = window.confirm(confirmString) - var map = Active.Map - var mapper = Active.Mapper - var authorized = map.authorizePermissionChange(mapper) + const doIt = window.confirm(confirmString) + const map = Active.Map + const authorized = map.authorizePermissionChange(Active.Mapper) - if (doIt && authorized) { - InfoBox.close() - DataModel.Maps.Active.remove(map) - DataModel.Maps.Featured.remove(map) - DataModel.Maps.Mine.remove(map) - DataModel.Maps.Shared.remove(map) - map.destroy() - browserHistory.push('/') - GlobalUI.notifyUser('Map eliminated') - } else if (!authorized) { - window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?") + if (!doIt) { + return } + if (!authorized) { + window.alert("Hey now. We can't just go around willy nilly deleting other people's maps now can we? Run off and find something constructive to do, eh?") + return + } + if (map.fork_children_ids.length > 0) { + let forkMessage = "This map has been forked, so it can't be deleted. The forked map idss are:" + forkMessage += map.fork_children_ids.join(', ') + window.alert(forkMessage) + return + } + + // confirmed deletion, authorized, and no fork children + InfoBox.close() + DataModel.Maps.Active.remove(map) + DataModel.Maps.Featured.remove(map) + DataModel.Maps.Mine.remove(map) + DataModel.Maps.Shared.remove(map) + map.destroy() + browserHistory.push('/') + GlobalUI.notifyUser('Map eliminated') } }