[MM-34303] Add team ID to response when linking a channel to a group (#17576)
* add team ID to channel group response Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -193,6 +193,7 @@ func TestLinkGroupChannel(t *testing.T) {
|
||||
|
||||
groupTeam, response := th.Client.LinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
||||
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
||||
assert.Equal(t, th.BasicChannel.TeamId, groupTeam.TeamID)
|
||||
assert.NotNil(t, groupTeam)
|
||||
|
||||
_, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
@@ -623,6 +624,7 @@ func TestPatchGroupChannel(t *testing.T) {
|
||||
|
||||
assert.Equal(t, g.Id, groupSyncable.GroupId)
|
||||
assert.Equal(t, th.BasicChannel.Id, groupSyncable.SyncableId)
|
||||
assert.Equal(t, th.BasicChannel.TeamId, groupSyncable.TeamID)
|
||||
assert.Equal(t, model.GroupSyncableTypeChannel, groupSyncable.Type)
|
||||
|
||||
patch.AutoAdd = model.NewBool(true)
|
||||
|
||||
@@ -60,14 +60,14 @@ func (syncable *GroupSyncable) UnmarshalJSON(b []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var channelId string
|
||||
var teamId string
|
||||
for key, value := range kvp {
|
||||
switch key {
|
||||
case "team_id":
|
||||
syncable.SyncableId = value.(string)
|
||||
syncable.Type = GroupSyncableTypeTeam
|
||||
teamId = value.(string)
|
||||
case "channel_id":
|
||||
syncable.SyncableId = value.(string)
|
||||
syncable.Type = GroupSyncableTypeChannel
|
||||
channelId = value.(string)
|
||||
case "group_id":
|
||||
syncable.GroupId = value.(string)
|
||||
case "auto_add":
|
||||
@@ -75,30 +75,40 @@ func (syncable *GroupSyncable) UnmarshalJSON(b []byte) error {
|
||||
default:
|
||||
}
|
||||
}
|
||||
if channelId != "" {
|
||||
syncable.TeamID = teamId
|
||||
syncable.SyncableId = channelId
|
||||
syncable.Type = GroupSyncableTypeChannel
|
||||
} else {
|
||||
syncable.SyncableId = teamId
|
||||
syncable.Type = GroupSyncableTypeTeam
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
||||
type Alias GroupSyncable
|
||||
|
||||
switch syncable.Type {
|
||||
case GroupSyncableTypeTeam:
|
||||
return json.Marshal(&struct {
|
||||
TeamID string `json:"team_id"`
|
||||
TeamDisplayName string `json:"team_display_name,omitempty"`
|
||||
TeamType string `json:"team_type,omitempty"`
|
||||
TeamID string `json:"team_id"`
|
||||
TeamDisplayName string `json:"team_display_name,omitempty"`
|
||||
TeamType string `json:"team_type,omitempty"`
|
||||
Type GroupSyncableType `json:"type,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
TeamDisplayName: syncable.TeamDisplayName,
|
||||
TeamType: syncable.TeamType,
|
||||
TeamID: syncable.SyncableId,
|
||||
Type: syncable.Type,
|
||||
Alias: (*Alias)(syncable),
|
||||
})
|
||||
case GroupSyncableTypeChannel:
|
||||
return json.Marshal(&struct {
|
||||
ChannelID string `json:"channel_id"`
|
||||
ChannelDisplayName string `json:"channel_display_name,omitempty"`
|
||||
ChannelType string `json:"channel_type,omitempty"`
|
||||
ChannelID string `json:"channel_id"`
|
||||
ChannelDisplayName string `json:"channel_display_name,omitempty"`
|
||||
ChannelType string `json:"channel_type,omitempty"`
|
||||
Type GroupSyncableType `json:"type,omitempty"`
|
||||
|
||||
TeamID string `json:"team_id,omitempty"`
|
||||
TeamDisplayName string `json:"team_display_name,omitempty"`
|
||||
@@ -109,6 +119,7 @@ func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
||||
ChannelID: syncable.SyncableId,
|
||||
ChannelDisplayName: syncable.ChannelDisplayName,
|
||||
ChannelType: syncable.ChannelType,
|
||||
Type: syncable.Type,
|
||||
|
||||
TeamID: syncable.TeamID,
|
||||
TeamDisplayName: syncable.TeamDisplayName,
|
||||
|
||||
@@ -479,11 +479,13 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
if _, err := s.Channel().Get(groupSyncable.SyncableId, false); err != nil {
|
||||
var channel *model.Channel
|
||||
channel, err := s.Channel().Get(groupSyncable.SyncableId, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||
groupSyncable.TeamID = channel.TeamId
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
||||
}
|
||||
@@ -661,7 +663,16 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
// We need to get the TeamId so redux can manage channels when teams are unlinked
|
||||
var channel *model.Channel
|
||||
channel, channelErr := s.Channel().Get(groupSyncable.SyncableId, false)
|
||||
if channelErr != nil {
|
||||
return nil, channelErr
|
||||
}
|
||||
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||
|
||||
groupSyncable.TeamID = channel.TeamId
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user