adapt-authoring-adaptframework 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -169,6 +169,11 @@ class AdaptFrameworkImport {
169
169
  * @type {Array<String>}
170
170
  */
171
171
  this.newTagIds = []
172
+ /**
173
+ * Array of asset IDs newly created during import for rollback. Excludes assets de-duplicated to existing records.
174
+ * @type {Array<String>}
175
+ */
176
+ this.newAssetIds = []
172
177
  /**
173
178
  * Contains non-fatal infomation messages regarding import status which can be return as response data. Fatal errors are thrown in the usual way.
174
179
  * @type {Object}
@@ -595,7 +600,9 @@ class AdaptFrameworkImport {
595
600
  })
596
601
  // store the asset _id so we can map it to the old path later
597
602
  const resolved = path.relative(`${this.coursePath}/..`, filepath)
598
- this.assetMap[resolved] = asset._id.toString()
603
+ const assetId = asset._id.toString()
604
+ this.assetMap[resolved] = assetId
605
+ this.newAssetIds.push(assetId)
599
606
  } catch (e) {
600
607
  if (e.code === 'DUPLICATE_ASSET') {
601
608
  const resolved = path.relative(`${this.coursePath}/..`, filepath)
@@ -902,9 +909,9 @@ class AdaptFrameworkImport {
902
909
  if (Object.keys(this.updatedContentPlugins).length) {
903
910
  tasks.push(this.restoreUpdatedPlugins())
904
911
  }
905
- // Delete imported assets
906
- if (this.assets) {
907
- tasks.push(...Object.values(this.assetMap).map(id =>
912
+ // Delete newly created assets (skip de-duplicated assets which point to pre-existing records)
913
+ if (this.assets && this.newAssetIds.length) {
914
+ tasks.push(...this.newAssetIds.map(id =>
908
915
  this.assets.delete({ _id: id })
909
916
  .catch(e => log('warn', `failed to delete asset '${id}'`, e))
910
917
  ))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-adaptframework",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Adapt framework integration for the Adapt authoring tool",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-adaptframework",
6
6
  "license": "GPL-3.0",
@@ -404,6 +404,7 @@ describe('AdaptFrameworkImport', () => {
404
404
  newContentPlugins: {},
405
405
  updatedContentPlugins: {},
406
406
  assetMap: {},
407
+ newAssetIds: [],
407
408
  newTagIds: [],
408
409
  contentJson: { course: {} },
409
410
  idMap: {},
@@ -438,12 +439,29 @@ describe('AdaptFrameworkImport', () => {
438
439
  assetMap: {
439
440
  'course/en/assets/logo.png': 'a1',
440
441
  'course/en/assets/bg.jpg': 'a2'
441
- }
442
+ },
443
+ newAssetIds: ['a1', 'a2']
442
444
  })
443
445
  await rollback.call(ctx)
444
446
  assert.deepEqual(deleted.sort(), ['a1', 'a2'])
445
447
  })
446
448
 
449
+ it('should not delete de-duplicated assets that point to pre-existing records', async () => {
450
+ const deleted = []
451
+ const ctx = makeRollbackCtx({
452
+ assets: {
453
+ delete: async ({ _id }) => deleted.push(_id)
454
+ },
455
+ assetMap: {
456
+ 'course/en/assets/new.png': 'a1',
457
+ 'course/en/assets/existing.png': 'a2-existing'
458
+ },
459
+ newAssetIds: ['a1']
460
+ })
461
+ await rollback.call(ctx)
462
+ assert.deepEqual(deleted, ['a1'])
463
+ })
464
+
447
465
  it('should delete course content on rollback', async () => {
448
466
  const contentDeleted = []
449
467
  const ctx = makeRollbackCtx({
@@ -499,7 +517,8 @@ describe('AdaptFrameworkImport', () => {
499
517
  'path/a.png': 'a1',
500
518
  'path/b.png': 'a2',
501
519
  'path/c.png': 'a3'
502
- }
520
+ },
521
+ newAssetIds: ['a1', 'a2', 'a3']
503
522
  })
504
523
  await rollback.call(ctx)
505
524
  assert.deepEqual(deleted.sort(), ['a2', 'a3'])