Adding device Id for version 2 of native apps (#5505)
* Adding device Id for version 2 * Changing ids
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
3b0f7163ab
Коммит
ca7d3b6e7b
@@ -206,11 +206,6 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(strings.HasPrefix(deviceId, model.PUSH_NOTIFY_APPLE+":") || strings.HasPrefix(deviceId, model.PUSH_NOTIFY_ANDROID+":")) {
|
|
||||||
c.SetInvalidParam("attachDevice", "deviceId")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// A special case where we logout of all other sessions with the same device id
|
// A special case where we logout of all other sessions with the same device id
|
||||||
if err := app.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil {
|
if err := app.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
|
|||||||
@@ -1114,6 +1114,37 @@ func TestUserUpdateDeviceId(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserUpdateDeviceId2(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
Client := th.BasicClient
|
||||||
|
|
||||||
|
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||||
|
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||||
|
|
||||||
|
user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||||
|
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||||
|
LinkUserToTeam(user, team)
|
||||||
|
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||||
|
|
||||||
|
Client.Login(user.Email, "passwd1")
|
||||||
|
Client.SetTeamId(team.Id)
|
||||||
|
deviceId := model.PUSH_NOTIFY_APPLE_REACT_NATIVE + ":1234567890"
|
||||||
|
|
||||||
|
if _, err := Client.AttachDeviceId(deviceId); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
|
||||||
|
t.Fatal(result.Err)
|
||||||
|
} else {
|
||||||
|
sessions := result.Data.([]*model.Session)
|
||||||
|
|
||||||
|
if sessions[0].DeviceId != deviceId {
|
||||||
|
t.Fatal("Missing device Id")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUserUpdateActive(t *testing.T) {
|
func TestUserUpdateActive(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PUSH_NOTIFY_APPLE = "apple"
|
PUSH_NOTIFY_APPLE = "apple"
|
||||||
PUSH_NOTIFY_ANDROID = "android"
|
PUSH_NOTIFY_ANDROID = "android"
|
||||||
|
PUSH_NOTIFY_APPLE_REACT_NATIVE = "apple_rn"
|
||||||
|
PUSH_NOTIFY_ANDROID_REACT_NATIVE = "android_rn"
|
||||||
|
|
||||||
PUSH_TYPE_MESSAGE = "message"
|
PUSH_TYPE_MESSAGE = "message"
|
||||||
PUSH_TYPE_CLEAR = "clear"
|
PUSH_TYPE_CLEAR = "clear"
|
||||||
@@ -46,12 +48,11 @@ func (me *PushNotification) ToJson() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
|
func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) {
|
||||||
if strings.HasPrefix(deviceId, PUSH_NOTIFY_APPLE+":") {
|
|
||||||
me.Platform = PUSH_NOTIFY_APPLE
|
parts := strings.Split(deviceId, ":")
|
||||||
me.DeviceId = strings.TrimPrefix(deviceId, PUSH_NOTIFY_APPLE+":")
|
if len(parts) == 2 {
|
||||||
} else if strings.HasPrefix(deviceId, PUSH_NOTIFY_ANDROID+":") {
|
me.Platform = parts[0]
|
||||||
me.Platform = PUSH_NOTIFY_ANDROID
|
me.DeviceId = parts[1]
|
||||||
me.DeviceId = strings.TrimPrefix(deviceId, PUSH_NOTIFY_ANDROID+":")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,8 +111,7 @@ func (me *Session) GetTeamByTeamId(teamId string) *TeamMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *Session) IsMobileApp() bool {
|
func (me *Session) IsMobileApp() bool {
|
||||||
return len(me.DeviceId) > 0 &&
|
return len(me.DeviceId) > 0
|
||||||
(strings.HasPrefix(me.DeviceId, PUSH_NOTIFY_APPLE+":") || strings.HasPrefix(me.DeviceId, PUSH_NOTIFY_ANDROID+":"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *Session) GetUserRoles() []string {
|
func (me *Session) GetUserRoles() []string {
|
||||||
|
|||||||
@@ -197,6 +197,26 @@ func TestSessionUpdateDeviceId(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSessionUpdateDeviceId2(t *testing.T) {
|
||||||
|
Setup()
|
||||||
|
|
||||||
|
s1 := model.Session{}
|
||||||
|
s1.UserId = model.NewId()
|
||||||
|
Must(store.Session().Save(&s1))
|
||||||
|
|
||||||
|
if rs1 := (<-store.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
|
||||||
|
t.Fatal(rs1.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s2 := model.Session{}
|
||||||
|
s2.UserId = model.NewId()
|
||||||
|
Must(store.Session().Save(&s2))
|
||||||
|
|
||||||
|
if rs2 := (<-store.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
|
||||||
|
t.Fatal(rs2.Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSessionStoreUpdateLastActivityAt(t *testing.T) {
|
func TestSessionStoreUpdateLastActivityAt(t *testing.T) {
|
||||||
Setup()
|
Setup()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user