Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

matrix-org / synapse / 4532

23 Sep 2019 - 19:39 coverage decreased (-49.7%) to 17.596%
4532

Pull #6079

buildkite

Richard van der Hoff
update changelog
Pull Request #6079: Add submit_url response parameter to msisdn /requestToken

359 of 12986 branches covered (2.76%)

Branch coverage included in aggregate %.

0 of 7 new or added lines in 1 file covered. (0.0%)

18869 existing lines in 281 files now uncovered.

8809 of 39116 relevant lines covered (22.52%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.65
/synapse/rest/client/v2_alpha/tags.py
1
# -*- coding: utf-8 -*-
2
# Copyright 2015, 2016 OpenMarket Ltd
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
import logging
1×
17

18
from twisted.internet import defer
1×
19

20
from synapse.api.errors import AuthError
1×
21
from synapse.http.servlet import RestServlet, parse_json_object_from_request
1×
22

23
from ._base import client_patterns
1×
24

25
logger = logging.getLogger(__name__)
1×
26

27

28
class TagListServlet(RestServlet):
1×
29
    """
30
    GET /user/{user_id}/rooms/{room_id}/tags HTTP/1.1
31
    """
32

33
    PATTERNS = client_patterns("/user/(?P<user_id>[^/]*)/rooms/(?P<room_id>[^/]*)/tags")
1×
34

35
    def __init__(self, hs):
1×
UNCOV
36
        super(TagListServlet, self).__init__()
!
UNCOV
37
        self.auth = hs.get_auth()
!
UNCOV
38
        self.store = hs.get_datastore()
!
39

40
    @defer.inlineCallbacks
1×
41
    def on_GET(self, request, user_id, room_id):
UNCOV
42
        requester = yield self.auth.get_user_by_req(request)
!
UNCOV
43
        if user_id != requester.user.to_string():
Branches [[0, 44], [0, 46]] missed. !
44
            raise AuthError(403, "Cannot get tags for other users.")
!
45

UNCOV
46
        tags = yield self.store.get_tags_for_room(user_id, room_id)
!
47

UNCOV
48
        return 200, {"tags": tags}
!
49

50

51
class TagServlet(RestServlet):
1×
52
    """
53
    PUT /user/{user_id}/rooms/{room_id}/tags/{tag} HTTP/1.1
54
    DELETE /user/{user_id}/rooms/{room_id}/tags/{tag} HTTP/1.1
55
    """
56

57
    PATTERNS = client_patterns(
1×
58
        "/user/(?P<user_id>[^/]*)/rooms/(?P<room_id>[^/]*)/tags/(?P<tag>[^/]*)"
59
    )
60

61
    def __init__(self, hs):
1×
UNCOV
62
        super(TagServlet, self).__init__()
!
UNCOV
63
        self.auth = hs.get_auth()
!
UNCOV
64
        self.store = hs.get_datastore()
!
UNCOV
65
        self.notifier = hs.get_notifier()
!
66

67
    @defer.inlineCallbacks
1×
68
    def on_PUT(self, request, user_id, room_id, tag):
UNCOV
69
        requester = yield self.auth.get_user_by_req(request)
!
UNCOV
70
        if user_id != requester.user.to_string():
Branches [[0, 71], [0, 73]] missed. !
71
            raise AuthError(403, "Cannot add tags for other users.")
!
72

UNCOV
73
        body = parse_json_object_from_request(request)
!
74

UNCOV
75
        max_id = yield self.store.add_tag_to_room(user_id, room_id, tag, body)
!
76

UNCOV
77
        self.notifier.on_new_event("account_data_key", max_id, users=[user_id])
!
78

UNCOV
79
        return 200, {}
!
80

81
    @defer.inlineCallbacks
1×
82
    def on_DELETE(self, request, user_id, room_id, tag):
UNCOV
83
        requester = yield self.auth.get_user_by_req(request)
!
UNCOV
84
        if user_id != requester.user.to_string():
Branches [[0, 85], [0, 87]] missed. !
85
            raise AuthError(403, "Cannot add tags for other users.")
!
86

UNCOV
87
        max_id = yield self.store.remove_tag_from_room(user_id, room_id, tag)
!
88

UNCOV
89
        self.notifier.on_new_event("account_data_key", max_id, users=[user_id])
!
90

UNCOV
91
        return 200, {}
!
92

93

94
def register_servlets(hs, http_server):
1×
UNCOV
95
    TagListServlet(hs).register(http_server)
!
UNCOV
96
    TagServlet(hs).register(http_server)
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC