diff --git a/lib/osf-components/addon/components/files/item/template.hbs b/lib/osf-components/addon/components/files/item/template.hbs index fe346e58d7a..2b681d966b9 100644 --- a/lib/osf-components/addon/components/files/item/template.hbs +++ b/lib/osf-components/addon/components/files/item/template.hbs @@ -11,43 +11,47 @@ {{this.item.itemName}} - - -
{{t 'osf-components.files-widget.confirm_delete.body'}}
-
-
- {{else}} -
- - {{this.item.itemName}} -
- {{#unless this.item.isFolder}} - + {{#if @filesManager.canEdit}}
{{t 'osf-components.files-widget.confirm_delete.body'}}
+ {{/if}} + {{else}} +
+ + {{this.item.itemName}} +
+ {{#unless this.item.isFolder}} + + {{#if @filesManager.canEdit}} + + +
{{t 'osf-components.files-widget.confirm_delete.body'}}
+
+
+ {{/if}} {{/unless}} {{/if}} diff --git a/lib/osf-components/addon/components/files/menu/template.hbs b/lib/osf-components/addon/components/files/menu/template.hbs index de2aec1883a..96e880e8bb3 100644 --- a/lib/osf-components/addon/components/files/menu/template.hbs +++ b/lib/osf-components/addon/components/files/menu/template.hbs @@ -3,17 +3,20 @@ @onClose={{fn this.onCloseMenu @isUploading}} as |dropdownMenu| > -
- - - -
+ {{#if this.canEdit}} +
+ + + +
+ {{/if}} {{/each}} diff --git a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/component.ts b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/component.ts index 6f7d846cde8..54f53965413 100644 --- a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/component.ts +++ b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/component.ts @@ -17,6 +17,7 @@ import pathJoin from 'ember-osf-web/utils/path-join'; import AbstractNodeModel from 'ember-osf-web/models/abstract-node'; import DraftRegistrationModel from 'ember-osf-web/models/draft-registration'; +import SchemaResponseModel from 'ember-osf-web/models/schema-response'; import styles from './styles'; import template from './template'; @@ -30,7 +31,8 @@ export default class Files extends Component { // Required param changeset!: BufferedChangeset; schemaBlock!: SchemaBlock; - draftRegistration!: DraftRegistrationModel; + draftRegistration?: DraftRegistrationModel; + revision?: SchemaResponseModel; @alias('schemaBlock.registrationResponseKey') valuePath!: string; @@ -42,7 +44,15 @@ export default class Files extends Component { @computed('draftRegistration', 'node.id') get nodeUrl() { - return pathJoin(baseURL, this.draftRegistration.belongsTo('branchedFrom').id()); + if (this.node) { + return pathJoin(baseURL, this.node.id); + } + return ''; + } + + @computed('revision', 'node', 'currentUserIsReadOnly') + get canEdit() { + return !this.revision && (this.node && !this.currentUserIsReadOnly); } didReceiveAttrs() { @@ -51,8 +61,8 @@ export default class Files extends Component { Boolean(this.changeset), ); assert( - 'Registries::SchemaBlockRenderer::Editable::Files requires a draft-registration to render', - Boolean(this.draftRegistration), + 'Registries::SchemaBlockRenderer::Editable::Files requires a draft-registration xor a revision to render', + Boolean(this.draftRegistration) !== Boolean(this.revision), ); assert( 'Registries::SchemaBlockRenderer::Editable::Files requires a valuePath to render', @@ -63,7 +73,11 @@ export default class Files extends Component { Boolean(this.schemaBlock), ); - this.node = this.draftRegistration.belongsTo('branchedFrom').value() as AbstractNodeModel; + if (this.draftRegistration) { + this.node = this.draftRegistration.belongsTo('branchedFrom').value() as AbstractNodeModel; + } else { + this.node = this.revision!.belongsTo('registration').value() as AbstractNodeModel; + } this.set('selectedFiles', this.changeset.get(this.valuePath) || []); } diff --git a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/template.hbs b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/template.hbs index 3824a92f56e..b1768fcf123 100644 --- a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/template.hbs +++ b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/files/template.hbs @@ -39,7 +39,7 @@ @onSelectFile={{action this.onSelectFile}} @onAddFile={{action this.onAddFile}} @onDeleteFile={{this.onDeleteFile}} - @canEdit={{and this.node (not this.currentUserIsReadOnly)}} + @canEdit={{this.canEdit}} disabled={{not this.node}} ...attributes /> diff --git a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/mapper/template.hbs b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/mapper/template.hbs index f8df6d26e4a..f8d16f38033 100644 --- a/lib/osf-components/addon/components/registries/schema-block-renderer/editable/mapper/template.hbs +++ b/lib/osf-components/addon/components/registries/schema-block-renderer/editable/mapper/template.hbs @@ -53,6 +53,7 @@ 'registries/schema-block-renderer/editable/files' changeset=@changeset draftRegistration=@draftRegistration + revision=@revision onInput=@onInput ) )}} diff --git a/lib/registries/addon/edit-revision/page/template.hbs b/lib/registries/addon/edit-revision/page/template.hbs index 47404713e43..5477029cf70 100644 --- a/lib/registries/addon/edit-revision/page/template.hbs +++ b/lib/registries/addon/edit-revision/page/template.hbs @@ -14,7 +14,7 @@ > {{#if navManager.currentPageManager}} ({ registration.update({ reviewActions }); }, }), + withFiles: trait({ + afterCreate(registration, server) { + const count = faker.random.number({ min: 1, max: 5 }); + const osfstorage = server.create('file-provider', { target: registration }); + const files = server.createList('file', count, { target: registration }); + osfstorage.rootFolder.update({ files }); + }, + }), }); declare module 'ember-cli-mirage/types/registries/model' { diff --git a/mirage/serializers/registration.ts b/mirage/serializers/registration.ts index e4a48713240..2c6242f2341 100644 --- a/mirage/serializers/registration.ts +++ b/mirage/serializers/registration.ts @@ -139,6 +139,14 @@ export default class RegistrationSerializer extends ApplicationSerializer | ModelInstance; if (this.request.url.includes('draft_nodes')) { node = schema.draftNodes.find(parentID); + } else if (this.request.url.includes('registrations')) { + node = schema.registrations.find(parentID); } else { node = schema.nodes.find(parentID); } diff --git a/tests/integration/components/files-widget/component-test.ts b/tests/integration/components/files-widget/component-test.ts index b94d9921e41..9048085c4a2 100644 --- a/tests/integration/components/files-widget/component-test.ts +++ b/tests/integration/components/files-widget/component-test.ts @@ -60,6 +60,20 @@ module('Integration | Component | files-widget', hooks => { assert.dom('[data-test-file-row]').exists({ count }); }); + test('it renders non-editable view for revision', async function(this: ThisTestContext, assert) { + const mirageRegistration = server.create('registration', 'withFiles'); + const registration = await this.store.findRecord('registration', mirageRegistration.id); + this.set('registration', registration); + const [osfstorage] = mirageRegistration.files.models; + const count = osfstorage.rootFolder.files.models.length; + await render(hbs``); + assert.dom('[data-test-delete-current-folder]').doesNotExist(); + assert.dom('[data-test-delete-file]').doesNotExist(); + assert.dom('[data-test-files-menu-trigger]').doesNotExist(); + assert.dom('[data-test-file-browser-list]').isVisible(); + assert.dom('[data-test-file-row]').exists({ count}); + }); + test('can sort files by name and date', async function(this: ThisTestContext, assert) { const mirageNode = server.create('node', { currentUserPermissions: Object.values(Permission) });