Add user ID tracking for versions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 12:10:52 -06:00
parent 3aab56b5ac
commit 6469beb341
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
5 changed files with 20 additions and 17 deletions

View File

@ -72,6 +72,7 @@ class ExportController extends Controller {
async export_subtree_as_html(page, user) { async export_subtree_as_html(page, user) {
const flat_tree = [] const flat_tree = []
await page.version_save('Exported page as HTML', user.id)
const add_to_tree = async (page, level = 0) => { const add_to_tree = async (page, level = 0) => {
if ( await page.is_accessible_by(user, 'view') ) { if ( await page.is_accessible_by(user, 'view') ) {

View File

@ -258,7 +258,7 @@ class OfflineController extends Controller {
if ( online_page ) { if ( online_page ) {
// if it existed in the online page, delete it // if it existed in the online page, delete it
online_page.NodeIds = online_page.NodeIds.filter(x => x !== rec.UUID) online_page.NodeIds = online_page.NodeIds.filter(x => x !== rec.UUID)
await online_page.version_save('Updated from offline sync') await online_page.version_save('Updated from offline sync', req.user.id)
} }
await existing_node.delete() await existing_node.delete()
@ -322,7 +322,7 @@ class OfflineController extends Controller {
} }
} }
await online_page.version_save('Updated page from online save') await online_page.version_save('Updated page from online save', req.user.id)
} }
// assuming the pages were created first, we should never have a case // assuming the pages were created first, we should never have a case

View File

@ -70,7 +70,7 @@ class Page extends Controller {
page.UpdatedAt = new Date page.UpdatedAt = new Date
page.UpdateUserId = req.user._id page.UpdateUserId = req.user._id
await page.version_save(save_message) await page.version_save(save_message, req.user.id)
return res.api(page) return res.api(page)
} }
@ -140,7 +140,7 @@ class Page extends Controller {
await node_obj.save() await node_obj.save()
page.NodeIds.push(node_obj.UUID); page.NodeIds.push(node_obj.UUID);
await page.version_save(`Added ${node_obj.Type.split('_')[0]} node to page`); await page.version_save(`Added ${node_obj.Type.split('_')[0]} node to page`, req.user.id);
return res.api(node_obj) return res.api(node_obj)
} }
} }
@ -204,7 +204,7 @@ class Page extends Controller {
} }
page.NodeIds = updated_nodes.map(x => x.UUID) page.NodeIds = updated_nodes.map(x => x.UUID)
await page.version_save('Bulk-updated nodes on page') await page.version_save('Bulk-updated nodes on page', req.user.id)
res.api(updated_nodes) res.api(updated_nodes)
} }
@ -230,10 +230,10 @@ class Page extends Controller {
} }
} }
await new_page.version_save('Created new top-level page') await new_page.version_save('Created new top-level page', req.user.id)
root_page.ChildPageIds.push(new_page.UUID) root_page.ChildPageIds.push(new_page.UUID)
await root_page.version_save(`Added new top-level page "${new_page.Name}"`) await root_page.version_save(`Added new top-level page "${new_page.Name}"`, req.user.id)
req.user.allow(`page:${new_page.UUID}`) req.user.allow(`page:${new_page.UUID}`)
await req.user.save() await req.user.save()
@ -251,7 +251,7 @@ class Page extends Controller {
await starter_node.save() await starter_node.save()
new_page.NodeIds.push(starter_node.UUID) new_page.NodeIds.push(starter_node.UUID)
await new_page.version_save('Added paragraph node to page') await new_page.version_save('Added paragraph node to page', req.user.id)
} }
return res.api(new_page) return res.api(new_page)
@ -289,10 +289,10 @@ class Page extends Controller {
} }
} }
await new_page.version_save(`Created new page as child of "${parent.Name}"`) await new_page.version_save(`Created new page as child of "${parent.Name}"`, req.user.id)
parent.ChildPageIds.push(new_page.UUID) parent.ChildPageIds.push(new_page.UUID)
await parent.version_save(`Created new child page "${new_page.Name}"`) await parent.version_save(`Created new child page "${new_page.Name}"`, req.user.id)
req.user.allow(`page:${new_page.UUID}`) req.user.allow(`page:${new_page.UUID}`)
await req.user.save() await req.user.save()
@ -310,7 +310,7 @@ class Page extends Controller {
await starter_node.save() await starter_node.save()
new_page.NodeIds.push(starter_node.UUID) new_page.NodeIds.push(starter_node.UUID)
await new_page.version_save('Added paragraph node to page') await new_page.version_save('Added paragraph node to page', req.user.id)
} }
return res.api(new_page) return res.api(new_page)
@ -329,7 +329,7 @@ class Page extends Controller {
page.Active = false page.Active = false
page.DeletedAt = new Date page.DeletedAt = new Date
await page.version_save('Deleted page') await page.version_save('Deleted page', req.user.id)
return res.api({}) return res.api({})
} }
} }

View File

@ -7,15 +7,16 @@ class VersionedModel extends Model {
version_archive: [Object], version_archive: [Object],
version_num: { type: Number, default: 1 }, version_num: { type: Number, default: 1 },
version_create_date: { type: Date, default: () => new Date }, version_create_date: { type: Date, default: () => new Date },
version_user_id: String,
} }
} }
async version_save(message = undefined) { async version_save(message = undefined, user_id = undefined) {
await this.new_version(message) await this.new_version(message, user_id)
return this.save() return this.save()
} }
async new_version(message = undefined) { async new_version(message = undefined, user_id = undefined) {
const version_data = await this.cast_to_version_data() const version_data = await this.cast_to_version_data()
version_data.version_UUID = uuid() version_data.version_UUID = uuid()
version_data.version_message = message version_data.version_message = message
@ -26,6 +27,7 @@ class VersionedModel extends Model {
this.version_num += 1 this.version_num += 1
this.version_archive.push(version_data) this.version_archive.push(version_data)
this.version_create_date = new Date() this.version_create_date = new Date()
this.version_user_id = user_id
} }
async cast_to_version_data() { async cast_to_version_data() {

View File

@ -203,7 +203,7 @@ class Page extends VersionedModel {
this[`shared_users_${level}`].push(user._id) this[`shared_users_${level}`].push(user._id)
// TODO replace user.uid with name of user when we support that // TODO replace user.uid with name of user when we support that
await this.version_save(`Shared with ${user.uid} (${level} access)`) await this.version_save(`Shared with ${user.uid} (${level} access)`, user.id)
await user.save() await user.save()
} }
@ -219,7 +219,7 @@ class Page extends VersionedModel {
this.shared_users_update = this.shared_users_update.filter(x => String(x) !== user.id) this.shared_users_update = this.shared_users_update.filter(x => String(x) !== user.id)
this.shared_users_manage = this.shared_users_manage.filter(x => String(x) !== user.id) this.shared_users_manage = this.shared_users_manage.filter(x => String(x) !== user.id)
await this.version_save(`Unshared with ${user.uid}`) await this.version_save(`Unshared with ${user.uid}`, user.id)
await user.save() await user.save()
} }