Implement some team endpoints for APIv4 (#5745)
* Implement PUT /teams/{team_id} endpoint for APIv4
* Implement GET /users/{user_id}/teams/{team_id}/unread endpoint for APIv4
* Implement POST /teams/{team_id}/members/ids endpoint for APIv4
* Remove debug statement
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
5ec49c0db0
Коммит
a284cd8c18
@@ -663,7 +663,7 @@ func (s SqlTeamStore) GetTeamsForUser(userId string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetTeamsUnreadForUser(teamId, userId string) StoreChannel {
|
||||
func (s SqlTeamStore) GetChannelUnreadsForAllTeams(excludeTeamId, userId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
@@ -672,15 +672,50 @@ func (s SqlTeamStore) GetTeamsUnreadForUser(teamId, userId string) StoreChannel
|
||||
var data []*model.ChannelUnread
|
||||
_, err := s.GetReplica().Select(&data,
|
||||
`SELECT
|
||||
Channels.TeamId, Channels.TotalMsgCount, ChannelMembers.MsgCount, ChannelMembers.MentionCount, ChannelMembers.NotifyProps
|
||||
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps
|
||||
FROM
|
||||
Channels, ChannelMembers
|
||||
WHERE
|
||||
Id = ChannelId AND UserId = :UserId AND DeleteAt = 0 AND TeamId != :TeamId`,
|
||||
map[string]interface{}{"UserId": userId, "TeamId": teamId})
|
||||
Id = ChannelId
|
||||
AND UserId = :UserId
|
||||
AND DeleteAt = 0
|
||||
AND TeamId != :TeamId`,
|
||||
map[string]interface{}{"UserId": userId, "TeamId": excludeTeamId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlTeamStore.GetTeamsUnreadForUser", "store.sql_team.get_unread.app_error", nil, "userId="+userId+" "+err.Error())
|
||||
result.Err = model.NewLocAppError("SqlTeamStore.GetChannelUnreadsForAllTeams", "store.sql_team.get_unread.app_error", nil, "userId="+userId+" "+err.Error())
|
||||
} else {
|
||||
result.Data = data
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetChannelUnreadsForTeam(teamId, userId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var data []*model.ChannelUnread
|
||||
_, err := s.GetReplica().Select(&data,
|
||||
`SELECT
|
||||
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps
|
||||
FROM
|
||||
Channels, ChannelMembers
|
||||
WHERE
|
||||
Id = ChannelId
|
||||
AND UserId = :UserId
|
||||
AND TeamId = :TeamId
|
||||
AND DeleteAt = 0`,
|
||||
map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlTeamStore.GetChannelUnreadsForTeam", "store.sql_team.get_unread.app_error", nil, "teamId="+teamId+" "+err.Error())
|
||||
} else {
|
||||
result.Data = data
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ func TestTeamStoreMemberCount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMyTeamMembersUnread(t *testing.T) {
|
||||
func TestGetChannelUnreadsForAllTeams(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
teamId1 := model.NewId()
|
||||
@@ -566,17 +566,17 @@ func TestMyTeamMembersUnread(t *testing.T) {
|
||||
Must(store.Team().SaveMember(m1))
|
||||
Must(store.Team().SaveMember(m2))
|
||||
|
||||
c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
|
||||
c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
|
||||
Must(store.Channel().Save(c1))
|
||||
c2 := &model.Channel{TeamId: m2.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
|
||||
c2 := &model.Channel{TeamId: m2.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
|
||||
Must(store.Channel().Save(c2))
|
||||
|
||||
cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
|
||||
Must(store.Channel().SaveMember(cm1))
|
||||
cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m2.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m2.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
|
||||
Must(store.Channel().SaveMember(cm2))
|
||||
|
||||
if r1 := <-store.Team().GetTeamsUnreadForUser("", uid); r1.Err != nil {
|
||||
if r1 := <-store.Team().GetChannelUnreadsForAllTeams("", uid); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
ms := r1.Data.([]*model.ChannelUnread)
|
||||
@@ -590,9 +590,13 @@ func TestMyTeamMembersUnread(t *testing.T) {
|
||||
if len(membersMap) != 2 {
|
||||
t.Fatal("Should be the unreads for all the teams")
|
||||
}
|
||||
|
||||
if ms[0].MsgCount != 10 {
|
||||
t.Fatal("subtraction failed")
|
||||
}
|
||||
}
|
||||
|
||||
if r2 := <-store.Team().GetTeamsUnreadForUser(teamId1, uid); r2.Err != nil {
|
||||
if r2 := <-store.Team().GetChannelUnreadsForAllTeams(teamId1, uid); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
} else {
|
||||
ms := r2.Data.([]*model.ChannelUnread)
|
||||
@@ -607,9 +611,46 @@ func TestMyTeamMembersUnread(t *testing.T) {
|
||||
if len(membersMap) != 1 {
|
||||
t.Fatal("Should be the unreads for just one team")
|
||||
}
|
||||
|
||||
if ms[0].MsgCount != 10 {
|
||||
t.Fatal("subtraction failed")
|
||||
}
|
||||
}
|
||||
|
||||
if r1 := <-store.Team().RemoveAllMembersByUser(uid); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChannelUnreadsForTeam(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
teamId1 := model.NewId()
|
||||
|
||||
uid := model.NewId()
|
||||
m1 := &model.TeamMember{TeamId: teamId1, UserId: uid}
|
||||
Must(store.Team().SaveMember(m1))
|
||||
|
||||
c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
|
||||
Must(store.Channel().Save(c1))
|
||||
c2 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
|
||||
Must(store.Channel().Save(c2))
|
||||
|
||||
cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
|
||||
Must(store.Channel().SaveMember(cm1))
|
||||
cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
|
||||
Must(store.Channel().SaveMember(cm2))
|
||||
|
||||
if r1 := <-store.Team().GetChannelUnreadsForTeam(m1.TeamId, m1.UserId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
ms := r1.Data.([]*model.ChannelUnread)
|
||||
if len(ms) != 2 {
|
||||
t.Fatal("wrong length")
|
||||
}
|
||||
|
||||
if ms[0].MsgCount != 10 {
|
||||
t.Fatal("subtraction failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ type TeamStore interface {
|
||||
GetTotalMemberCount(teamId string) StoreChannel
|
||||
GetActiveMemberCount(teamId string) StoreChannel
|
||||
GetTeamsForUser(userId string) StoreChannel
|
||||
GetTeamsUnreadForUser(teamId, userId string) StoreChannel
|
||||
GetChannelUnreadsForAllTeams(excludeTeamId, userId string) StoreChannel
|
||||
GetChannelUnreadsForTeam(teamId, userId string) StoreChannel
|
||||
RemoveMember(teamId string, userId string) StoreChannel
|
||||
RemoveAllMembersByTeam(teamId string) StoreChannel
|
||||
RemoveAllMembersByUser(userId string) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user