From 1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 4 Apr 2017 20:17:15 +0100 Subject: PLT-6023: Add Users to Team in WebApp. (#5956) * PLT-6198: Use added to channel system message on default channels. Use a different sytem message when a user was added to a default channel by someone else than when they joined themselves. * PLT-6023: Add Users to Team in WebApp. * Fix string text. * Handle added_to_team websocket message. * Fix unread flag on new channel. --- webapp/client/client.jsx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'webapp/client/client.jsx') diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx index 1f70300e8..c1a9d2f85 100644 --- a/webapp/client/client.jsx +++ b/webapp/client/client.jsx @@ -489,6 +489,15 @@ export default class Client { // Team Routes Section + getTeam(teamId, success, error) { + request. + get(`${this.getTeamsRoute()}/${teamId}/me`). + set(this.defaultHeaders). + type('application/json'). + accept('application/json'). + end(this.handleResponse.bind(this, 'getTeam', success, error)); + } + findTeamByName(teamName, success, error) { request. post(`${this.getTeamsRoute()}/find_team_by_name`). @@ -681,6 +690,30 @@ export default class Client { this.trackEvent('api', 'api_teams_invite_members'); } + addUsersToTeam(teamId, userIds, success, error) { + let nonEmptyTeamId = teamId; + if (nonEmptyTeamId === '') { + nonEmptyTeamId = this.getTeamId(); + } + + const teamMembers = userIds.map((userId) => { + return { + team_id: nonEmptyTeamId, + user_id: userId + }; + }); + + request. + post(`${this.url}/api/v4/teams/${nonEmptyTeamId}/members/batch`). + set(this.defaultHeaders). + type('application/json'). + accept('application/json'). + send(teamMembers). + end(this.handleResponse.bind(this, 'addUsersToTeam', success, error)); + + this.trackEvent('api', 'api_teams_batch_add_members', {team_id: nonEmptyTeamId, count: teamMembers.length}); + } + removeUserFromTeam(teamId, userId, success, error) { let nonEmptyTeamId = teamId; if (nonEmptyTeamId === '') { @@ -1124,6 +1157,29 @@ export default class Client { this.trackEvent('api', 'api_profiles_get_in_team', {team_id: teamId}); } + getProfilesNotInTeam(teamId, offset, limit, success, error) { + // Super hacky, but this option only exists in api v4 + function wrappedSuccess(data, res) { + // Convert the profile list provided by api v4 to a map to match similar v3 calls + const profiles = {}; + + for (const profile of data) { + profiles[profile.id] = profile; + } + + success(profiles, res); + } + + request. + get(`${this.url}/api/v4/users?not_in_team=${this.getTeamId()}&page=${offset}&per_page=${limit}`). + set(this.defaultHeaders). + type('application/json'). + accept('application/json'). + end(this.handleResponse.bind(this, 'getProfilesNotInTeam', wrappedSuccess, error)); + + this.trackEvent('api', 'api_profiles_get_not_in_team', {team_id: teamId}); + } + getProfilesInChannel(channelId, offset, limit, success, error) { request. get(`${this.getChannelNeededRoute(channelId)}/users/${offset}/${limit}`). @@ -1191,6 +1247,19 @@ export default class Client { end(this.handleResponse.bind(this, 'searchUsers', success, error)); } + searchUsersNotInTeam(term, teamId, options, success, error) { + // Note that this is calling an APIv4 Endpoint since no APIv3 equivalent exists. + request. + post(`${this.url}/api/v4/users/search`). + set(this.defaultHeaders). + type('application/json'). + accept('application/json'). + send({term, not_in_team_id: teamId, ...options}). + end(this.handleResponse.bind(this, 'searchUsersNotInTeam', success, error)); + + this.trackEvent('api', 'api_search_users_not_in_team', {team_id: teamId}); + } + autocompleteUsersInChannel(term, channelId, success, error) { request. get(`${this.getChannelNeededRoute(channelId)}/users/autocomplete?term=${encodeURIComponent(term)}`). -- cgit v1.2.3-1-g7c22