| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const NoteRevision = require('../entities/note_revision'); | 
					
						
							|  |  |  | const dateUtils = require('../services/date_utils'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Note} note | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  | function protectNoteRevisions(note) { | 
					
						
							|  |  |  |     for (const revision of note.getRevisions()) { | 
					
						
							| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  |         if (note.isProtected !== revision.isProtected) { | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |             const content = revision.getContent(); | 
					
						
							| 
									
										
										
										
											2019-11-09 13:01:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  |             revision.isProtected = note.isProtected; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-09 13:01:05 +01:00
										 |  |  |             // this will force de/encryption
 | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |             revision.setContent(content); | 
					
						
							| 
									
										
										
										
											2019-11-09 13:01:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |             revision.save(); | 
					
						
							| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Note} note | 
					
						
							|  |  |  |  * @return {NoteRevision} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  | function createNoteRevision(note) { | 
					
						
							|  |  |  |     if (note.hasLabel("disableVersioning")) { | 
					
						
							| 
									
										
										
										
											2019-12-02 20:21:52 +01:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |     const noteRevision = new NoteRevision({ | 
					
						
							| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  |         noteId: note.noteId, | 
					
						
							|  |  |  |         // title and text should be decrypted now
 | 
					
						
							|  |  |  |         title: note.title, | 
					
						
							|  |  |  |         type: note.type, | 
					
						
							|  |  |  |         mime: note.mime, | 
					
						
							|  |  |  |         isProtected: false, // will be fixed in the protectNoteRevisions() call
 | 
					
						
							|  |  |  |         utcDateLastEdited: note.utcDateModified, | 
					
						
							|  |  |  |         utcDateCreated: dateUtils.utcNowDateTime(), | 
					
						
							|  |  |  |         utcDateModified: dateUtils.utcNowDateTime(), | 
					
						
							|  |  |  |         dateLastEdited: note.dateModified, | 
					
						
							|  |  |  |         dateCreated: dateUtils.localNowDateTime() | 
					
						
							|  |  |  |     }).save(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |     noteRevision.setContent(note.getContent()); | 
					
						
							| 
									
										
										
										
											2019-11-09 11:58:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return noteRevision; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     protectNoteRevisions, | 
					
						
							|  |  |  |     createNoteRevision | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  | }; |