Track file group versioning & include version num in node versions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 12:51:56 -06:00
parent a584631b75
commit 3bef5f3423
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 12 additions and 4 deletions

View File

@ -39,7 +39,7 @@ class File extends Controller {
}
}
await group.save()
await group.version_save(`Added to page "${page.Name}"`, req.user.id)
req.user.allow(`files:${group.UUID}`)
await req.user.save()
@ -85,11 +85,12 @@ class File extends Controller {
if ( !group ) return res.status(404).message('Invalid file group.').api({})
// if ( !group.accessible_by(req.user) ) return req.security.deny()
let file_name = ''
if ( req.uploads.uploaded_file ) {
group.FileIds.push(req.uploads.uploaded_file.id)
}
await group.save()
await group.version_save(`Added file${file_name ? ' "'+file_name+'"' : ''}`, req.user.id)
return res.redirect(req.body.redirectTo ? req.body.redirectTo : '/')
}

View File

@ -1,4 +1,4 @@
const Model = require('flitter-orm/src/model/Model')
const VersionedModel = require('../VersionedModel')
const uuid = require('uuid/v4')
/*
@ -6,10 +6,11 @@ const uuid = require('uuid/v4')
* -------------------------------------------------------------
* Put some description here!
*/
class FileGroup extends Model {
class FileGroup extends VersionedModel {
static get schema() {
// Return a flitter-orm schema here.
return {
...super.schema,
NodeId: String,
PageId: String,
FileIds: [String],

View File

@ -69,6 +69,12 @@ class Node extends VersionedModel {
if ( code ) {
data.associated_type_version_num = code.version_num
}
} else if ( this.Type === 'file_ref' && this.Value?.Value ) {
const FileGroup = this.models.get('api:FileGroup')
const group = await FileGroup.findOne({ UUID: this.Value?.Value })
if ( group ) {
data.associated_type_version_num = group.version_num
}
}
return data