From 2a2af485fc04456f57106b594c47f272f48f756c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrey=20Ca=C3=B1on?= Date: Thu, 6 Jun 2019 16:06:21 -0500 Subject: [PATCH] PE-356 Rename team channels (#70) * filter list of groups by course and team, rename team channels * Addressing pr comments --- rocketc/api_rocket_chat.py | 4 +--- rocketc/rocketc.py | 33 +++++++++++++++++++++++--------- rocketc/static/js/src/rocketc.js | 3 ++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/rocketc/api_rocket_chat.py b/rocketc/api_rocket_chat.py index b77af2e3..284491d0 100644 --- a/rocketc/api_rocket_chat.py +++ b/rocketc/api_rocket_chat.py @@ -146,13 +146,11 @@ def kick_user_from_group(self, user_id, room_id): def list_all_groups(self, user_id, auth_token, **kwargs): """Get a list of groups""" url_path = "groups.list" - payload = kwargs url = "{}{}{}".format(self.server_url, self.API_path, url_path) headers = {"X-User-Id": user_id, "X-Auth-Token": auth_token} - response = requests.get(url=url, headers=headers, params=payload) - return handle_response("list_all_groups", response, **kwargs) + return handle_response("list_all_groups", requests.get(url=url, headers=headers), **kwargs) def get_groups_history(self, room_id, latest="", oldest="", # pylint: disable=too-many-arguments count=100, inclusive=False, unreads=False): diff --git a/rocketc/rocketc.py b/rocketc/rocketc.py index 8fdc2d92..715a823a 100644 --- a/rocketc/rocketc.py +++ b/rocketc/rocketc.py @@ -626,9 +626,22 @@ def create_group(self, data, suffix=""): @staticmethod def _create_team_group_name(team, group_name, course): + """ + This method returns the formated name for given team and group name, + in order to ensure a unique name in the rocketchat server. + **Example** + ** group_name = "Test" + ** team = { + "name": "team1", + "topic": "animals" + ...... + } + ** course = "coursev1:edx-c101-2019T2" + returns "Test(animals/team1)__coursev1:edx-c101-2019T2" + """ team_name, team_topic = generate_team_variables(team) - return "{}__{}__{}__{}".format(group_name, team_name, team_topic, course) + return "{}({}/{})__{}".format(group_name, team_topic, team_name, course) def _remove_user_from_group(self, group_name, user_id, auth_token=None): """ @@ -705,11 +718,7 @@ def get_list_of_groups(self, data, suffix=""): LOG.warn("Invalid data for method get_list_of_groups: %s", data) return None - team = self._get_team(self.user_data["username"]) - - kwargs = generate_query_dict(self.course_id, team=team) - - groups = list(self._get_list_groups(user_id, auth_token, **kwargs)) + groups = list(self._get_list_groups(user_id, auth_token)) return groups def _get_list_groups(self, user_id, auth_token, **kwargs): @@ -718,10 +727,16 @@ def _get_list_groups(self, user_id, auth_token, **kwargs): """ api = self.api_rocket_chat groups = api.list_all_groups(user_id, auth_token, **kwargs) + team, topic = generate_team_variables(self._get_team(self.user_data["username"])) if groups["success"]: - groups = groups["groups"] - for group in groups: - yield group["name"] + for group in groups["groups"]: + fields = group.get("customFields", {}) + if ( + team == fields.get("team") and + topic == fields.get("topic") and + self.course_id == fields.get("course") + ): + yield group["name"] def _get_user_messages(self, group_name, latest="", oldest="", count=100): """ diff --git a/rocketc/static/js/src/rocketc.js b/rocketc/static/js/src/rocketc.js index c77585e5..ca81eb1d 100644 --- a/rocketc/static/js/src/rocketc.js +++ b/rocketc/static/js/src/rocketc.js @@ -145,7 +145,8 @@ function RocketChatXBlock(runtime, element) { $("#select-channel").val($("#tool-buttons").attr("data-default")); } $("#select-channel").change(function(){ - url = $("#tool-buttons").attr("data-domain") + $("#select-channel").val() +"?layout=embedded"; + var groupName = $("#select-channel").val().replace("/", "%252F") + url = $("#tool-buttons").attr("data-domain") + groupName + "?layout=embedded"; $("#myframe").attr("src", url); }); };