Skip to content

Commit

Permalink
Use MM username, not email username (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoile authored Oct 4, 2019
1 parent b7b3811 commit b0fad00
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
8 changes: 0 additions & 8 deletions server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions server/meeting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 <room id>`.", 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 <room id>`.", p.getConfiguration().SiteHost, userName, email)
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 4 additions & 20 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,31 @@ package main
import (
"errors"
"fmt"
"regexp"
)

type UserInfo struct {
Email string `json:"email"`
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
}
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/components/icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b0fad00

Please sign in to comment.