##// END OF EJS Templates
comments-api: make edit API resilent to bad version data.
marcink -
r4443:d2ba3852 default
parent child Browse files
Show More
@@ -34,7 +34,7 b' from sqlalchemy.sql.functions import coa'
34 from rhodecode.lib import helpers as h, diffs, channelstream, hooks_utils
34 from rhodecode.lib import helpers as h, diffs, channelstream, hooks_utils
35 from rhodecode.lib import audit_logger
35 from rhodecode.lib import audit_logger
36 from rhodecode.lib.exceptions import CommentVersionMismatch
36 from rhodecode.lib.exceptions import CommentVersionMismatch
37 from rhodecode.lib.utils2 import extract_mentioned_users, safe_str
37 from rhodecode.lib.utils2 import extract_mentioned_users, safe_str, safe_int
38 from rhodecode.model import BaseModel
38 from rhodecode.model import BaseModel
39 from rhodecode.model.db import (
39 from rhodecode.model.db import (
40 ChangesetComment,
40 ChangesetComment,
@@ -504,12 +504,16 b' class CommentsModel(BaseModel):'
504 old_comment_text = comment.text
504 old_comment_text = comment.text
505 comment.text = text
505 comment.text = text
506 comment.modified_at = datetime.datetime.now()
506 comment.modified_at = datetime.datetime.now()
507 version = safe_int(version)
507
508
509 # NOTE(marcink): this returns initial comment + edits, so v2 from ui
510 # would return 3 here
508 comment_version = ChangesetCommentHistory.get_version(comment_id)
511 comment_version = ChangesetCommentHistory.get_version(comment_id)
509 if (comment_version - version) != 1:
512
513 if isinstance(version, (int, long)) and (comment_version - version) != 1:
510 log.warning(
514 log.warning(
511 'Version mismatch comment_version {} submitted {}, skipping'.format(
515 'Version mismatch comment_version {} submitted {}, skipping'.format(
512 comment_version,
516 comment_version-1, # -1 since note above
513 version
517 version
514 )
518 )
515 )
519 )
General Comments 0
You need to be logged in to leave comments. Login now