Skip to content

Commit

Permalink
Merge b511c3d into f6d22ee
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum committed Feb 23, 2017
2 parents f6d22ee + b511c3d commit 552a817
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 66 deletions.
79 changes: 56 additions & 23 deletions api/channel_test.go
Expand Up @@ -1536,54 +1536,73 @@ func TestUpdateNotifyProps(t *testing.T) {
data := make(map[string]string)
data["channel_id"] = channel1.Id
data["user_id"] = user.Id
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION

//timeBeforeUpdate := model.GetMillis()
time.Sleep(100 * time.Millisecond)

// test updating desktop
if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
} else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
} else if notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_ALL {
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps[model.MARK_UNREAD_NOTIFY_PROP])
}

// test an empty update
delete(data, "desktop")
delete(data, model.DESKTOP_NOTIFY_PROP)

if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
} else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_ALL {
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps[model.MARK_UNREAD_NOTIFY_PROP])
} else if notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps[model.DESKTOP_NOTIFY_PROP])
}

// test updating mark unread
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION

if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_MENTION {
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
} else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
} else if notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps[model.DESKTOP_NOTIFY_PROP])
}

// test updating both
data["desktop"] = model.CHANNEL_NOTIFY_NONE
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_NONE
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION

if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_NONE {
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_NONE {
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
} else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
} else if notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_MENTION {
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
}

// test updating push notification preferences
delete(data, model.DESKTOP_NOTIFY_PROP)
delete(data, model.MARK_UNREAD_NOTIFY_PROP)
data[model.PUSH_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.PUSH_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
t.Fatal("NotifyProps[\"push\"] did not update properly")
}

// test updating email preferences
delete(data, model.PUSH_NOTIFY_PROP)
data[model.EMAIL_NOTIFY_PROP] = "true"
if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.EMAIL_NOTIFY_PROP] != "true" {
t.Fatal("NotifyProps[\"email\"] did not update properly")
}

// test error cases
data["user_id"] = "junk"
if _, err := Client.UpdateNotifyProps(data); err == nil {
Expand All @@ -1606,24 +1625,38 @@ func TestUpdateNotifyProps(t *testing.T) {
t.Fatal("Should have errored - bad channel id")
}

data["desktop"] = "junk"
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_ALL
data[model.DESKTOP_NOTIFY_PROP] = "junk"
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_ALL
if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad desktop notify level")
}

data["desktop"] = model.CHANNEL_NOTIFY_ALL
data["mark_unread"] = "junk"
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
data[model.MARK_UNREAD_NOTIFY_PROP] = "junk"
if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad mark unread level")
}

data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_ALL
data[model.PUSH_NOTIFY_PROP] = "junk"
data[model.EMAIL_NOTIFY_PROP] = "true"
if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad push level")
}

data[model.PUSH_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
data[model.EMAIL_NOTIFY_PROP] = "junk"
if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad email notification option")
}

th.LoginBasic2()

data["channel_id"] = channel1.Id
data["user_id"] = user2.Id
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - user not in channel")
}
Expand Down
17 changes: 13 additions & 4 deletions app/channel.go
Expand Up @@ -226,18 +226,27 @@ func UpdateChannelMemberNotifyProps(data map[string]string, channelId string, us
}

// update whichever notify properties have been provided, but don't change the others
if markUnread, exists := data["mark_unread"]; exists {
member.NotifyProps["mark_unread"] = markUnread
if markUnread, exists := data[model.MARK_UNREAD_NOTIFY_PROP]; exists {
member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = markUnread
}

if desktop, exists := data["desktop"]; exists {
member.NotifyProps["desktop"] = desktop
if desktop, exists := data[model.DESKTOP_NOTIFY_PROP]; exists {
member.NotifyProps[model.DESKTOP_NOTIFY_PROP] = desktop
}

if email, exists := data[model.EMAIL_NOTIFY_PROP]; exists {
member.NotifyProps[model.EMAIL_NOTIFY_PROP] = email
}

if push, exists := data[model.PUSH_NOTIFY_PROP]; exists {
member.NotifyProps[model.PUSH_NOTIFY_PROP] = push
}

if result := <-Srv.Store.Channel().UpdateMember(member); result.Err != nil {
return nil, result.Err
} else {
InvalidateCacheForUser(userId)
InvalidateCacheForChannelMembersNotifyProps(channelId)
return member, nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/import.go
Expand Up @@ -581,11 +581,11 @@ func ImportUserChannels(user *model.User, team *model.Team, data *[]UserChannelI
notifyProps := member.NotifyProps

if cdata.NotifyProps.Desktop != nil {
notifyProps["desktop"] = *cdata.NotifyProps.Desktop
notifyProps[model.DESKTOP_NOTIFY_PROP] = *cdata.NotifyProps.Desktop
}

if cdata.NotifyProps.MarkUnread != nil {
notifyProps["mark_unread"] = *cdata.NotifyProps.MarkUnread
notifyProps[model.MARK_UNREAD_NOTIFY_PROP] = *cdata.NotifyProps.MarkUnread
}

if _, err := UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id); err != nil {
Expand Down
54 changes: 27 additions & 27 deletions app/import_test.go
Expand Up @@ -1157,7 +1157,7 @@ func TestImportImportUser(t *testing.T) {
// Check channel member properties.
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
t.Fatalf("Failed to get channel member from database.")
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps["desktop"] != "default" || channelMember.NotifyProps["mark_unread"] != "all" {
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] != "default" || channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] != "all" {
t.Fatalf("Channel member properties not as expected")
}

Expand All @@ -1171,8 +1171,8 @@ func TestImportImportUser(t *testing.T) {
Name: &channelName,
Roles: ptrStr("channel_user channel_admin"),
NotifyProps: &UserChannelNotifyPropsImportData{
Desktop: ptrStr("mention"),
MarkUnread: ptrStr("mention"),
Desktop: ptrStr(model.USER_NOTIFY_MENTION),
MarkUnread: ptrStr(model.USER_NOTIFY_MENTION),
},
},
},
Expand All @@ -1191,7 +1191,7 @@ func TestImportImportUser(t *testing.T) {

if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
t.Fatalf("Failed to get channel member Desktop from database.")
} else if channelMember.Roles != "channel_user channel_admin" && channelMember.NotifyProps["desktop"] == "mention" && channelMember.NotifyProps["mark_unread"] == "mention" {
} else if channelMember.Roles != "channel_user channel_admin" && channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] == model.USER_NOTIFY_MENTION && channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.USER_NOTIFY_MENTION {
t.Fatalf("Channel member properties not as expected")
}

Expand All @@ -1211,27 +1211,27 @@ func TestImportImportUser(t *testing.T) {
// Add a user with some preferences.
username = model.NewId()
data = UserImportData{
Username: &username,
Email: ptrStr(model.NewId() + "@example.com"),
Theme: ptrStr(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
SelectedFont: ptrStr("Roboto Slab"),
UseMilitaryTime: ptrStr("true"),
NameFormat: ptrStr("nickname_full_name"),
CollapsePreviews: ptrStr("true"),
MessageDisplay: ptrStr("compact"),
Username: &username,
Email: ptrStr(model.NewId() + "@example.com"),
Theme: ptrStr(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
SelectedFont: ptrStr("Roboto Slab"),
UseMilitaryTime: ptrStr("true"),
NameFormat: ptrStr("nickname_full_name"),
CollapsePreviews: ptrStr("true"),
MessageDisplay: ptrStr("compact"),
ChannelDisplayMode: ptrStr("centered"),
}
if err := ImportUser(&data, false); err != nil {
t.Fatalf("Should have succeeded.")
}

// Check their values.
user, err = GetUserByUsername(username);
user, err = GetUserByUsername(username)
if err != nil {
t.Fatalf("Failed to get user from database.")
}

if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
t.Fatalf("Failed to get theme category preferences")
} else {
preferences := res.Data.(model.Preferences)
Expand All @@ -1242,7 +1242,7 @@ func TestImportImportUser(t *testing.T) {
}
}

if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
t.Fatalf("Failed to get display category preferences")
} else {
preferences := res.Data.(model.Preferences)
Expand Down Expand Up @@ -1275,22 +1275,22 @@ func TestImportImportUser(t *testing.T) {

// Change those preferences.
data = UserImportData{
Username: &username,
Email: ptrStr(model.NewId() + "@example.com"),
Theme: ptrStr(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
SelectedFont: ptrStr("Lato"),
UseMilitaryTime: ptrStr("false"),
NameFormat: ptrStr("full_name"),
CollapsePreviews: ptrStr("false"),
MessageDisplay: ptrStr("clean"),
Username: &username,
Email: ptrStr(model.NewId() + "@example.com"),
Theme: ptrStr(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
SelectedFont: ptrStr("Lato"),
UseMilitaryTime: ptrStr("false"),
NameFormat: ptrStr("full_name"),
CollapsePreviews: ptrStr("false"),
MessageDisplay: ptrStr("clean"),
ChannelDisplayMode: ptrStr("full"),
}
if err := ImportUser(&data, false); err != nil {
t.Fatalf("Should have succeeded.")
}

// Check their values again.
if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
t.Fatalf("Failed to get theme category preferences")
} else {
preferences := res.Data.(model.Preferences)
Expand All @@ -1301,7 +1301,7 @@ func TestImportImportUser(t *testing.T) {
}
}

if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
t.Fatalf("Failed to get display category preferences")
} else {
preferences := res.Data.(model.Preferences)
Expand Down Expand Up @@ -1388,7 +1388,7 @@ func TestImportBulkImport(t *testing.T) {
}

// Run bulk import using valid JSON but missing version line at the start.
data3:= `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
data3 := `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
{"type": "channel", "channel": {"type": "O", "display_name": "xr6m6udffngark2uekvr3hoeny", "team": "` + teamName + `", "name": "` + channelName + `"}}
{"type": "user", "user": {"username": "kufjgnkxkrhhfgbrip6qxkfsaa", "email": "kufjgnkxkrhhfgbrip6qxkfsaa@example.com"}}
{"type": "user", "user": {"username": "bwshaim6qnc2ne7oqkd5b2s2rq", "email": "bwshaim6qnc2ne7oqkd5b2s2rq@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}]}]}}`
Expand All @@ -1401,7 +1401,7 @@ func TestImportProcessImportDataFileVersionLine(t *testing.T) {
_ = Setup()

data := LineImportData{
Type: "version",
Type: "version",
Version: ptrInt(1),
}
if version, err := processImportDataFileVersionLine(data); err != nil || version != 1 {
Expand Down

0 comments on commit 552a817

Please sign in to comment.