[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)
|
groupTeam, response := th.Client.LinkGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
|
||||||
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
assert.Equal(t, http.StatusCreated, response.StatusCode)
|
||||||
|
assert.Equal(t, th.BasicChannel.TeamId, groupTeam.TeamID)
|
||||||
assert.NotNil(t, groupTeam)
|
assert.NotNil(t, groupTeam)
|
||||||
|
|
||||||
_, response = th.SystemAdminClient.UpdateChannelRoles(th.BasicChannel.Id, th.BasicUser.Id, "")
|
_, 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, g.Id, groupSyncable.GroupId)
|
||||||
assert.Equal(t, th.BasicChannel.Id, groupSyncable.SyncableId)
|
assert.Equal(t, th.BasicChannel.Id, groupSyncable.SyncableId)
|
||||||
|
assert.Equal(t, th.BasicChannel.TeamId, groupSyncable.TeamID)
|
||||||
assert.Equal(t, model.GroupSyncableTypeChannel, groupSyncable.Type)
|
assert.Equal(t, model.GroupSyncableTypeChannel, groupSyncable.Type)
|
||||||
|
|
||||||
patch.AutoAdd = model.NewBool(true)
|
patch.AutoAdd = model.NewBool(true)
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ func (syncable *GroupSyncable) UnmarshalJSON(b []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var channelId string
|
||||||
|
var teamId string
|
||||||
for key, value := range kvp {
|
for key, value := range kvp {
|
||||||
switch key {
|
switch key {
|
||||||
case "team_id":
|
case "team_id":
|
||||||
syncable.SyncableId = value.(string)
|
teamId = value.(string)
|
||||||
syncable.Type = GroupSyncableTypeTeam
|
|
||||||
case "channel_id":
|
case "channel_id":
|
||||||
syncable.SyncableId = value.(string)
|
channelId = value.(string)
|
||||||
syncable.Type = GroupSyncableTypeChannel
|
|
||||||
case "group_id":
|
case "group_id":
|
||||||
syncable.GroupId = value.(string)
|
syncable.GroupId = value.(string)
|
||||||
case "auto_add":
|
case "auto_add":
|
||||||
@@ -75,23 +75,32 @@ func (syncable *GroupSyncable) UnmarshalJSON(b []byte) error {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if channelId != "" {
|
||||||
|
syncable.TeamID = teamId
|
||||||
|
syncable.SyncableId = channelId
|
||||||
|
syncable.Type = GroupSyncableTypeChannel
|
||||||
|
} else {
|
||||||
|
syncable.SyncableId = teamId
|
||||||
|
syncable.Type = GroupSyncableTypeTeam
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
||||||
type Alias GroupSyncable
|
type Alias GroupSyncable
|
||||||
|
|
||||||
switch syncable.Type {
|
switch syncable.Type {
|
||||||
case GroupSyncableTypeTeam:
|
case GroupSyncableTypeTeam:
|
||||||
return json.Marshal(&struct {
|
return json.Marshal(&struct {
|
||||||
TeamID string `json:"team_id"`
|
TeamID string `json:"team_id"`
|
||||||
TeamDisplayName string `json:"team_display_name,omitempty"`
|
TeamDisplayName string `json:"team_display_name,omitempty"`
|
||||||
TeamType string `json:"team_type,omitempty"`
|
TeamType string `json:"team_type,omitempty"`
|
||||||
|
Type GroupSyncableType `json:"type,omitempty"`
|
||||||
*Alias
|
*Alias
|
||||||
}{
|
}{
|
||||||
TeamDisplayName: syncable.TeamDisplayName,
|
TeamDisplayName: syncable.TeamDisplayName,
|
||||||
TeamType: syncable.TeamType,
|
TeamType: syncable.TeamType,
|
||||||
TeamID: syncable.SyncableId,
|
TeamID: syncable.SyncableId,
|
||||||
|
Type: syncable.Type,
|
||||||
Alias: (*Alias)(syncable),
|
Alias: (*Alias)(syncable),
|
||||||
})
|
})
|
||||||
case GroupSyncableTypeChannel:
|
case GroupSyncableTypeChannel:
|
||||||
@@ -99,6 +108,7 @@ func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
|||||||
ChannelID string `json:"channel_id"`
|
ChannelID string `json:"channel_id"`
|
||||||
ChannelDisplayName string `json:"channel_display_name,omitempty"`
|
ChannelDisplayName string `json:"channel_display_name,omitempty"`
|
||||||
ChannelType string `json:"channel_type,omitempty"`
|
ChannelType string `json:"channel_type,omitempty"`
|
||||||
|
Type GroupSyncableType `json:"type,omitempty"`
|
||||||
|
|
||||||
TeamID string `json:"team_id,omitempty"`
|
TeamID string `json:"team_id,omitempty"`
|
||||||
TeamDisplayName string `json:"team_display_name,omitempty"`
|
TeamDisplayName string `json:"team_display_name,omitempty"`
|
||||||
@@ -109,6 +119,7 @@ func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
|
|||||||
ChannelID: syncable.SyncableId,
|
ChannelID: syncable.SyncableId,
|
||||||
ChannelDisplayName: syncable.ChannelDisplayName,
|
ChannelDisplayName: syncable.ChannelDisplayName,
|
||||||
ChannelType: syncable.ChannelType,
|
ChannelType: syncable.ChannelType,
|
||||||
|
Type: syncable.Type,
|
||||||
|
|
||||||
TeamID: syncable.TeamID,
|
TeamID: syncable.TeamID,
|
||||||
TeamDisplayName: syncable.TeamDisplayName,
|
TeamDisplayName: syncable.TeamDisplayName,
|
||||||
|
|||||||
@@ -479,11 +479,13 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
|
|||||||
|
|
||||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||||
case model.GroupSyncableTypeChannel:
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||||
|
groupSyncable.TeamID = channel.TeamId
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
||||||
}
|
}
|
||||||
@@ -661,7 +663,16 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable)
|
|||||||
case model.GroupSyncableTypeTeam:
|
case model.GroupSyncableTypeTeam:
|
||||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||||
case model.GroupSyncableTypeChannel:
|
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))
|
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||||
|
|
||||||
|
groupSyncable.TeamID = channel.TeamId
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
return nil, fmt.Errorf("invalid GroupSyncableType: %s", groupSyncable.Type)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user