mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fixing /logout command (#2908)
This commit is contained in:
committed by
Joram Wilander
parent
204109b4b9
commit
d2f9fd52fe
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user