[release-10.11] Restrict group_constrained to channels that support group sync (#36916)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
56098dd6f0
Коммит
beaa59db54
@@ -329,6 +329,10 @@ func (o *Channel) IsValid() *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if o.IsGroupConstrained() && !o.SupportsGroupSync() {
|
||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.group_constrained.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -356,6 +360,11 @@ func (o *Channel) IsGroupOrDirect() bool {
|
||||
return o.Type == ChannelTypeDirect || o.Type == ChannelTypeGroup
|
||||
}
|
||||
|
||||
// SupportsGroupSync reports whether group_constrained is meaningful for the channel type.
|
||||
func (o *Channel) SupportsGroupSync() bool {
|
||||
return o.Type == ChannelTypeOpen || o.Type == ChannelTypePrivate
|
||||
}
|
||||
|
||||
func (o *Channel) IsOpen() bool {
|
||||
return o.Type == ChannelTypeOpen
|
||||
}
|
||||
|
||||
@@ -35,6 +35,47 @@ func TestChannelPatch(t *testing.T) {
|
||||
require.Equal(t, *p.GroupConstrained, *o.GroupConstrained)
|
||||
}
|
||||
|
||||
func TestChannelSupportsGroupSync(t *testing.T) {
|
||||
require.True(t, (&Channel{Type: ChannelTypeOpen}).SupportsGroupSync())
|
||||
require.True(t, (&Channel{Type: ChannelTypePrivate}).SupportsGroupSync())
|
||||
require.False(t, (&Channel{Type: ChannelTypeDirect}).SupportsGroupSync())
|
||||
require.False(t, (&Channel{Type: ChannelTypeGroup}).SupportsGroupSync())
|
||||
}
|
||||
|
||||
func TestChannelIsValidGroupConstrained(t *testing.T) {
|
||||
base := Channel{
|
||||
Id: NewId(),
|
||||
CreateAt: GetMillis(),
|
||||
UpdateAt: GetMillis(),
|
||||
DisplayName: "x",
|
||||
Name: "valid-name",
|
||||
Header: "h",
|
||||
Purpose: "p",
|
||||
}
|
||||
|
||||
t.Run("group_constrained is allowed on public and private channels", func(t *testing.T) {
|
||||
c := base
|
||||
c.GroupConstrained = NewPointer(true)
|
||||
|
||||
c.Type = ChannelTypeOpen
|
||||
require.Nil(t, c.IsValid())
|
||||
|
||||
c.Type = ChannelTypePrivate
|
||||
require.Nil(t, c.IsValid())
|
||||
})
|
||||
|
||||
t.Run("group_constrained is rejected on direct and group channels", func(t *testing.T) {
|
||||
c := base
|
||||
c.GroupConstrained = NewPointer(true)
|
||||
|
||||
c.Type = ChannelTypeDirect
|
||||
require.NotNil(t, c.IsValid())
|
||||
|
||||
c.Type = ChannelTypeGroup
|
||||
require.NotNil(t, c.IsValid())
|
||||
})
|
||||
}
|
||||
|
||||
func TestChannelIsValid(t *testing.T) {
|
||||
o := Channel{}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user