-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for delete signatures #101
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d3525b
support for delete signatures
lagartoverde 3e99a89
fix besluitenlijst
lagartoverde 7c77218
fix typo in besluitenlijst versioned resource fetching
lagartoverde a9c5157
json:api compliant endpoint to create signed resources
nvdk 2799b52
Merge branch 'feature/signed-resource-json-api-endpoint' into feature…
abeforgit e9290f6
feat(signing): make the signing endpoint json-api compliant
abeforgit b2ab736
fix(publication): return URI directly from ensure method
abeforgit 2c9dd8b
fix(utils): remove console.log statement
abeforgit 3561bb2
Merge branch 'master' into feature/delete-signatures
abeforgit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
// @ts-ignore | ||
import { prefixMap } from '../support/prefixes'; | ||
import { query, sparqlEscapeUri } from 'mu'; | ||
|
||
export default class SignedResource { | ||
static async findURI(uri) { | ||
const queryString = ` | ||
${prefixMap.get('mu').toSparqlString()} | ||
${prefixMap.get('sign').toSparqlString()} | ||
${prefixMap.get('dct').toSparqlString()} | ||
${prefixMap.get('publicationStatus').toSparqlString()} | ||
${prefixMap.get('ext').toSparqlString()} | ||
SELECT DISTINCT * | ||
WHERE { | ||
BIND(${sparqlEscapeUri(uri)} as ?uri) | ||
?uri a sign:SignedResource; | ||
mu:uuid ?uuid; | ||
sign:text ?html; | ||
sign:hashValue ?hashValue; | ||
sign:hashAlgorithm ?hashAlgorithm; | ||
dct:created ?created; | ||
sign:signatoryRoles ?signatoryRole. | ||
|
||
?uri sign:status ?blockchainStatus; | ||
sign:signatory ?signatory. | ||
|
||
?blockchainStatus mu:uuid ?blockchainStatusUuid. | ||
?signatory mu:uuid ?signatoryUuid. | ||
|
||
OPTIONAL { ?uri ext:deleted ?deleted. } | ||
OPTIONAL { | ||
?uri ext:signsAgenda ?agenda. | ||
?agenda mu:uuid ?agendaUuid. | ||
} | ||
OPTIONAL { | ||
?uri ext:signsBesluitenlijst ?versionedBesluitenLijst. | ||
?versionedBesluitenLijst mu:uuid ?versionedBesluitenLijstUuid. | ||
} | ||
OPTIONAL { | ||
?uri ext:signsNotulen ?versionedNotulen. | ||
?versionedNotulen mu:uuid ?versionedNotulenUuid. | ||
} | ||
OPTIONAL { | ||
?uri ext:signsBehandeling ?versionedBehandeling. | ||
?versionedBehandeling mu:uuid ?versionedBehandelingUuid. | ||
} | ||
} ORDER BY DESC (?created) | ||
`; | ||
try { | ||
const result = await query(queryString); | ||
if (result.results.bindings.length === 1) { | ||
const sr = SignedResource.fromBinding(result.results.bindings[0]); | ||
return sr; | ||
} else if (result.results.bindings.length > 1) { | ||
console.warn( | ||
`Found ${result.results.bindings.length} SignedResources for one URI, this is unexpected. Returning the newest one` | ||
); | ||
// console.warn("bindings:", result.results.bindings); | ||
const sr = SignedResource.fromBinding(result.results.bindings[0]); | ||
return sr; | ||
} else { | ||
throw `did not find signed resource with uri ${uri}`; | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
throw `failed to retrieve signed resource with uri ${uri}`; | ||
} | ||
} | ||
|
||
static fromBinding({ | ||
uri, | ||
uuid, | ||
html, | ||
hashValue, | ||
hashAlgorithm, | ||
created, | ||
signatoryRole, | ||
deleted, | ||
blockchainStatus, | ||
signatory, | ||
blockchainStatusUuid, | ||
signatoryUuid, | ||
agenda, | ||
versionedBesluitenLijst, | ||
versionedNotulen, | ||
versionedBehandeling, | ||
agendaUuid, | ||
versionedBesluitenLijstUuid, | ||
versionedNotulenUuid, | ||
versionedBehandelingUuid, | ||
}) { | ||
return new SignedResource({ | ||
uri: uri.value, | ||
uuid: uuid.value, | ||
html: html.value, | ||
hashValue: hashValue.value, | ||
hashAlgorithm: hashAlgorithm.value, | ||
created: created.value, | ||
signatoryRole: signatoryRole.value, | ||
deleted: deleted?.value, | ||
blockchainStatus: blockchainStatus.value, | ||
signatory: signatory.value, | ||
blockchainStatusUuid: blockchainStatusUuid.value, | ||
signatoryUuid: signatoryUuid.value, | ||
agenda: agenda?.value, | ||
versionedBesluitenLijst: versionedBesluitenLijst?.value, | ||
versionedNotulen: versionedNotulen?.value, | ||
versionedBehandeling: versionedBehandeling?.value, | ||
agendaUuid: agendaUuid?.value, | ||
versionedBesluitenLijstUuid: versionedBesluitenLijstUuid?.value, | ||
versionedNotulenUuid: versionedNotulenUuid?.value, | ||
versionedBehandelingUuid: versionedBehandelingUuid?.value, | ||
}); | ||
} | ||
|
||
constructor({ | ||
uri, | ||
uuid, | ||
html, | ||
hashValue, | ||
hashAlgorithm, | ||
created, | ||
signatoryRole, | ||
deleted, | ||
blockchainStatus, | ||
signatory, | ||
blockchainStatusUuid, | ||
signatoryUuid, | ||
agenda, | ||
versionedBesluitenLijst, | ||
versionedNotulen, | ||
versionedBehandeling, | ||
agendaUuid, | ||
versionedBesluitenLijstUuid, | ||
versionedNotulenUuid, | ||
versionedBehandelingUuid, | ||
}) { | ||
this.uuid = uuid; | ||
this.uri = uri; | ||
this.html = html; | ||
this.signatory = signatory; | ||
this.created = created; | ||
this.signatoryRole = signatoryRole; | ||
this.hashAlgorithm = hashAlgorithm; | ||
this.hashValue = hashValue; | ||
this.deleted = deleted; | ||
this.blockchainStatus = blockchainStatus; | ||
this.blockchainStatusUuid = blockchainStatusUuid; | ||
this.signatoryUuid = signatoryUuid; | ||
this.agenda = agenda; | ||
this.versionedBesluitenLijst = versionedBesluitenLijst; | ||
this.versionedNotulen = versionedNotulen; | ||
this.versionedBehandeling = versionedBehandeling; | ||
this.agendaUuid = agendaUuid; | ||
this.versionedBesluitenLijstUuid = versionedBesluitenLijstUuid; | ||
this.versionedNotulenUuid = versionedNotulenUuid; | ||
this.versionedBehandelingUuid = versionedBehandelingUuid; | ||
} | ||
|
||
/** | ||
* Convert into a json-api compliant model according to the mu-cl-resource config | ||
*/ | ||
toMuResourceModel() { | ||
// required relationships | ||
const relationships = { | ||
'blockchain-status': { | ||
data: { | ||
type: 'blockchain-statuses', | ||
id: this.blockchainStatusUuid, | ||
}, | ||
}, | ||
gebruiker: { | ||
data: { type: 'gebruikers', id: this.signatoryUuid }, | ||
}, | ||
}; | ||
// optional relationships | ||
if (this.agendaUuid) { | ||
relationships.agenda = { | ||
data: { | ||
type: 'agendas', | ||
id: this.agendaUuid, | ||
}, | ||
}; | ||
} | ||
if (this.versionedBesluitenLijstUuid) { | ||
relationships['versioned-besluiten-lijst'] = { | ||
data: { | ||
type: 'versioned-besluiten-lijsten', | ||
id: this.versionedBesluitenLijstUuid, | ||
}, | ||
}; | ||
} | ||
if (this.versionedNotulenUuid) { | ||
relationships['versioned-notulen'] = { | ||
data: { | ||
type: 'versioned-notulen', | ||
id: this.versionedNotulenUuid, | ||
}, | ||
}; | ||
} | ||
if (this.versionedBehandelingUuid) { | ||
relationships['versioned-behandeling'] = { | ||
data: { | ||
type: 'versioned-behandelingen', | ||
id: this.versionedBehandelingUuid, | ||
}, | ||
}; | ||
} | ||
return { | ||
data: { | ||
id: this.uuid, | ||
type: 'signed-resources', | ||
attributes: { | ||
uri: this.uri, | ||
content: this.html, | ||
'hash-value': this.hashValue, | ||
'created-on': this.created, | ||
deleted: this.deleted, | ||
}, | ||
relationships, | ||
links: { | ||
self: '/signed-resources/' + this.uuid, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider blockchainStatus and uuid legacy and no longer required. little value in adding them as this hasn't been used in over 4 years.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the interest of limiting scope, OK to leave it for now and open a separate pr to clean up obsolete stuff?