Skip to content

Commit

Permalink
Merge pull request #266 from inventaire/merge
Browse files Browse the repository at this point in the history
entities merge: reject circular merges
  • Loading branch information
jum-s committed Jan 27, 2019
2 parents 7e1d4f3 + b3a69a5 commit be50e3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions server/controllers/entities/merge.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ merge = (reqUserId, toPrefix, fromUri, toUri)-> (res)->
toEntity = entities[toUri] or entities[redirects[toUri]]
unless toEntity? then throw notFound 'to', toUri

if fromEntity.uri is toEntity.uri
throw error_.new "can't merge an entity into itself", 400, { fromUri, toUri }

unless fromEntity.type is toEntity.type
# Exception: authors can be organizations and collectives of all kinds
# which will not get a 'human' type
Expand Down
10 changes: 4 additions & 6 deletions tests/api/entities/merge.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@ describe 'entities:merge', ->

return

it 'should reject merge of a redirection to a wd entity', (done)->
wdEntityUri = 'wd:Q618719'
it 'should reject a circular merge', (done)->
createWork()
.then (workA)->
merge workA.uri, wdEntityUri
.then -> merge workA.uri, wdEntityUri
.then (work)->
merge work.uri, work.uri
.then undesiredRes(done)
.catch (err)->
err.statusCode.should.equal 400
err.body.status_verbose
.should.equal 'turnIntoRedirection failed: the entity is a redirection'
.should.equal "can't merge an entity into itself"
done()
.catch undesiredErr(done)

Expand Down

0 comments on commit be50e3d

Please sign in to comment.