summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-10-15 14:52:59 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-15 15:16:34 -0400
commit4b99e1714029689f27ebf4cb078c60367b0594a4 (patch)
treeb8b9e453ef3d2847867263f2e8ae3630902fb859 /api
parentbd2fec0fb16783049ec555d8015f49a0ed3ccf80 (diff)
downloadchat-4b99e1714029689f27ebf4cb078c60367b0594a4.tar.gz
chat-4b99e1714029689f27ebf4cb078c60367b0594a4.tar.bz2
chat-4b99e1714029689f27ebf4cb078c60367b0594a4.zip
Removed preference migration code
Diffstat (limited to 'api')
-rw-r--r--api/preference.go51
-rw-r--r--api/preference_test.go48
-rw-r--r--api/user.go39
3 files changed, 39 insertions, 99 deletions
diff --git a/api/preference.go b/api/preference.go
index 88cb132f8..3a0535473 100644
--- a/api/preference.go
+++ b/api/preference.go
@@ -52,61 +52,10 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
data := result.Data.(model.Preferences)
- data = transformPreferences(c, data, category)
-
w.Write([]byte(data.ToJson()))
}
}
-func transformPreferences(c *Context, preferences model.Preferences, category string) model.Preferences {
- if len(preferences) == 0 && category == model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW {
- // add direct channels for a user that existed before preferences were added
- preferences = addDirectChannels(c.Session.UserId, c.Session.TeamId)
- }
-
- return preferences
-}
-
-func addDirectChannels(userId, teamId string) model.Preferences {
- var profiles map[string]*model.User
- if result := <-Srv.Store.User().GetProfiles(teamId); result.Err != nil {
- l4g.Error("Failed to add direct channel preferences for user user_id=%s, team_id=%s, err=%v", userId, teamId, result.Err.Error())
- return model.Preferences{}
- } else {
- profiles = result.Data.(map[string]*model.User)
- }
-
- var preferences model.Preferences
-
- for id := range profiles {
- if id == userId {
- continue
- }
-
- profile := profiles[id]
-
- preference := model.Preference{
- UserId: userId,
- Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW,
- Name: profile.Id,
- Value: "true",
- }
-
- preferences = append(preferences, preference)
-
- if len(preferences) >= 10 {
- break
- }
- }
-
- if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
- l4g.Error("Failed to add direct channel preferences for user user_id=%s, eam_id=%s, err=%v", userId, teamId, result.Err.Error())
- return model.Preferences{}
- } else {
- return preferences
- }
-}
-
func getPreference(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
category := params["category"]
diff --git a/api/preference_test.go b/api/preference_test.go
index 318ce9582..dfdf8b581 100644
--- a/api/preference_test.go
+++ b/api/preference_test.go
@@ -113,54 +113,6 @@ func TestGetPreferenceCategory(t *testing.T) {
}
}
-func TestTransformPreferences(t *testing.T) {
- Setup()
-
- 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)
-
- user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
- user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
- store.Must(Srv.Store.User().VerifyEmail(user1.Id))
-
- for i := 0; i < 5; i++ {
- user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
- Client.Must(Client.CreateUser(user, ""))
- }
-
- Client.Must(Client.LoginByEmail(team.Name, user1.Email, "pwd"))
-
- if result, err := Client.GetPreferenceCategory(model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW); err != nil {
- t.Fatal(err)
- } else if data := result.Data.(model.Preferences); len(data) != 5 {
- t.Fatal("received the wrong number of direct channels")
- }
-
- user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
- user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
- store.Must(Srv.Store.User().VerifyEmail(user2.Id))
-
- for i := 0; i < 10; i++ {
- user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
- Client.Must(Client.CreateUser(user, ""))
- }
-
- // make sure user1's preferences don't change
- if result, err := Client.GetPreferenceCategory(model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW); err != nil {
- t.Fatal(err)
- } else if data := result.Data.(model.Preferences); len(data) != 5 {
- t.Fatal("received the wrong number of direct channels")
- }
-
- Client.Must(Client.LoginByEmail(team.Name, user2.Email, "pwd"))
-
- if result, err := Client.GetPreferenceCategory(model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW); err != nil {
- t.Fatal(err)
- } else if data := result.Data.(model.Preferences); len(data) != 10 {
- t.Fatal("received the wrong number of direct channels")
- }
-}
-
func TestGetPreference(t *testing.T) {
Setup()
diff --git a/api/user.go b/api/user.go
index 146ede015..1d628d301 100644
--- a/api/user.go
+++ b/api/user.go
@@ -237,6 +237,45 @@ func fireAndForgetWelcomeEmail(userId, email, teamName, teamDisplayName, siteURL
}()
}
+func addDirectChannelsAndForget(user *model.User) {
+ go func() {
+ var profiles map[string]*model.User
+ if result := <-Srv.Store.User().GetProfiles(user.TeamId); result.Err != nil {
+ l4g.Error("Failed to add direct channel preferences for user user_id=%s, team_id=%s, err=%v", user.Id, user.TeamId, result.Err.Error())
+ return
+ } else {
+ profiles = result.Data.(map[string]*model.User)
+ }
+
+ var preferences model.Preferences
+
+ for id := range profiles {
+ if id == user.Id {
+ continue
+ }
+
+ profile := profiles[id]
+
+ preference := model.Preference{
+ UserId: user.Id,
+ Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW,
+ Name: profile.Id,
+ Value: "true",
+ }
+
+ preferences = append(preferences, preference)
+
+ if len(preferences) >= 10 {
+ break
+ }
+ }
+
+ if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil {
+ l4g.Error("Failed to add direct channel preferences for new user user_id=%s, eam_id=%s, err=%v", user.Id, user.TeamId, result.Err.Error())
+ }
+ }()
+}
+
func FireAndForgetVerifyEmail(userId, userEmail, teamName, teamDisplayName, siteURL, teamURL string) {
go func() {