summary refs log tree commit diff
path: root/synapse/rest/client/v2_alpha/groups.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2018-03-28 14:03:37 +0100
committerDavid Baker <dave@matrix.org>2018-03-28 14:03:37 +0100
commit79452edeee94a09a826ee2b41a08811b823a3ad6 (patch)
treebdaa7170826c96481040394a679e5970f9d69d85 /synapse/rest/client/v2_alpha/groups.py
parentfix typo (diff)
downloadsynapse-79452edeee94a09a826ee2b41a08811b823a3ad6.tar.xz
Add joinability for groups
Adds API to set the 'joinable' flag, and corresponding flag in the
table.
Diffstat (limited to 'synapse/rest/client/v2_alpha/groups.py')
-rw-r--r--synapse/rest/client/v2_alpha/groups.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/synapse/rest/client/v2_alpha/groups.py b/synapse/rest/client/v2_alpha/groups.py
index f762dbfa9a..dc8247d172 100644
--- a/synapse/rest/client/v2_alpha/groups.py
+++ b/synapse/rest/client/v2_alpha/groups.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 # Copyright 2017 Vector Creations Ltd
+# Copyright 2018 New Vector Ltd
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -401,6 +402,32 @@ class GroupInvitedUsersServlet(RestServlet):
         defer.returnValue((200, result))
 
 
+class GroupJoinableServlet(RestServlet):
+    """Set whether a group is joinable without an invite
+    """
+    PATTERNS = client_v2_patterns("/groups/(?P<group_id>[^/]*)/joinable$")
+
+    def __init__(self, hs):
+        super(GroupJoinableServlet, self).__init__()
+        self.auth = hs.get_auth()
+        self.groups_handler = hs.get_groups_local_handler()
+
+    @defer.inlineCallbacks
+    def on_POST(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.set_group_joinable(
+            group_id,
+            requester_user_id,
+            content,
+        )
+
+        defer.returnValue((200, result))
+
+
 class GroupCreateServlet(RestServlet):
     """Create a group
     """
@@ -738,6 +765,7 @@ def register_servlets(hs, http_server):
     GroupInvitedUsersServlet(hs).register(http_server)
     GroupUsersServlet(hs).register(http_server)
     GroupRoomServlet(hs).register(http_server)
+    GroupJoinableServlet(hs).register(http_server)
     GroupCreateServlet(hs).register(http_server)
     GroupAdminRoomsServlet(hs).register(http_server)
     GroupAdminRoomsConfigServlet(hs).register(http_server)