From b0fad009a44b7ecb3c12ce66b05b296a2d0446b1 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Fri, 4 Oct 2019 10:48:31 -0400 Subject: [PATCH] Use MM username, not email username (#9) --- server/http_test.go | 8 -------- server/meeting.go | 12 ++++++------ server/store.go | 2 +- server/user.go | 24 ++++-------------------- webapp/src/components/icon.jsx | 2 -- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/server/http_test.go b/server/http_test.go index 5d98777..80cac4a 100644 --- a/server/http_test.go +++ b/server/http_test.go @@ -123,14 +123,6 @@ func TestPlugin(t *testing.T) { User: validUser, Room: "myroom", }, - { - Name: "Invalid meeting request: user has no roomId set, using their email. Invalid email.", - Request: validMeetingRequest5, - SiteHost: "hostname.webex.com", - ExpectedStatusCode: http.StatusBadRequest, - User: UserInfo{Email: "myemailtestcom", RoomID: ""}, - Room: "myemail", - }, { Name: "Valid meeting request: user has no email, but roomId is set.", Request: validMeetingRequest6, diff --git a/server/meeting.go b/server/meeting.go index 7dd46a3..ff0fdf8 100644 --- a/server/meeting.go +++ b/server/meeting.go @@ -87,8 +87,8 @@ func (p *Plugin) getUrlFromRoomId(roomId string) (string, error) { return roomUrl, nil } -func (p *Plugin) getUrlFromNameOrEmail(emailName, email string) (string, error) { - roomUrl, err := p.webexClient.GetPersonalMeetingRoomUrl("", emailName, email) +func (p *Plugin) getUrlFromNameOrEmail(userName, email string) (string, error) { + roomUrl, err := p.webexClient.GetPersonalMeetingRoomUrl("", userName, email) if err != nil { return "", err } @@ -107,13 +107,13 @@ func (p *Plugin) getRoomUrlFromMMId(mattermostUserId string) (string, error) { } } else { // Look for their url using userName or email - email, emailName, err := p.getEmailAndEmailName(mattermostUserId) + email, userName, err := p.getEmailAndUserName(mattermostUserId) if err != nil { - return "", fmt.Errorf("Error getting email and emailName: %v", err) + return "", fmt.Errorf("Error getting email and Username: %v", err) } - roomUrl, err = p.getUrlFromNameOrEmail(emailName, email) + roomUrl, err = p.getUrlFromNameOrEmail(userName, email) if err != nil { - return "", fmt.Errorf("No Personal Room link found at `%s` for your userName: `%s`, or your email: `%s`. Try setting a room manually with `/webex room `.", p.getConfiguration().SiteHost, emailName, email) + return "", fmt.Errorf("No Personal Room link found at `%s` for your Username: `%s`, or your email: `%s`. Try setting a room manually with `/webex room `.", p.getConfiguration().SiteHost, userName, email) } } diff --git a/server/store.go b/server/store.go index 8f43e27..6933bad 100644 --- a/server/store.go +++ b/server/store.go @@ -65,7 +65,7 @@ func (store store) set(key string, v interface{}) error { func (store store) StoreUserInfo(mattermostUserId string, info UserInfo) error { // Set the email because we need a field in the userInfo that cannot be blank (in order to tell if a user was found) - email, _, err := store.plugin.getEmailAndEmailName(mattermostUserId) + email, _, err := store.plugin.getEmailAndUserName(mattermostUserId) if err != nil { return err } diff --git a/server/user.go b/server/user.go index eb9dcc8..c8fbe25 100644 --- a/server/user.go +++ b/server/user.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "regexp" ) type UserInfo struct { @@ -11,39 +10,24 @@ type UserInfo struct { RoomID string `json:"room_id"` } -func (p *Plugin) getUserFromEmail(email string) (string, error) { - rexp := regexp.MustCompile("^(.*)@") - matches := rexp.FindStringSubmatch(email) - if matches == nil || matches[1] == "" { - p.errorf("Error getting userName from email address, address: %v", email) - return "", errors.New("error getting userName from email, please contact your system administrator") - } - - return matches[1], nil -} - -func (p *Plugin) getEmailAndEmailName(mattermostUserId string) (string, string, error) { +func (p *Plugin) getEmailAndUserName(mattermostUserId string) (string, string, error) { user, appErr := p.API.GetUser(mattermostUserId) if appErr != nil { p.errorf("error getting mattermost user from mattermostUserId: %s", mattermostUserId) return "", "", errors.New("error getting mattermost user from mattermostUserId, please contact your system administrator") } - emailName, err := p.getUserFromEmail(user.Email) - if err != nil { - return "", "", err - } - return user.Email, emailName, nil + return user.Email, user.Username, nil } func (p *Plugin) getRoomOrDefault(mattermostUserId string) (string, error) { roomId, err := p.getRoom(mattermostUserId) if err == ErrUserNotFound { - _, emailName, err2 := p.getEmailAndEmailName(mattermostUserId) + _, userName, err2 := p.getEmailAndUserName(mattermostUserId) if err2 != nil { return "", err2 } - return emailName, nil + return userName, nil } else if err != nil { return "", err } diff --git a/webapp/src/components/icon.jsx b/webapp/src/components/icon.jsx index e4fc6d3..892fa3b 100644 --- a/webapp/src/components/icon.jsx +++ b/webapp/src/components/icon.jsx @@ -3,8 +3,6 @@ import React from 'react'; -import {makeStyleFromTheme} from 'mattermost-redux/utils/theme_utils'; - import {Svgs} from '../constants'; export default class Icon extends React.PureComponent {