Merge pull request #1078 from hmhealey/plt701
PLT-701 Removed preference migration code
Этот коммит содержится в:
@@ -52,61 +52,10 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
data := result.Data.(model.Preferences)
|
data := result.Data.(model.Preferences)
|
||||||
|
|
||||||
data = transformPreferences(c, data, category)
|
|
||||||
|
|
||||||
w.Write([]byte(data.ToJson()))
|
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) {
|
func getPreference(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
category := params["category"]
|
category := params["category"]
|
||||||
|
|||||||
@@ -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) {
|
func TestGetPreference(t *testing.T) {
|
||||||
Setup()
|
Setup()
|
||||||
|
|
||||||
|
|||||||
43
api/user.go
43
api/user.go
@@ -198,7 +198,9 @@ func CreateUser(c *Context, team *model.Team, user *model.User) *model.User {
|
|||||||
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
|
l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fireAndForgetWelcomeEmail(result.Data.(*model.User).Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), user.EmailVerified)
|
fireAndForgetWelcomeEmail(ruser.Id, ruser.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team), user.EmailVerified)
|
||||||
|
|
||||||
|
addDirectChannelsAndForget(ruser)
|
||||||
|
|
||||||
if user.EmailVerified {
|
if user.EmailVerified {
|
||||||
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
||||||
@@ -237,6 +239,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) {
|
func FireAndForgetVerifyEmail(userId, userEmail, teamName, teamDisplayName, siteURL, teamURL string) {
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user