alert user if map deletion fails because it's been forked
This commit is contained in:
parent
a6694a3f72
commit
39d28ee136
2 changed files with 31 additions and 17 deletions
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -362,15 +362,28 @@ 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) {
|
||||
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)
|
||||
|
@ -379,9 +392,6 @@ const InfoBox = {
|
|||
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?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue