summaryrefslogtreecommitdiffstats
path: root/store/sql_team_store.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-10-27 22:18:52 -0700
committer=Corey Hulen <corey@hulen.com>2015-10-27 22:18:52 -0700
commitbb25056d9afca501f147450466aaeecca9fef66f (patch)
tree64f7b9eeb590e2cb0fe13b7a2eb55ddb798b30be /store/sql_team_store.go
parent940f5c29c7c35a66f0b37f62831809e3633a5ea9 (diff)
downloadchat-bb25056d9afca501f147450466aaeecca9fef66f.tar.gz
chat-bb25056d9afca501f147450466aaeecca9fef66f.tar.bz2
chat-bb25056d9afca501f147450466aaeecca9fef66f.zip
PLT-340
Diffstat (limited to 'store/sql_team_store.go')
-rw-r--r--store/sql_team_store.go81
1 files changed, 80 insertions, 1 deletions
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index e5a25b80d..cacc8595e 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -23,6 +23,7 @@ func NewSqlTeamStore(sqlStore *SqlStore) TeamStore {
table.ColMap("Email").SetMaxSize(128)
table.ColMap("CompanyName").SetMaxSize(64)
table.ColMap("AllowedDomains").SetMaxSize(500)
+ table.ColMap("InviteId").SetMaxSize(32)
}
return s
@@ -38,6 +39,7 @@ func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
func (s SqlTeamStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_teams_name", "Teams", "Name")
+ s.CreateIndexIfNotExists("idx_teams_invite_id", "Teams", "InviteId")
}
func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
@@ -101,6 +103,7 @@ func (s SqlTeamStore) Update(team *model.Team) StoreChannel {
} else {
oldTeam := oldResult.(*model.Team)
team.CreateAt = oldTeam.CreateAt
+ team.UpdateAt = model.GetMillis()
team.Name = oldTeam.Name
if count, err := s.GetMaster().Update(team); err != nil {
@@ -150,7 +153,12 @@ func (s SqlTeamStore) Get(id string) StoreChannel {
} else if obj == nil {
result.Err = model.NewAppError("SqlTeamStore.Get", "We couldn't find the existing team", "id="+id)
} else {
- result.Data = obj.(*model.Team)
+ team := obj.(*model.Team)
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+
+ result.Data = team
}
storeChannel <- result
@@ -160,6 +168,35 @@ func (s SqlTeamStore) Get(id string) StoreChannel {
return storeChannel
}
+func (s SqlTeamStore) GetByInviteId(inviteId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ team := model.Team{}
+
+ if err := s.GetReplica().SelectOne(&team, "SELECT * FROM Teams WHERE Id = :InviteId OR InviteId = :InviteId", map[string]interface{}{"InviteId": inviteId}); err != nil {
+ result.Err = model.NewAppError("SqlTeamStore.GetByInviteId", "We couldn't find the existing team", "inviteId="+inviteId+", "+err.Error())
+ }
+
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+
+ if len(inviteId) == 0 || team.InviteId != inviteId {
+ result.Err = model.NewAppError("SqlTeamStore.GetByInviteId", "We couldn't find the existing team", "inviteId="+inviteId)
+ }
+
+ result.Data = &team
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlTeamStore) GetByName(name string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -172,6 +209,10 @@ func (s SqlTeamStore) GetByName(name string) StoreChannel {
result.Err = model.NewAppError("SqlTeamStore.GetByName", "We couldn't find the existing team", "name="+name+", "+err.Error())
}
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+
result.Data = &team
storeChannel <- result
@@ -192,6 +233,12 @@ func (s SqlTeamStore) GetTeamsForEmail(email string) StoreChannel {
result.Err = model.NewAppError("SqlTeamStore.GetTeamsForEmail", "We encounted a problem when looking up teams", "email="+email+", "+err.Error())
}
+ for _, team := range data {
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+ }
+
result.Data = data
storeChannel <- result
@@ -212,6 +259,38 @@ func (s SqlTeamStore) GetAll() StoreChannel {
result.Err = model.NewAppError("SqlTeamStore.GetAllTeams", "We could not get all teams", err.Error())
}
+ for _, team := range data {
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+ }
+
+ result.Data = data
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlTeamStore) GetAllTeamListing() StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var data []*model.Team
+ if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams WHERE AllowTeamListing = 1"); err != nil {
+ result.Err = model.NewAppError("SqlTeamStore.GetAllTeams", "We could not get all teams", err.Error())
+ }
+
+ for _, team := range data {
+ if len(team.InviteId) == 0 {
+ team.InviteId = team.Id
+ }
+ }
+
result.Data = data
storeChannel <- result