Add approval creation things
This commit is contained in:
@@ -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;
|
||||
};
|
||||
29
server/views/artifact-version-approval-form.pug
Normal file
29
server/views/artifact-version-approval-form.pug
Normal file
@@ -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
|
||||
37
server/views/artifact-version-approval.pug
Normal file
37
server/views/artifact-version-approval.pug
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user