Skip to content

Commit

Permalink
PE-356 Rename team channels (#70)
Browse files Browse the repository at this point in the history
* filter list of groups by course and team, rename team channels

* Addressing pr comments
  • Loading branch information
andrey-canon authored Jun 6, 2019
1 parent 5d9e84f commit 2a2af48
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 1 addition & 3 deletions rocketc/api_rocket_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
33 changes: 24 additions & 9 deletions rocketc/rocketc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion rocketc/static/js/src/rocketc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand Down

0 comments on commit 2a2af48

Please sign in to comment.