Skip to content

Commit

Permalink
Add support for signed/published-resource contents in files
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonkey committed Apr 12, 2024
1 parent 43e33d6 commit 5aa056e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-queens-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend-gelinkt-notuleren": patch
---

Add support for signed-resources and published-resources which have their content in files instead of directly as text
1 change: 1 addition & 0 deletions app/controllers/meetings/publish/uittreksels/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default class MeetingsPublishUittrekselsShowController extends Controller
@action
async refreshRoute() {
await this.router.refresh();
this.error = undefined;
}

signDocumentTask = task(async () => {
Expand Down
21 changes: 15 additions & 6 deletions app/models/published-resource.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default class PublishedResourceModel extends Model {
/** Optional, content might be in .file instead **/
@attr content;
@attr hashValue;
@attr('datetime') createdOn;
@attr submissionStatus;

@belongsTo('blockchain-status', { inverse: null }) status;
@belongsTo('gebruiker', { inverse: null }) gebruiker;
@belongsTo('agenda', { inverse: 'publishedResource' }) agenda;
@belongsTo('versioned-besluiten-lijst', { inverse: 'publishedResource' })
@belongsTo('blockchain-status', { async: true, inverse: null }) status;
@belongsTo('gebruiker', { async: true, inverse: null }) gebruiker;
@belongsTo('agenda', { async: true, inverse: 'publishedResource' }) agenda;
@belongsTo('versioned-besluiten-lijst', {
async: true,
inverse: 'publishedResource',
})
versionedBesluitenLijst;
@belongsTo('versioned-behandeling', { inverse: 'publishedResource' })
@belongsTo('versioned-behandeling', {
async: true,
inverse: 'publishedResource',
})
versionedBehandeling;
@belongsTo('versioned-notulen', { inverse: 'publishedResource' })
@belongsTo('versioned-notulen', { async: true, inverse: 'publishedResource' })
versionedNotulen;
/** Optional, content might be in .content instead **/
@belongsTo('file', { async: true, inverse: null }) file;
}
21 changes: 15 additions & 6 deletions app/models/signed-resource.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default class SignedResourceModel extends Model {
/** Optional, content might be in .file instead **/
@attr content;
@attr hashValue;
@attr('boolean', { defaultValue: false }) deleted;
@attr('datetime') createdOn;

@belongsTo('blockchain-status', { inverse: null }) status;
@belongsTo('gebruiker', { inverse: null }) gebruiker;
@belongsTo('agenda', { inverse: 'signedResources' }) agenda;
@belongsTo('versioned-besluiten-lijst', { inverse: 'signedResources' })
@belongsTo('blockchain-status', { async: true, inverse: null }) status;
@belongsTo('gebruiker', { async: true, inverse: null }) gebruiker;
@belongsTo('agenda', { async: true, inverse: 'signedResources' }) agenda;
@belongsTo('versioned-besluiten-lijst', {
async: true,
inverse: 'signedResources',
})
versionedBesluitenLijst;
@belongsTo('versioned-behandeling', { inverse: 'signedResources' })
@belongsTo('versioned-behandeling', {
async: true,
inverse: 'signedResources',
})
versionedBehandeling;
@belongsTo('versioned-notulen', { inverse: 'signedResources' })
@belongsTo('versioned-notulen', { async: true, inverse: 'signedResources' })
versionedNotulen;
/** Optional, content might be in .content instead **/
@belongsTo('file', { async: true, inverse: null }) file;
}
7 changes: 6 additions & 1 deletion app/routes/meetings/publish/publication-actions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export default class MeetingsPublishPublicationActionsDetailRoute extends Route
},
);
const signedResource = await log.signedResource;
if (signedResource) {
if (signedResource?.content) {
return signedResource.content;
} else if (signedResource?.file) {
const fileMeta = await signedResource.file;
const fileContent =
fileMeta && (await (await fetch(fileMeta.downloadLink)).text());
return fileContent;
} else {
const publishedResource = await log.publishedResource;
return publishedResource.content;
Expand Down
4 changes: 2 additions & 2 deletions app/routes/meetings/publish/uittreksels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class MeetingsPublishUittrekselsRoute extends Route {
query['filter[titel]'] = params.title;
}
const result = await this.store.query('agendapunt', query);
const agendapoints = result.toArray();
const agendapoints = result.slice();
const agendapointsToDisplay = [];
agendapointsToDisplay.meta = result.meta;

Expand All @@ -48,7 +48,7 @@ export default class MeetingsPublishUittrekselsRoute extends Route {
'filter[:or:][deleted]': false,
'filter[:or:][:has-no:deleted]': 'yes',
})
).toArray()[0];
)[0];
agendapointsToDisplay.push({
titel: agendapoint.titel,
behandeling: agendapoint.behandeling,
Expand Down
2 changes: 1 addition & 1 deletion app/routes/meetings/publish/uittreksels/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class MeetingsPublishUittrekselsShowRoute extends Route {
versionedTreatment,
meeting,
signedResources: signedResources.toArray(),
publishedResource: publishedResource.firstObject,
publishedResource: publishedResource[0],
// if a versionedTreatment exists, that means some signature or publication
// has happened, which means that there are no errors, so we can safely do this
validationErrors: [],
Expand Down
4 changes: 2 additions & 2 deletions app/templates/meetings/publish/uittreksels/show.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AuAlert @icon="cross" @sitle={{t "publish.excerpt-error-message"}} @skin="error" @size="small">
<code>{{this.error}}</code>
</AuAlert>
<AuButton {{on "click" (perform this.loadExtract)}}>{{t "publish.retry"}}</AuButton>
<AuButton {{on "click" this.refreshRoute}}>{{t "publish.retry"}}</AuButton>
{{else}}
<div class="au-u-margin-bottom-small au-u-hide-on-print">
<AuLink @route="meetings.publish.uittreksels" @skin="secondary" @icon="arrow-left" @iconAlignment="left">{{t
Expand Down Expand Up @@ -186,4 +186,4 @@
@mockDocument={{this.previewDocument}}
@confirm={{perform this.publishDocumentTask}}
@cancel={{this.closePublishingModal}} />
{{/if}}
{{/if}}

0 comments on commit 5aa056e

Please sign in to comment.