Fixing /logout command (#2908)

This commit is contained in:
Christopher Speller
2016-05-06 12:08:49 -04:00
committed by Joram Wilander
parent 204109b4b9
commit d2f9fd52fe
4 changed files with 17 additions and 12 deletions

View File

@@ -33,6 +33,16 @@ func (me *LogoutProvider) GetCommand(c *Context) *model.Command {
}
func (me *LogoutProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
FAIL := &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.fail_message")}
SUCCESS := &model.CommandResponse{GotoLocation: "/", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/logout", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
// We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out
if c.Session.Id != "" {
RevokeSessionById(c, c.Session.Id)
if c.Err != nil {
return FAIL
}
return SUCCESS
}
return FAIL
}

View File

@@ -4,17 +4,11 @@
package api
import (
"strings"
"testing"
"github.com/mattermost/platform/model"
)
func TestLogoutTestCommand(t *testing.T) {
th := Setup().InitBasic()
rs1 := th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout", false)).Data.(*model.CommandResponse)
if !strings.HasSuffix(rs1.GotoLocation, "logout") {
t.Fatal("failed to logout")
}
th.BasicClient.Must(th.BasicClient.Command(th.BasicChannel.Id, "/logout", false))
}

View File

@@ -764,10 +764,7 @@ func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
c.RemoveSessionCookie(w, r)
if c.Session.Id != "" {
if result := <-Srv.Store.Session().Remove(c.Session.Id); result.Err != nil {
c.Err = result.Err
return
}
RevokeSessionById(c, c.Session.Id)
}
}

View File

@@ -387,6 +387,10 @@
"id": "api.command_logout.success_message",
"translation": "Logging out..."
},
{
"id": "api.command_logout.fail_message",
"translation": "Failed to log out"
},
{
"id": "api.command_me.desc",
"translation": "Do an action"