From 81c23328cc0fea41c216171e73d2c4942d74be15 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sun, 16 Jan 2022 04:10:24 +0200 Subject: [PATCH] Add approval creation things --- server/router/versions/index.js | 208 ++++++++++++++++++ .../views/artifact-version-approval-form.pug | 29 +++ server/views/artifact-version-approval.pug | 37 ++++ server/views/artifact-version.pug | 9 + 4 files changed, 283 insertions(+) create mode 100644 server/views/artifact-version-approval-form.pug create mode 100644 server/views/artifact-version-approval.pug diff --git a/server/router/versions/index.js b/server/router/versions/index.js index e16754a..b08fbd1 100644 --- a/server/router/versions/index.js +++ b/server/router/versions/index.js @@ -53,6 +53,9 @@ module.exports = function (options) { forkedFromId: null }, required: false + }, + { + association: db.ArtifactVersion.ArtifactVersionApproval } ] }).then(artifactVersion => { @@ -379,5 +382,210 @@ module.exports = function (options) { }) }) + router.route('/:id/approval') + .get(function(request, response, next) { + db.ArtifactVersion.findByPk(request.params.id, { + include: [ + { + association: db.ArtifactVersion.Artifact, + // required: true, + include: [ + { + association: db.Artifact.ArtifactApproval + }, + { + association: db.Artifact.Owner, + // required: false, + include: [ + { + association: db.Owner.OwnerEntities, + // required: true, + include: [ + { + association: db.OwnerEntity.Entity, + // required: false, + include: [ + { + association: db.Entity.EntityUsers, + required: false, + where: { + userId: request.user?.id ?? null + } + } + ] + } + ] + } + ] + } + ] + }, + { + association: db.ArtifactVersion.Chapters + }, + { + association: db.ArtifactVersion.TranslationArtifactVersions, + where: { + backTranslationFromId: null, + forkedFromId: null + }, + required: false + }, + { + association: db.ArtifactVersion.ArtifactVersionApproval, + required:true + } + ] + }).then(artifactVersion => { + if (artifactVersion) { + response.display("artifact-version-approval", { + user: request.user, + pageTitle: "Artifact - Mantra", + artifactVersion: artifactVersion + }) + } else { + next() + } + }).catch(error => { + next(error) + }) + }) + + + router.route('/:id/approval/add') + .get(function(request, response, next) { + db.ArtifactVersion.findByPk(request.params.id, { + include: [ + { + association: db.ArtifactVersion.Artifact, + required: true, + include: [ + { + association: db.Artifact.ArtifactApproval, + }, + { + association: db.Artifact.Owner, + required: true, + include: [ + { + association: db.Owner.OwnerEntities, + required: true, + include: [ + { + association: db.OwnerEntity.Entity, + required: true, + include: [ + { + association: db.Entity.EntityUsers, + required: true, + where: { + userId: request.user?.id ?? null + } + } + ] + } + ] + } + ] + } + ] + }, + { + association: db.ArtifactVersion.Chapters + } + ] + }).then(artifactVersion => { + if (artifactVersion) { + if (artifactVersion.artifactVersionApproval) { + return response.redirect(`/v/${artifactVersion.id}/approval`) + } + response.display("artifact-version-approval-form", { + user: request.user, + pageTitle: "Approval - Mantra", + artifactVersion: artifactVersion, + artifactVersionApproval: { + name: artifactVersion.artifact.artifactApproval?.name, + description: artifactVersion.artifact.artifactApproval?.description, + conditions: artifactVersion.artifact.artifactApproval?.conditions, + satoshis: artifactVersion.artifact.artifactApproval?.satoshis, + approvedAt: artifactVersion.artifact.artifactApproval?.approvedAt + } + }) + } else { + next() + } + + }).catch(error => { + next(error) + }) + }) + .post(function(request, response, next) { + db.ArtifactVersion.findByPk(request.params.id, { + include: [ + { + association: db.ArtifactVersion.Artifact, + required: true, + include: [ + { + association: db.Artifact.ArtifactApproval, + }, + { + association: db.Artifact.Owner, + required: true, + include: [ + { + association: db.Owner.OwnerEntities, + required: true, + include: [ + { + association: db.OwnerEntity.Entity, + required: true, + include: [ + { + association: db.Entity.EntityUsers, + required: true, + where: { + userId: request.user?.id ?? null + } + } + ] + } + ] + } + ] + } + ] + }, + { + association: db.ArtifactVersion.Chapters + } + ] + }).then(async (artifactVersion) => { + if (artifactVersion) { + if (artifactVersion.artifactVersionApproval == null) { + // Create artifactVersionApproval + const satoshis = Number(request.body.satoshis) ? Number(request.body.satoshis) : null + await db.ArtifactVersionApproval.create({ + name: request.body.name, + type: 'umbrella', + artifactVersionId: artifactVersion.id, + description: request.body.description, + conditions: request.body.conditions, + satoshis: satoshis, + creatorId: request.user.id, + approvedAt: request.body.isApproved == 'on' ? new Date() : null + }) + } + + response.redirect(`/v/${artifactVersion.id}/approval`) + } else { + next() + } + + }).catch(error => { + next(error) + }) + }) + return router; }; \ No newline at end of file diff --git a/server/views/artifact-version-approval-form.pug b/server/views/artifact-version-approval-form.pug new file mode 100644 index 0000000..c205c31 --- /dev/null +++ b/server/views/artifact-version-approval-form.pug @@ -0,0 +1,29 @@ +extend templates/layout.pug + +block content + .container + .center + h1 License Approval for #{artifactVersion.artifact.name} - #{artifactVersion.tag} + + .row + .col.s12 + form.row(action=`/v/${artifactVersion.id}/approval/add`, method="post") + .col.s12.input-field + input#name(type="text", name="name", value=artifactVersionApproval.name, placeholder="Creative Commons/Copyright agreement") + label(for="name") Name of license/approval for the content to be translated + .col.s12.input-field + input#conditions(type="text", name="conditions", value=artifactVersionApproval.conditions, placeholder="The following dictate how the produced translations shall be treated") + label(for="conditions") Summary of the conditions required to get approval (optional) + .col.s12.input-field + textarea#description.materialize-textarea(name="description", placeholder="Describe the approval being given in sufficient detail.")= artifactVersionApproval.description + label(for="description") Detailed description of license/approval + .col.s12.input-field + input(id="satoshis",type="number", name="satoshis", placeholder="100000 satoshis", step=1, min=1, max=2100000000000000) + label(for="satoshis") Satoshis required to unlock the approval + .col.s12.input-field + p + label + input#isApproved(type="checkbox", name="isApproved", checked=artifactVersionApproval.approvedAt!=null) + span Approval already granted + .col.s12 + button.btn.black(type="submit") add approval \ No newline at end of file diff --git a/server/views/artifact-version-approval.pug b/server/views/artifact-version-approval.pug new file mode 100644 index 0000000..8eb9545 --- /dev/null +++ b/server/views/artifact-version-approval.pug @@ -0,0 +1,37 @@ +extend templates/layout.pug + +block content + - + const isOwnedByUser = artifactVersion.artifact.owner.ownerEntities.some(ownerEntity => { + return ownerEntity.entity.entityUsers.some(entityUser => { + return entityUser.userId == user?.id + }) + }) + .container + .center + h1 #{artifactVersion.artifact.name} + if artifactVersion.artifact.accessibility == "private" + i.right.medium.material-icons lock + + h2 #{artifactVersion.tag} + p.flow-text + each ownerEntity, index in artifactVersion.artifact.owner.ownerEntities + small + if index > 0 + span and + span.chip #{ownerEntity.entity.name} + + .row + .col.s12 + if artifactVersion.artifactVersionApproval + p.flow-text Approval: #{artifactVersion.artifactVersionApproval.name} + p.flow-text= artifactVersion.artifactVersionApproval.conditions + p.flow-text= artifactVersion.artifactVersionApproval.description + if artifactVersion.artifactVersionApproval.approvedAt + p.flow-text.green-text(title=artifactVersion.artifactVersionApproval.approvedAt.toLocaleString()) approval has already been given to translate the work. + else + p.flow-text Pending approval + else + p.flow-text No digital rights approval information has been provided for this content. + if isOwnedByUser + a.btn.black(href=`/v/${artifactVersion.id}/approval/add`) add approval information diff --git a/server/views/artifact-version.pug b/server/views/artifact-version.pug index bfcfca7..c254352 100644 --- a/server/views/artifact-version.pug +++ b/server/views/artifact-version.pug @@ -28,6 +28,15 @@ block content .col.s12 a.btn.black(href=`/v/${artifactVersion.id}/campaign/create`) funding campaign + .row + .col.s12 + if artifactVersion.artifactVersionApproval + p.flow-text Approval: + a(href=`/v/${artifactVersion.id}/approval`) #{artifactVersion.artifactVersionApproval.name} + else + p.flow-text No digital rights approval information has been provided for this content. + if isOwnedByUser + a.btn.black(href=`/v/${artifactVersion.id}/approval/add`) add approval information if isOwnedByUser .divider