Allow update group publicity

This commit is contained in:
Erik Johnston 2017-08-08 14:19:07 +01:00
parent 05e21285aa
commit b880ff190a
2 changed files with 43 additions and 0 deletions

View file

@ -557,6 +557,33 @@ class GroupSelfAcceptInviteServlet(RestServlet):
defer.returnValue((200, result))
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, {}))
class GroupsForUserServlet(RestServlet):
"""Get all groups the logged in user is joined to
"""
@ -598,4 +625,5 @@ def register_servlets(hs, http_server):
GroupSummaryRoomsCatServlet(hs).register(http_server)
GroupRoleServlet(hs).register(http_server)
GroupRolesServlet(hs).register(http_server)
GroupSelfUpdatePublicityServlet(hs).register(http_server)
GroupSummaryUsersRoleServlet(hs).register(http_server)

View file

@ -835,6 +835,21 @@ class GroupServerStore(SQLBaseStore):
desc="add_room_to_group",
)
def update_group_publicity(self, group_id, user_id, publicise):
"""Update whether the user is publicising their membership of the group
"""
return self._simple_update_one(
table="local_group_membership",
keyvalues={
"group_id": group_id,
"user_id": user_id,
},
updatevalues={
"is_publicised": publicise,
},
desc="update_group_publicity"
)
@defer.inlineCallbacks
def register_user_group_membership(self, group_id, user_id, membership,
is_admin=False, content={},