@@ -268,7 +268,7 @@ const deleteNote = async (req, res) => {
268268}
269269
270270const updateNote = async ( req , res ) => {
271- if ( req . isAuthenticated ( ) ) {
271+ if ( req . isAuthenticated ( ) || config . allowAnonymousEdits ) {
272272 const noteId = await Note . parseNoteIdAsync ( req . params . noteId )
273273 try {
274274 const note = await Note . findOne ( {
@@ -292,23 +292,25 @@ const updateNote = async (req, res) => {
292292 title : Note . parseNoteTitle ( content ) ,
293293 content : content ,
294294 lastchangeAt : now ,
295- authorship : [
295+ authorship : req . isAuthenticated ( ) ? [
296296 [
297297 req . user . id ,
298298 0 ,
299299 content . length ,
300300 now ,
301301 now
302302 ]
303- ]
303+ ] : [ ]
304304 } )
305305
306306 if ( ! updated ) {
307307 logger . error ( 'Update note failed: Write note content error.' )
308308 return errorInternalError ( req , res )
309309 }
310310
311- updateHistory ( req . user . id , note . id , content )
311+ if ( req . isAuthenticated ( ) ) {
312+ updateHistory ( req . user . id , note . id , content )
313+ }
312314
313315 Revision . saveNoteRevision ( note , ( err , revision ) => {
314316 if ( err ) {
@@ -321,7 +323,7 @@ const updateNote = async (req, res) => {
321323 } )
322324 } )
323325 } catch ( err ) {
324- logger . error ( err )
326+ logger . error ( err . stack )
325327 logger . error ( 'Update note failed: Internal Error.' )
326328 return errorInternalError ( req , res )
327329 }
0 commit comments