Beispiel #1
0
    def test_create(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {'text': text}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (0 inline, 1 general)'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]

        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/vcs_test_hg/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
Beispiel #2
0
    def test_delete(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {'text': text, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})

        comments = ChangesetComment.query().all()
        self.assertEqual(len(comments), 1)
        comment_id = comments[0].comment_id

        self.app.post(url(controller='changeset',
                                    action='delete_comment',
                                    repo_name=HG_REPO,
                                    comment_id=comment_id),
            params={'_method': 'delete', '_authentication_token': self.authentication_token()})

        comments = ChangesetComment.query().all()
        self.assertEqual(len(comments), 0)

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 0 comments (0 inline, 0 general)'''
        )
Beispiel #3
0
    def test_delete(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {'text': text}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)

        comments = ChangesetComment.query().all()
        self.assertEqual(len(comments), 1)
        comment_id = comments[0].comment_id

        self.app.delete(url(controller='changeset',
                                    action='delete_comment',
                                    repo_name=HG_REPO,
                                    comment_id=comment_id))

        comments = ChangesetComment.query().all()
        self.assertEqual(len(comments), 0)

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 0 comments (0 inline, 0 general)'''
        )
Beispiel #4
0
    def test_create(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {'text': text, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        self.assertEqual(response.status, '200 OK')

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (0 inline, 1 general)'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]

        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/%s/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID))
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {
            'text': text,
            'f_path': f_path,
            'line': line,
            '_authentication_token': self.authentication_token()
        }
        response = self.app.post(url(controller='changeset',
                                     action='comment',
                                     repo_name=HG_REPO,
                                     revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            url(controller='changeset',
                action='index',
                repo_name=HG_REPO,
                revision=rev))
        #test DB
        assert ChangesetComment.query().count() == 1
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (1 inline, 0 general)''')
        response.mustcontain(
            '''<div class="comments-list-chunk" '''
            '''data-f_path="vcs/web/simplevcs/views/repository.py" '''
            '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">'''
        )

        assert Notification.query().count() == 1
        assert ChangesetComment.query().count() == 1

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
        sbj = (u'/%s/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' %
               (HG_REPO, ID))
        print "%s vs %s" % (sbj, notification.subject)
        assert sbj in notification.subject
Beispiel #6
0
    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'@%s check CommentOnRevision' % TEST_USER_REGULAR_LOGIN

        params = {'text': text, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        self.assertEqual(response.status, '200 OK')

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (0 inline, 1 general)'''
        )

        self.assertEqual(Notification.query().count(), 2)
        users = [x.user.username for x in UserNotification.query().all()]

        # test_regular gets notification by @mention
        self.assertEqual(sorted(users), [TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN])
    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'@test_regular check CommentOnRevision'

        params = {'text': text, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (0 inline, 1 general)'''
        )

        self.assertEqual(Notification.query().count(), 2)
        users = [x.user.username for x in UserNotification.query().all()]

        # test_regular gets notification by @mention
        self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
    def test_create_status_change(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = 'general comment on changeset'

        params = {
            'text': text,
            'changeset_status': 'rejected',
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='changeset',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='changeset',
                     action='index',
                     repo_name=base.HG_REPO,
                     revision=rev))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (0 inline, 1 general)''')
        response.mustcontain(text)

        # test DB
        assert ChangesetComment.query().count() == 1

        # check status
        status = ChangesetStatusModel().get_status(repo=base.HG_REPO,
                                                   revision=rev)
        assert status == 'rejected'
Beispiel #9
0
    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'@test_regular check CommentOnRevision'

        params = {'text':text}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        # test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (0 inline, 1 general)'''
        )

        self.assertEqual(Notification.query().count(), 2)
        users = [x.user.username for x in UserNotification.query().all()]

        # test_regular gets notification by @mention
        self.assertEqual(sorted(users), [u'test_admin', u'test_regular'])
    def test_create(self):
        self.log_user()
        pr_id = self._create_pr()

        text = 'general comment on pullrequest'
        params = {
            'text': text,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='pullrequests',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          pull_request_id=pr_id),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='pullrequests',
                     action='show',
                     repo_name=base.HG_REPO,
                     pull_request_id=pr_id,
                     extra=''))
        # PRs currently always have an initial 'Under Review' status change
        # that counts as a general comment, hence '2' in the test below. That
        # could be counted as a misfeature, to be reworked later.
        response.mustcontain('''<div class="comments-number">'''
                             ''' 2 comments (0 inline, 2 general)''')
        response.mustcontain(text)

        # test DB
        assert ChangesetComment.query().count() == 2
    def test_create_with_mention(self):
        self.log_user()
        pr_id = self._create_pr()

        text = '@%s check CommentOnRevision' % base.TEST_USER_REGULAR_LOGIN
        params = {
            'text': text,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='pullrequests',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          pull_request_id=pr_id),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='pullrequests',
                     action='show',
                     repo_name=base.HG_REPO,
                     pull_request_id=pr_id,
                     extra=''))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 2 comments (0 inline, 2 general)''')
        response.mustcontain('<b>@%s</b> check CommentOnRevision' %
                             base.TEST_USER_REGULAR_LOGIN)

        # test DB
        assert ChangesetComment.query().count() == 2
    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = '@%s check CommentOnRevision' % base.TEST_USER_REGULAR_LOGIN

        params = {
            'text': text,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='changeset',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='changeset',
                     action='index',
                     repo_name=base.HG_REPO,
                     revision=rev))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (0 inline, 1 general)''')
        response.mustcontain('<b>@%s</b> check CommentOnRevision' %
                             base.TEST_USER_REGULAR_LOGIN)

        # test DB
        assert ChangesetComment.query().count() == 1
    def setUp(self):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        for x in Notification.query().all():
            Session().delete(x)
        Session().commit()
Beispiel #14
0
    def setUp(self):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        for x in Notification.query().all():
            Session().delete(x)
        Session().commit()
Beispiel #15
0
 def delete_comment(self, repo_name, comment_id):
     co = ChangesetComment.get(comment_id)
     if not co:
         raise HTTPBadRequest()
     owner = co.author.user_id == c.authuser.user_id
     repo_admin = h.HasRepoPermissionAny('repository.admin')
     if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
         ChangesetCommentsModel().delete(comment=co)
         Session().commit()
         return True
     else:
         raise HTTPForbidden()
Beispiel #16
0
 def delete_comment(self, repo_name, comment_id):
     co = ChangesetComment.get(comment_id)
     if not co:
         raise HTTPBadRequest()
     owner = co.author.user_id == c.authuser.user_id
     repo_admin = h.HasRepoPermissionAny('repository.admin')
     if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
         ChangesetCommentsModel().delete(comment=co)
         Session().commit()
         return True
     else:
         raise HTTPForbidden()
Beispiel #17
0
 def delete_comment(self, repo_name, comment_id):
     co = ChangesetComment.get_or_404(comment_id)
     if co.repo.repo_name != repo_name:
         raise HTTPNotFound()
     owner = co.author_id == request.authuser.user_id
     repo_admin = h.HasRepoPermissionLevel('admin')(repo_name)
     if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
         ChangesetCommentsModel().delete(comment=co)
         Session().commit()
         return True
     else:
         raise HTTPForbidden()
    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {'text': text, 'f_path': f_path, 'line': line, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        #test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (1 inline, 0 general)'''
        )
        response.mustcontain(
            '''<div style="display:none" class="inline-comment-placeholder" '''
            '''path="vcs/web/simplevcs/views/repository.py" '''
            '''target_id="vcswebsimplevcsviewsrepositorypy">'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/vcs_test_hg/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
    def test_delete(self):
        self.log_user()
        pr_id = self._create_pr()

        text = 'general comment on changeset to be deleted'
        params = {
            'text': text,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='pullrequests',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          pull_request_id=pr_id),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})

        comments = ChangesetComment.query().all()
        assert len(comments) == 2
        comment_id = comments[-1].comment_id

        self.app.post(base.url("pullrequest_comment_delete",
                               repo_name=base.HG_REPO,
                               comment_id=comment_id),
                      params={
                          '_session_csrf_secret_token':
                          self.session_csrf_secret_token()
                      })

        comments = ChangesetComment.query().all()
        assert len(comments) == 1

        response = self.app.get(
            base.url(controller='pullrequests',
                     action='show',
                     repo_name=base.HG_REPO,
                     pull_request_id=pr_id,
                     extra=''))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (0 inline, 1 general)''')
        response.mustcontain(no=text)
Beispiel #20
0
    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {'text': text, 'f_path': f_path, 'line': line}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params)
        # Test response...
        self.assertEqual(response.status, '302 Found')
        response.follow()

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        #test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (1 inline, 0 general)'''
        )
        response.mustcontain(
            '''<div style="display:none" class="inline-comment-placeholder" '''
            '''path="vcs/web/simplevcs/views/repository.py" '''
            '''target_id="vcswebsimplevcsviewsrepositorypy">'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/vcs_test_hg/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % ID)
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
    def test_create(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'

        params = {
            'text': text,
            '_authentication_token': self.authentication_token()
        }
        response = self.app.post(url(controller='changeset',
                                     action='comment',
                                     repo_name=HG_REPO,
                                     revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            url(controller='changeset',
                action='index',
                repo_name=HG_REPO,
                revision=rev))
        # test DB
        assert ChangesetComment.query().count() == 1
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (0 inline, 1 general)''')

        assert Notification.query().count() == 1
        assert ChangesetComment.query().count() == 1

        notification = Notification.query().all()[0]

        ID = ChangesetComment.query().first().comment_id
        assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT
        sbj = (u'/%s/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' %
               (HG_REPO, ID))
        print "%s vs %s" % (sbj, notification.subject)
        assert sbj in notification.subject
Beispiel #22
0
    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'CommentOnRevision'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {'text': text, 'f_path': f_path, 'line': line, '_authentication_token': self.authentication_token()}
        response = self.app.post(url(controller='changeset', action='comment',
                                     repo_name=HG_REPO, revision=rev),
                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        self.assertEqual(response.status, '200 OK')

        response = self.app.get(url(controller='changeset', action='index',
                                repo_name=HG_REPO, revision=rev))
        #test DB
        self.assertEqual(ChangesetComment.query().count(), 1)
        response.mustcontain(
            '''<div class="comments-number">'''
            ''' 1 comment (1 inline, 0 general)'''
        )
        response.mustcontain(
            '''<div class="comments-list-chunk" '''
            '''data-f_path="vcs/web/simplevcs/views/repository.py" '''
            '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">'''
        )

        self.assertEqual(Notification.query().count(), 1)
        self.assertEqual(ChangesetComment.query().count(), 1)

        notification = Notification.query().all()[0]
        ID = ChangesetComment.query().first().comment_id
        self.assertEqual(notification.type_,
                         Notification.TYPE_CHANGESET_COMMENT)
        sbj = (u'/%s/changeset/'
               '27cd5cce30c96924232dffcd24178a07ffeb5dfc#comment-%s' % (HG_REPO, ID))
        print "%s vs %s" % (sbj, notification.subject)
        self.assertTrue(sbj in notification.subject)
    def test_delete(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = 'general comment on changeset to be deleted'

        params = {
            'text': text,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='changeset',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})

        comments = ChangesetComment.query().all()
        assert len(comments) == 1
        comment_id = comments[0].comment_id

        self.app.post(base.url("changeset_comment_delete",
                               repo_name=base.HG_REPO,
                               comment_id=comment_id),
                      params={
                          '_session_csrf_secret_token':
                          self.session_csrf_secret_token()
                      })

        comments = ChangesetComment.query().all()
        assert len(comments) == 0

        response = self.app.get(
            base.url(controller='changeset',
                     action='index',
                     repo_name=base.HG_REPO,
                     revision=rev))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 0 comments (0 inline, 0 general)''')
        response.mustcontain(no=text)
Beispiel #24
0
    def delete_comment(self, repo_name, comment_id):
        co = ChangesetComment.get(comment_id)
        if co.pull_request.is_closed():
            #don't allow deleting comments on closed pull request
            raise HTTPForbidden()

        owner = co.author_id == request.authuser.user_id
        repo_admin = h.HasRepoPermissionLevel('admin')(c.repo_name)
        if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
            ChangesetCommentsModel().delete(comment=co)
            Session().commit()
            return True
        else:
            raise HTTPForbidden()
Beispiel #25
0
    def delete_comment(self, repo_name, comment_id):
        co = ChangesetComment.get(comment_id)
        if co.pull_request.is_closed():
            #don't allow deleting comments on closed pull request
            raise HTTPForbidden()

        owner = co.author.user_id == c.authuser.user_id
        repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
        if h.HasPermissionAny('hg.admin') or repo_admin or owner:
            ChangesetCommentsModel().delete(comment=co)
            Session().commit()
            return True
        else:
            raise HTTPForbidden()
Beispiel #26
0
def delete_cs_pr_comment(repo_name, comment_id):
    """Delete a comment from a changeset or pull request"""
    co = ChangesetComment.get_or_404(comment_id)
    if co.repo.repo_name != repo_name:
        raise HTTPNotFound()
    if co.pull_request and co.pull_request.is_closed():
        # don't allow deleting comments on closed pull request
        raise HTTPForbidden()

    owner = co.author_id == request.authuser.user_id
    repo_admin = h.HasRepoPermissionLevel('admin')(repo_name)
    if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
        ChangesetCommentsModel().delete(comment=co)
        Session().commit()
        return True
    else:
        raise HTTPForbidden()
Beispiel #27
0
    def get_comments(self, repo_id, revision=None, pull_request=None):
        """
        Gets main comments based on revision or pull_request_id

        :param repo_id:
        :param revision:
        :param pull_request:
        """

        q = ChangesetComment.query()\
                .filter(ChangesetComment.repo_id == repo_id)\
                .filter(ChangesetComment.line_no == None)\
                .filter(ChangesetComment.f_path == None)
        if revision:
            q = q.filter(ChangesetComment.revision == revision)
        elif pull_request:
            pull_request = self.__get_pull_request(pull_request)
            q = q.filter(ChangesetComment.pull_request == pull_request)
        else:
            raise Exception('Please specify revision or pull_request')
        q = q.order_by(ChangesetComment.created_on)
        return q.all()
    def test_create_inline(self):
        self.log_user()
        pr_id = self._create_pr()

        text = 'inline comment on changeset'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'
        params = {
            'text': text,
            'f_path': f_path,
            'line': line,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='pullrequests',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          pull_request_id=pr_id),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='pullrequests',
                     action='show',
                     repo_name=base.HG_REPO,
                     pull_request_id=pr_id,
                     extra=''))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 2 comments (1 inline, 1 general)''')
        response.mustcontain(
            '''<div class="comments-list-chunk" '''
            '''data-f_path="vcs/web/simplevcs/views/repository.py" '''
            '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">'''
        )
        response.mustcontain(text)

        # test DB
        assert ChangesetComment.query().count() == 2
Beispiel #29
0
    def get_comments(self, repo_id, revision=None, pull_request=None):
        """
        Gets main comments based on revision or pull_request_id

        :param repo_id:
        :param revision:
        :param pull_request:
        """

        q = ChangesetComment.query()\
                .filter(ChangesetComment.repo_id == repo_id)\
                .filter(ChangesetComment.line_no == None)\
                .filter(ChangesetComment.f_path == None)
        if revision:
            q = q.filter(ChangesetComment.revision == revision)
        elif pull_request:
            pull_request = self.__get_pull_request(pull_request)
            q = q.filter(ChangesetComment.pull_request == pull_request)
        else:
            raise Exception('Please specify revision or pull_request')
        q = q.order_by(ChangesetComment.created_on)
        return q.all()
    def test_create_inline(self):
        self.log_user()
        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = 'inline comment on changeset'
        f_path = 'vcs/web/simplevcs/views/repository.py'
        line = 'n1'

        params = {
            'text': text,
            'f_path': f_path,
            'line': line,
            '_session_csrf_secret_token': self.session_csrf_secret_token()
        }
        response = self.app.post(base.url(controller='changeset',
                                          action='comment',
                                          repo_name=base.HG_REPO,
                                          revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            base.url(controller='changeset',
                     action='index',
                     repo_name=base.HG_REPO,
                     revision=rev))
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (1 inline, 0 general)''')
        response.mustcontain(
            '''<div class="comments-list-chunk" '''
            '''data-f_path="vcs/web/simplevcs/views/repository.py" '''
            '''data-line_no="n1" data-target-id="vcswebsimplevcsviewsrepositorypy_n1">'''
        )
        response.mustcontain(text)

        # test DB
        assert ChangesetComment.query().count() == 1
    def test_create_with_mention(self):
        self.log_user()

        rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
        text = u'@%s check CommentOnRevision' % TEST_USER_REGULAR_LOGIN

        params = {
            'text': text,
            '_authentication_token': self.authentication_token()
        }
        response = self.app.post(url(controller='changeset',
                                     action='comment',
                                     repo_name=HG_REPO,
                                     revision=rev),
                                 params=params,
                                 extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
        # Test response...
        assert response.status == '200 OK'

        response = self.app.get(
            url(controller='changeset',
                action='index',
                repo_name=HG_REPO,
                revision=rev))
        # test DB
        assert ChangesetComment.query().count() == 1
        response.mustcontain('''<div class="comments-number">'''
                             ''' 1 comment (0 inline, 1 general)''')

        assert Notification.query().count() == 2
        users = [x.user.username for x in UserNotification.query().all()]

        # test_regular gets notification by @mention
        assert sorted(users) == [
            TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
        ]
    def setup_method(self, method):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        self.remove_all_notifications()
Beispiel #33
0
    def create(self, text, repo, user, revision=None, pull_request=None,
               f_path=None, line_no=None, status_change=None, closing_pr=False,
               send_email=True):
        """
        Creates new comment for changeset or pull request.
        If status_change is not None this comment is associated with a
        status change of changeset or changesets associated with pull request

        :param text:
        :param repo:
        :param user:
        :param revision:
        :param pull_request: (for emails, not for comments)
        :param f_path:
        :param line_no:
        :param status_change: (for emails, not for comments)
        :param closing_pr: (for emails, not for comments)
        :param send_email: also send email
        """
        if not text:
            log.warning('Missing text for comment, skipping...')
            return

        repo = self._get_repo(repo)
        user = self._get_user(user)
        comment = ChangesetComment()
        comment.repo = repo
        comment.author = user
        comment.text = text
        comment.f_path = f_path
        comment.line_no = line_no

        if revision:
            comment.revision = revision
        elif pull_request:
            pull_request = self.__get_pull_request(pull_request)
            comment.pull_request = pull_request
        else:
            raise Exception('Please specify revision or pull_request_id')

        Session().add(comment)
        Session().flush()

        if send_email:
            (subj, body, recipients, notification_type,
             email_kwargs) = self._get_notification_data(
                                repo, comment, user,
                                comment_text=text,
                                line_no=line_no,
                                revision=revision,
                                pull_request=pull_request,
                                status_change=status_change,
                                closing_pr=closing_pr)
            email_kwargs['is_mention'] = False
            # create notification objects, and emails
            NotificationModel().create(
                created_by=user, subject=subj, body=body,
                recipients=recipients, type_=notification_type,
                email_kwargs=email_kwargs,
            )

            mention_recipients = set(self._extract_mentions(body))\
                                    .difference(recipients)
            if mention_recipients:
                email_kwargs['is_mention'] = True
                subj = _('[Mention]') + ' ' + subj
                NotificationModel().create(
                    created_by=user, subject=subj, body=body,
                    recipients=mention_recipients,
                    type_=notification_type,
                    email_kwargs=email_kwargs
                )

        return comment
Beispiel #34
0
    def setUp(self):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        remove_all_notifications()
Beispiel #35
0
    def create(self, text, repo, author, revision=None, pull_request=None,
               f_path=None, line_no=None, status_change=None, closing_pr=False,
               send_email=True):
        """
        Creates a new comment for either a changeset or a pull request.
        status_change and closing_pr is only for the optional email.

        Returns the created comment.
        """
        if not status_change and not text:
            log.warning('Missing text for comment, skipping...')
            return None

        repo = Repository.guess_instance(repo)
        author = User.guess_instance(author)
        comment = ChangesetComment()
        comment.repo = repo
        comment.author = author
        comment.text = text
        comment.f_path = f_path
        comment.line_no = line_no

        if revision is not None:
            comment.revision = revision
        elif pull_request is not None:
            pull_request = PullRequest.guess_instance(pull_request)
            comment.pull_request = pull_request
        else:
            raise Exception('Please specify revision or pull_request_id')

        Session().add(comment)
        Session().flush()

        if send_email:
            (subj, body, recipients, notification_type,
             email_kwargs) = self._get_notification_data(
                                repo, comment, author,
                                comment_text=text,
                                line_no=line_no,
                                revision=revision,
                                pull_request=pull_request,
                                status_change=status_change,
                                closing_pr=closing_pr)
            email_kwargs['is_mention'] = False
            # create notification objects, and emails
            NotificationModel().create(
                created_by=author, subject=subj, body=body,
                recipients=recipients, type_=notification_type,
                email_kwargs=email_kwargs,
            )

            mention_recipients = extract_mentioned_users(body).difference(recipients)
            if mention_recipients:
                email_kwargs['is_mention'] = True
                subj = _('[Mention]') + ' ' + subj
                # FIXME: this subject is wrong and unused!
                NotificationModel().create(
                    created_by=author, subject=subj, body=body,
                    recipients=mention_recipients,
                    type_=notification_type,
                    email_kwargs=email_kwargs
                )

        return comment
Beispiel #36
0
    def delete(self, comment):
        comment = ChangesetComment.guess_instance(comment)
        Session().delete(comment)

        return comment
Beispiel #37
0
    def delete(self, comment):
        comment = ChangesetComment.guess_instance(comment)
        Session().delete(comment)

        return comment
Beispiel #38
0
    def _get_notification_data(self, repo, comment, user, comment_text,
                               line_no=None, revision=None, pull_request=None,
                               status_change=None, closing_pr=False):
        """
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = cs.short_id

            threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' % (repo.repo_name, revision, line_no,
                                                           h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                repo_name=repo.repo_name,
                revision=revision,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = ChangesetComment.get_users(revision=revision)
            # add changeset author if it's known locally
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                cs_author = repo.user
            recipients += [cs_author]
            email_kwargs = {
                'status_change': status_change,
                'cs_comment_user': user.full_name_and_username,
                'cs_target_repo': h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url': comment_url,
                'raw_id': revision,
                'message': cs.message,
                'repo_name': repo.repo_name,
                'short_id': h.short_id(revision),
                'branch': cs.branch,
                'comment_username': user.username,
                'threading': threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
            threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
                                          pull_request.pull_request_id,
                                          h.canonical_hostname())]
            if line_no: # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name,
                                                          pull_request.pull_request_id, line_no,
                                                          h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                anchor='comment-%s' % comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request %(pr_nice_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_nice_id': comment.pull_request.nice_id(),
                           'line': line},
                          comment_url)
            )
            # get the current participants of this pull request
            recipients = ChangesetComment.get_users(pull_request_id=
                                                pull_request.pull_request_id)
            # add pull request author
            recipients += [pull_request.owner]

            # add the reviewers to notification
            recipients += pull_request.get_reviewer_users()

            #set some variables for email notification
            email_kwargs = {
                'pr_title': pull_request.title,
                'pr_nice_id': pull_request.nice_id(),
                'status_change': status_change,
                'closing_pr': closing_pr,
                'pr_comment_url': comment_url,
                'pr_comment_user': user.full_name_and_username,
                'pr_target_repo': h.canonical_url('summary_home',
                                   repo_name=pull_request.other_repo.repo_name),
                'repo_name': pull_request.other_repo.repo_name,
                'ref': org_ref_name,
                'comment_username': user.username,
                'threading': threading,
            }

        return subj, body, recipients, notification_type, email_kwargs
 def setup_method(self, method):
     for x in ChangesetComment.query().all():
         Session().delete(x)
     Session().commit()
Beispiel #40
0
    def _get_notification_data(self,
                               repo,
                               comment,
                               user,
                               comment_text,
                               line_no=None,
                               revision=None,
                               pull_request=None,
                               status_change=None,
                               closing_pr=False):
        """
        Get notification data

        :param comment_text:
        :param line:
        :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
        """
        # make notification
        body = comment_text  # text of the comment
        line = ''
        if line_no:
            line = _('on line %s') % line_no

        #changeset
        if revision:
            notification_type = Notification.TYPE_CHANGESET_COMMENT
            cs = repo.scm_instance.get_changeset(revision)
            desc = "%s" % (cs.short_id)

            threading = [
                '%s-rev-%s@%s' %
                (repo.repo_name, revision, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-rev-%s-line-%s@%s' %
                                 (repo.repo_name, revision, line_no,
                                  h.canonical_hostname()))
            comment_url = h.canonical_url('changeset_home',
                                          repo_name=repo.repo_name,
                                          revision=revision,
                                          anchor='comment-%s' %
                                          comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re changeset: %(desc)s %(line)s' % \
                          {'desc': desc, 'line': line},
                          comment_url)
            )
            # get the current participants of this changeset
            recipients = ChangesetComment.get_users(revision=revision)
            # add changeset author if it's in kallithea system
            cs_author = User.get_from_cs_author(cs.author)
            if not cs_author:
                #use repo owner if we cannot extract the author correctly
                cs_author = repo.user
            recipients += [cs_author]
            email_kwargs = {
                'status_change':
                status_change,
                'cs_comment_user':
                h.person(user, 'username_and_name'),
                'cs_target_repo':
                h.canonical_url('summary_home', repo_name=repo.repo_name),
                'cs_comment_url':
                comment_url,
                'raw_id':
                revision,
                'message':
                cs.message,
                'repo_name':
                repo.repo_name,
                'short_id':
                h.short_id(revision),
                'branch':
                cs.branch,
                'comment_username':
                user.username,
                'threading':
                threading,
            }
        #pull request
        elif pull_request:
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
            desc = comment.pull_request.title
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(
                ':')
            threading = [
                '%s-pr-%s@%s' %
                (pull_request.other_repo.repo_name,
                 pull_request.pull_request_id, h.canonical_hostname())
            ]
            if line_no:  # TODO: url to file _and_ line number
                threading.append('%s-pr-%s-line-%s@%s' %
                                 (pull_request.other_repo.repo_name,
                                  pull_request.pull_request_id, line_no,
                                  h.canonical_hostname()))
            comment_url = pull_request.url(canonical=True,
                                           anchor='comment-%s' %
                                           comment.comment_id)
            subj = safe_unicode(
                h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
                          {'desc': desc,
                           'pr_id': comment.pull_request.pull_request_id,
                           'line': line},
                          comment_url)
            )
            # get the current participants of this pull request
            recipients = ChangesetComment.get_users(
                pull_request_id=pull_request.pull_request_id)
            # add pull request author
            recipients += [pull_request.author]

            # add the reviewers to notification
            recipients += [x.user for x in pull_request.reviewers]

            #set some variables for email notification
            email_kwargs = {
                'pr_title':
                pull_request.title,
                'pr_id':
                pull_request.pull_request_id,
                'status_change':
                status_change,
                'closing_pr':
                closing_pr,
                'pr_comment_url':
                comment_url,
                'pr_comment_user':
                h.person(user, 'username_and_name'),
                'pr_target_repo':
                h.canonical_url('summary_home',
                                repo_name=pull_request.other_repo.repo_name),
                'repo_name':
                pull_request.other_repo.repo_name,
                'ref':
                org_ref_name,
                'comment_username':
                user.username,
                'threading':
                threading,
            }

        return subj, body, recipients, notification_type, email_kwargs
    def setup_method(self, method):
        for x in ChangesetComment.query().all():
            Session().delete(x)
        Session().commit()

        self.remove_all_notifications()
Beispiel #42
0
    def create(self,
               text,
               repo,
               user,
               revision=None,
               pull_request=None,
               f_path=None,
               line_no=None,
               status_change=None,
               closing_pr=False,
               send_email=True):
        """
        Creates new comment for changeset or pull request.
        If status_change is not None this comment is associated with a
        status change of changeset or changesets associated with pull request

        :param text:
        :param repo:
        :param user:
        :param revision:
        :param pull_request: (for emails, not for comments)
        :param f_path:
        :param line_no:
        :param status_change: (for emails, not for comments)
        :param closing_pr: (for emails, not for comments)
        :param send_email: also send email
        """
        if not text:
            log.warning('Missing text for comment, skipping...')
            return

        repo = self._get_repo(repo)
        user = self._get_user(user)
        comment = ChangesetComment()
        comment.repo = repo
        comment.author = user
        comment.text = text
        comment.f_path = f_path
        comment.line_no = line_no

        if revision:
            comment.revision = revision
        elif pull_request:
            pull_request = self.__get_pull_request(pull_request)
            comment.pull_request = pull_request
        else:
            raise Exception('Please specify revision or pull_request_id')

        Session().add(comment)
        Session().flush()

        if send_email:
            (subj, body, recipients, notification_type,
             email_kwargs) = self._get_notification_data(
                 repo,
                 comment,
                 user,
                 comment_text=text,
                 line_no=line_no,
                 revision=revision,
                 pull_request=pull_request,
                 status_change=status_change,
                 closing_pr=closing_pr)
            email_kwargs['is_mention'] = False
            # create notification objects, and emails
            NotificationModel().create(
                created_by=user,
                subject=subj,
                body=body,
                recipients=recipients,
                type_=notification_type,
                email_kwargs=email_kwargs,
            )

            mention_recipients = set(self._extract_mentions(body))\
                                    .difference(recipients)
            if mention_recipients:
                email_kwargs['is_mention'] = True
                subj = _('[Mention]') + ' ' + subj
                NotificationModel().create(created_by=user,
                                           subject=subj,
                                           body=body,
                                           recipients=mention_recipients,
                                           type_=notification_type,
                                           email_kwargs=email_kwargs)

        return comment
Beispiel #43
0
    def create(self,
               text,
               repo,
               author,
               revision=None,
               pull_request=None,
               f_path=None,
               line_no=None,
               status_change=None,
               closing_pr=False,
               send_email=True):
        """
        Creates a new comment for either a changeset or a pull request.
        status_change and closing_pr is only for the optional email.

        Returns the created comment.
        """
        if not status_change and not text:
            log.warning('Missing text for comment, skipping...')
            return None

        repo = Repository.guess_instance(repo)
        author = User.guess_instance(author)
        comment = ChangesetComment()
        comment.repo = repo
        comment.author = author
        comment.text = text
        comment.f_path = f_path
        comment.line_no = line_no

        if revision is not None:
            comment.revision = revision
        elif pull_request is not None:
            pull_request = PullRequest.guess_instance(pull_request)
            comment.pull_request = pull_request
        else:
            raise Exception('Please specify revision or pull_request_id')

        Session().add(comment)
        Session().flush()

        if send_email:
            (subj, body, recipients, notification_type,
             email_kwargs) = self._get_notification_data(
                 repo,
                 comment,
                 author,
                 comment_text=text,
                 line_no=line_no,
                 revision=revision,
                 pull_request=pull_request,
                 status_change=status_change,
                 closing_pr=closing_pr)
            email_kwargs['is_mention'] = False
            # create notification objects, and emails
            NotificationModel().create(
                created_by=author,
                subject=subj,
                body=body,
                recipients=recipients,
                type_=notification_type,
                email_kwargs=email_kwargs,
            )

            mention_recipients = extract_mentioned_users(body).difference(
                recipients)
            if mention_recipients:
                email_kwargs['is_mention'] = True
                subj = _('[Mention]') + ' ' + subj
                # FIXME: this subject is wrong and unused!
                NotificationModel().create(created_by=author,
                                           subject=subj,
                                           body=body,
                                           recipients=mention_recipients,
                                           type_=notification_type,
                                           email_kwargs=email_kwargs)

        return comment