2017-07-10 09:52:27 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2017 Vector Creations Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
from twisted.internet import defer
|
|
|
|
|
|
|
|
from synapse.http.servlet import RestServlet, parse_json_object_from_request
|
|
|
|
from synapse.types import GroupID
|
|
|
|
|
|
|
|
from ._base import client_v2_patterns
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class GroupServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get the group profile
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/profile$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 12:20:24 -04:00
|
|
|
group_description = yield self.groups_handler.get_group_profile(
|
|
|
|
group_id,
|
|
|
|
requester_user_id,
|
|
|
|
)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, group_description))
|
|
|
|
|
2017-07-20 04:46:33 -04:00
|
|
|
@defer.inlineCallbacks
|
2017-07-20 12:49:55 -04:00
|
|
|
def on_POST(self, request, group_id):
|
2017-07-20 04:46:33 -04:00
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-20 04:46:33 -04:00
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
yield self.groups_handler.update_group_profile(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id, content,
|
2017-07-20 04:46:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, {}))
|
|
|
|
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
class GroupSummaryServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get the full group summary
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/summary$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSummaryServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 12:20:24 -04:00
|
|
|
get_group_summary = yield self.groups_handler.get_group_summary(
|
|
|
|
group_id,
|
|
|
|
requester_user_id,
|
|
|
|
)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, get_group_summary))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupSummaryRoomsCatServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Update/delete a rooms entry in the summary.
|
|
|
|
|
|
|
|
Matches both:
|
|
|
|
- /groups/:group/summary/rooms/:room_id
|
|
|
|
- /groups/:group/summary/categories/:category/rooms/:room_id
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/summary"
|
2017-07-18 12:19:39 -04:00
|
|
|
"(/categories/(?P<category_id>[^/]+))?"
|
|
|
|
"/rooms/(?P<room_id>[^/]*)$"
|
2017-07-10 09:52:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSummaryRoomsCatServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, category_id, room_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
resp = yield self.groups_handler.update_group_summary_room(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
room_id=room_id,
|
|
|
|
category_id=category_id,
|
|
|
|
content=content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_DELETE(self, request, group_id, category_id, room_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
resp = yield self.groups_handler.delete_group_summary_room(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
room_id=room_id,
|
|
|
|
category_id=category_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupCategoryServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get/add/update/delete a group category
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/categories/(?P<category_id>[^/]+)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupCategoryServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id, category_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
category = yield self.groups_handler.get_group_category(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
category_id=category_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, category))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, category_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
resp = yield self.groups_handler.update_group_category(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
category_id=category_id,
|
|
|
|
content=content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_DELETE(self, request, group_id, category_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
resp = yield self.groups_handler.delete_group_category(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
category_id=category_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupCategoriesServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get all group categories
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/categories/$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupCategoriesServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
category = yield self.groups_handler.get_group_categories(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, category))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupRoleServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get/add/update/delete a group role
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/roles/(?P<role_id>[^/]+)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupRoleServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id, role_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
category = yield self.groups_handler.get_group_role(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
role_id=role_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, category))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, role_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
resp = yield self.groups_handler.update_group_role(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
role_id=role_id,
|
|
|
|
content=content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_DELETE(self, request, group_id, role_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
resp = yield self.groups_handler.delete_group_role(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
role_id=role_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupRolesServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get all group roles
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/roles/$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupRolesServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
category = yield self.groups_handler.get_group_roles(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id,
|
2017-07-10 09:52:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, category))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupSummaryUsersRoleServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Update/delete a user's entry in the summary.
|
|
|
|
|
|
|
|
Matches both:
|
|
|
|
- /groups/:group/summary/users/:room_id
|
|
|
|
- /groups/:group/summary/roles/:role/users/:user_id
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/summary"
|
2017-07-18 12:19:39 -04:00
|
|
|
"(/roles/(?P<role_id>[^/]+))?"
|
|
|
|
"/users/(?P<user_id>[^/]*)$"
|
2017-07-10 09:52:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSummaryUsersRoleServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, role_id, user_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
resp = yield self.groups_handler.update_group_summary_user(
|
|
|
|
group_id, requester_user_id,
|
|
|
|
user_id=user_id,
|
|
|
|
role_id=role_id,
|
|
|
|
content=content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_DELETE(self, request, group_id, role_id, user_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
resp = yield self.groups_handler.delete_group_summary_user(
|
|
|
|
group_id, requester_user_id,
|
|
|
|
user_id=user_id,
|
|
|
|
role_id=role_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, resp))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupRoomServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get all rooms in a group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/rooms$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupRoomServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 11:51:32 -04:00
|
|
|
result = yield self.groups_handler.get_rooms_in_group(group_id, requester_user_id)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupUsersServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get all users in a group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/users$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupUsersServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 11:51:32 -04:00
|
|
|
result = yield self.groups_handler.get_users_in_group(group_id, requester_user_id)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
2017-10-16 10:52:12 -04:00
|
|
|
|
2017-10-16 10:31:11 -04:00
|
|
|
class GroupInvitedUsersServlet(RestServlet):
|
|
|
|
"""Get users invited to a group
|
|
|
|
"""
|
|
|
|
PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/invited_users$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupInvitedUsersServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-10-16 10:31:11 -04:00
|
|
|
|
2017-10-26 12:20:24 -04:00
|
|
|
result = yield self.groups_handler.get_invited_users_in_group(
|
|
|
|
group_id,
|
|
|
|
requester_user_id,
|
|
|
|
)
|
2017-10-16 10:31:11 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
class GroupCreateServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Create a group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns("/create_group$")
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupCreateServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
self.server_name = hs.hostname
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_POST(self, request):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
# TODO: Create group on remote server
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
localpart = content.pop("localpart")
|
2017-10-20 11:33:15 -04:00
|
|
|
group_id = GroupID(localpart, self.server_name).to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 12:20:24 -04:00
|
|
|
result = yield self.groups_handler.create_group(
|
|
|
|
group_id,
|
|
|
|
requester_user_id,
|
|
|
|
content,
|
|
|
|
)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupAdminRoomsServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Add a room to the group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/admin/rooms/(?P<room_id>[^/]*)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupAdminRoomsServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, room_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
2017-07-18 12:28:42 -04:00
|
|
|
result = yield self.groups_handler.add_room_to_group(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id, room_id, content,
|
2017-07-18 12:28:42 -04:00
|
|
|
)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
2017-09-26 10:52:41 -04:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_DELETE(self, request, group_id, room_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-09-26 10:52:41 -04:00
|
|
|
|
|
|
|
result = yield self.groups_handler.remove_room_from_group(
|
2017-10-26 11:51:32 -04:00
|
|
|
group_id, requester_user_id, room_id,
|
2017-09-26 10:52:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
class GroupAdminUsersInviteServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Invite a user to the group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/admin/users/invite/(?P<user_id>[^/]*)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupAdminUsersInviteServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
self.store = hs.get_datastore()
|
|
|
|
self.is_mine_id = hs.is_mine_id
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, user_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
config = content.get("config", {})
|
|
|
|
result = yield self.groups_handler.invite(
|
|
|
|
group_id, user_id, requester_user_id, config,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupAdminUsersKickServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Kick a user from the group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/admin/users/remove/(?P<user_id>[^/]*)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupAdminUsersKickServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id, user_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
result = yield self.groups_handler.remove_user_from_group(
|
|
|
|
group_id, user_id, requester_user_id, content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupSelfLeaveServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Leave a joined group
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/self/leave$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSelfLeaveServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
result = yield self.groups_handler.remove_user_from_group(
|
|
|
|
group_id, requester_user_id, requester_user_id, content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupSelfJoinServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Attempt to join a group, or knock
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/self/join$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSelfJoinServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
result = yield self.groups_handler.join_group(
|
|
|
|
group_id, requester_user_id, content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class GroupSelfAcceptInviteServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Accept a group invite
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/self/accept_invite$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSelfAcceptInviteServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
result = yield self.groups_handler.accept_invite(
|
|
|
|
group_id, requester_user_id, content,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
2017-08-08 09:19:07 -04:00
|
|
|
class GroupSelfUpdatePublicityServlet(RestServlet):
|
|
|
|
"""Update whether we publicise a users membership of a group
|
|
|
|
"""
|
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/groups/(?P<group_id>[^/]*)/self/update_publicity$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupSelfUpdatePublicityServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.store = hs.get_datastore()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_PUT(self, request, group_id):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
|
|
|
requester_user_id = requester.user.to_string()
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
publicise = content["publicise"]
|
|
|
|
yield self.store.update_group_publicity(
|
|
|
|
group_id, requester_user_id, publicise,
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, {}))
|
|
|
|
|
|
|
|
|
2017-08-09 08:36:22 -04:00
|
|
|
class PublicisedGroupsForUserServlet(RestServlet):
|
|
|
|
"""Get the list of groups a user is advertising
|
|
|
|
"""
|
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/publicised_groups/(?P<user_id>[^/]*)$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(PublicisedGroupsForUserServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.store = hs.get_datastore()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request, user_id):
|
|
|
|
yield self.auth.get_user_by_req(request)
|
|
|
|
|
|
|
|
result = yield self.groups_handler.get_publicised_groups_for_user(
|
|
|
|
user_id
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
class PublicisedGroupsForUsersServlet(RestServlet):
|
|
|
|
"""Get the list of groups a user is advertising
|
|
|
|
"""
|
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/publicised_groups$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(PublicisedGroupsForUsersServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.store = hs.get_datastore()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_POST(self, request):
|
|
|
|
yield self.auth.get_user_by_req(request)
|
|
|
|
|
|
|
|
content = parse_json_object_from_request(request)
|
|
|
|
user_ids = content["user_ids"]
|
|
|
|
|
|
|
|
result = yield self.groups_handler.bulk_get_publicised_groups(
|
|
|
|
user_ids
|
|
|
|
)
|
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
2017-07-10 09:52:27 -04:00
|
|
|
class GroupsForUserServlet(RestServlet):
|
2017-07-18 12:19:39 -04:00
|
|
|
"""Get all groups the logged in user is joined to
|
|
|
|
"""
|
2017-07-10 09:52:27 -04:00
|
|
|
PATTERNS = client_v2_patterns(
|
|
|
|
"/joined_groups$"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, hs):
|
|
|
|
super(GroupsForUserServlet, self).__init__()
|
|
|
|
self.auth = hs.get_auth()
|
|
|
|
self.clock = hs.get_clock()
|
|
|
|
self.groups_handler = hs.get_groups_local_handler()
|
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def on_GET(self, request):
|
|
|
|
requester = yield self.auth.get_user_by_req(request)
|
2017-10-26 11:51:32 -04:00
|
|
|
requester_user_id = requester.user.to_string()
|
2017-07-10 09:52:27 -04:00
|
|
|
|
2017-10-26 11:51:32 -04:00
|
|
|
result = yield self.groups_handler.get_joined_groups(requester_user_id)
|
2017-07-10 09:52:27 -04:00
|
|
|
|
|
|
|
defer.returnValue((200, result))
|
|
|
|
|
|
|
|
|
|
|
|
def register_servlets(hs, http_server):
|
|
|
|
GroupServlet(hs).register(http_server)
|
|
|
|
GroupSummaryServlet(hs).register(http_server)
|
2017-10-16 10:31:11 -04:00
|
|
|
GroupInvitedUsersServlet(hs).register(http_server)
|
2017-07-10 09:52:27 -04:00
|
|
|
GroupUsersServlet(hs).register(http_server)
|
|
|
|
GroupRoomServlet(hs).register(http_server)
|
|
|
|
GroupCreateServlet(hs).register(http_server)
|
|
|
|
GroupAdminRoomsServlet(hs).register(http_server)
|
|
|
|
GroupAdminUsersInviteServlet(hs).register(http_server)
|
|
|
|
GroupAdminUsersKickServlet(hs).register(http_server)
|
|
|
|
GroupSelfLeaveServlet(hs).register(http_server)
|
|
|
|
GroupSelfJoinServlet(hs).register(http_server)
|
|
|
|
GroupSelfAcceptInviteServlet(hs).register(http_server)
|
|
|
|
GroupsForUserServlet(hs).register(http_server)
|
|
|
|
GroupCategoryServlet(hs).register(http_server)
|
|
|
|
GroupCategoriesServlet(hs).register(http_server)
|
|
|
|
GroupSummaryRoomsCatServlet(hs).register(http_server)
|
|
|
|
GroupRoleServlet(hs).register(http_server)
|
|
|
|
GroupRolesServlet(hs).register(http_server)
|
2017-08-08 09:19:07 -04:00
|
|
|
GroupSelfUpdatePublicityServlet(hs).register(http_server)
|
2017-07-10 09:52:27 -04:00
|
|
|
GroupSummaryUsersRoleServlet(hs).register(http_server)
|
2017-08-09 08:36:22 -04:00
|
|
|
PublicisedGroupsForUserServlet(hs).register(http_server)
|
2017-08-11 08:42:42 -04:00
|
|
|
PublicisedGroupsForUsersServlet(hs).register(http_server)
|