Skip to content

Commit

Permalink
Merge pull request #982 from traPtitech/fix/933
Browse files Browse the repository at this point in the history
親チャンネル変更時の深さ判定を修正
  • Loading branch information
wtks authored Jul 29, 2020
2 parents dc9999a + 4e618c8 commit 7d5f67c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion service/channel/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ func (m *managerImpl) UpdateChannel(id uuid.UUID, args repository.UpdateChannelA
return ErrTooDeepChannel // ループ検出
}
}
if len(ascs)+1+m.T.getChannelDepth(ch.ID) > m.MaxChannelDepth {
// 親チャンネル + 自分を含めた子チャンネルの深さ
if len(ascs)+m.T.getChannelDepth(ch.ID) > m.MaxChannelDepth {
return ErrTooDeepChannel
}
}
Expand Down
16 changes: 16 additions & 0 deletions service/channel/manager_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/traPtitech/traQ/utils/random"
"github.com/traPtitech/traQ/utils/set"
"go.uber.org/zap"
"sort"
"strconv"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -457,6 +459,13 @@ func TestManagerImpl_UpdateChannel(t *testing.T) {
Parent: optional.UUIDFrom(pubChannelRootUUID),
},
},
{
ID: cABCE,
Args: repository.UpdateChannelArgs{
UpdaterID: uuid.Must(uuid.NewV4()),
Parent: optional.UUIDFrom(cABCD),
},
},
{
ID: cEFGHI,
Args: repository.UpdateChannelArgs{
Expand All @@ -470,6 +479,7 @@ func TestManagerImpl_UpdateChannel(t *testing.T) {
},
}
for i, c := range cases {
c := c
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
Expand Down Expand Up @@ -547,6 +557,12 @@ func TestManagerImpl_UpdateChannel(t *testing.T) {
if assert.NoError(t, err) {
v, err := cm.GetChannel(c.ID)
require.NoError(t, err)
sort.Slice(v.ChildrenID, func(i, j int) bool {
return strings.Compare(v.ChildrenID[i].String(), v.ChildrenID[j].String()) > 0
})
sort.Slice(new.ChildrenID, func(i, j int) bool {
return strings.Compare(new.ChildrenID[i].String(), new.ChildrenID[j].String()) > 0
})
assert.EqualValues(t, &new, v)
}
})
Expand Down

0 comments on commit 7d5f67c

Please sign in to comment.