Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Add option for groups to hide their membership list from the world #2563

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ def update_group_profile(self, group_id, requester_user_id, content):
if not isinstance(value, basestring):
raise SynapseError(400, "%r value is not a string" % (keyname,))
profile[keyname] = value
if not isinstance(content["membership_is_private"], bool):
profile["membership_is_private"] = content["membership_is_private"]

yield self.store.update_group_profile(group_id, profile)

Expand All @@ -383,10 +385,15 @@ def get_users_in_group(self, group_id, requester_user_id):
yield self.check_group_is_ours(group_id, and_exists=True)

is_user_in_group = yield self.store.is_user_in_group(requester_user_id, group_id)
group = yield self.store.get_group(group_id)
is_membership_public = not group["membership_is_private"] \
or group["membership_is_private"] is None

user_results = yield self.store.get_users_in_group(
group_id, include_private=is_user_in_group,
)
user_results = []
if is_membership_public or is_user_in_group:
user_results = yield self.store.get_users_in_group(
group_id, include_private=is_user_in_group,
)

chunk = []
for user_result in user_results:
Expand Down Expand Up @@ -725,6 +732,7 @@ def create_group(self, group_id, user_id, content):
short_description = profile.get("short_description")
long_description = profile.get("long_description")
user_profile = content.get("user_profile", {})
membership_is_private = content.get("membership_is_private", False)

yield self.store.create_group(
group_id,
Expand All @@ -733,6 +741,7 @@ def create_group(self, group_id, user_id, content):
avatar_url=avatar_url,
short_description=short_description,
long_description=long_description,
membership_is_private=membership_is_private,
)

if not self.hs.is_mine_id(user_id):
Expand Down
6 changes: 4 additions & 2 deletions synapse/storage/group_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def get_group(self, group_id):
keyvalues={
"group_id": group_id,
},
retcols=("name", "short_description", "long_description", "avatar_url",),
retcols=("name", "short_description", "long_description", "avatar_url",
"membership_is_private"),
allow_none=True,
desc="is_user_in_group",
)
Expand Down Expand Up @@ -1017,7 +1018,7 @@ def _register_user_group_membership_txn(txn, next_id):

@defer.inlineCallbacks
def create_group(self, group_id, user_id, name, avatar_url, short_description,
long_description,):
long_description, membership_is_private):
yield self._simple_insert(
table="groups",
values={
Expand All @@ -1026,6 +1027,7 @@ def create_group(self, group_id, user_id, name, avatar_url, short_description,
"avatar_url": avatar_url,
"short_description": short_description,
"long_description": long_description,
"membership_is_private": membership_is_private,
},
desc="create_group",
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/prepare_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Remember to update this number every time a change is made to database
# schema files, so the users will be informed on server restarts.
SCHEMA_VERSION = 45
SCHEMA_VERSION = 46

dir_path = os.path.abspath(os.path.dirname(__file__))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2017 Travis Ralston
*
* 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.
*/


ALTER TABLE groups ADD COLUMN membership_is_private BOOLEAN;