mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
Merge pull request #2473 from anyproto/fix-restrict-template-creation
Restrict template objects creation
This commit is contained in:
commit
c6161f0685
5 changed files with 25 additions and 25 deletions
|
@ -116,10 +116,8 @@ func (s *service) createObjectInSpace(
|
|||
}
|
||||
details = internalflag.PutToDetails(details, req.InternalFlags)
|
||||
|
||||
if bundle.HasObjectTypeByKey(req.ObjectTypeKey) {
|
||||
if t := bundle.MustGetType(req.ObjectTypeKey); t.RestrictObjectCreation {
|
||||
return "", nil, errors.Wrap(restriction.ErrRestricted, "creation of this object type is restricted")
|
||||
}
|
||||
if t, e := bundle.GetType(req.ObjectTypeKey); e == nil && t.RestrictObjectCreation && req.ObjectTypeKey != bundle.TypeKeyTemplate {
|
||||
return "", nil, errors.Wrap(restriction.ErrRestricted, "creation of this object type is restricted")
|
||||
}
|
||||
|
||||
switch req.ObjectTypeKey {
|
||||
|
|
|
@ -1134,14 +1134,13 @@ func TestHistory_Show(t *testing.T) {
|
|||
Model: &pb.Change{},
|
||||
}
|
||||
|
||||
heads := []string{"id", "id1"}
|
||||
changesMap := map[string][]*objecttree.Change{
|
||||
"id1 id": {root, ch1},
|
||||
"id id1": {root, ch},
|
||||
"id id1": {root, ch1},
|
||||
"id1 id": {root, ch},
|
||||
objectId: {root, ch, ch1},
|
||||
}
|
||||
|
||||
h := newFixtureShow(t, changesMap, heads, objectId, spaceID)
|
||||
h := newFixtureShow(t, changesMap, objectId, spaceID)
|
||||
|
||||
// when
|
||||
fullId := domain.FullID{ObjectID: objectId, SpaceID: spaceID}
|
||||
|
@ -1214,7 +1213,7 @@ func newFixtureDiffVersions(t *testing.T,
|
|||
}
|
||||
}
|
||||
|
||||
func newFixtureShow(t *testing.T, changes map[string][]*objecttree.Change, heads []string, objectId, spaceID string) *historyFixture {
|
||||
func newFixtureShow(t *testing.T, changes map[string][]*objecttree.Change, objectId, spaceID string) *historyFixture {
|
||||
spaceService := mock_space.NewMockService(t)
|
||||
space := mock_clientspace.NewMockSpace(t)
|
||||
ctrl := gomock.NewController(t)
|
||||
|
@ -1232,7 +1231,7 @@ func newFixtureShow(t *testing.T, changes map[string][]*objecttree.Change, heads
|
|||
return &historyStub{
|
||||
objectId: objectId,
|
||||
changes: chs,
|
||||
heads: heads,
|
||||
heads: opts.Heads,
|
||||
}, nil
|
||||
}).AnyTimes()
|
||||
space.EXPECT().TreeBuilder().Return(treeBuilder)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package emailcollector
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -188,10 +189,10 @@ func TestEmailCollector(t *testing.T) {
|
|||
|
||||
t.Run("should handle concurrent requests", func(t *testing.T) {
|
||||
// Given
|
||||
var callCount int
|
||||
var callCount atomic.Uint32
|
||||
collector := &mockEmailCollector{
|
||||
onSetRequest: func(req *pb.RpcMembershipGetVerificationEmailRequest) error {
|
||||
callCount++
|
||||
callCount.Add(1)
|
||||
assert.Equal(t, "test@example.com", req.Email)
|
||||
return nil
|
||||
},
|
||||
|
@ -214,6 +215,6 @@ func TestEmailCollector(t *testing.T) {
|
|||
for i := 0; i < 10; i++ {
|
||||
<-done
|
||||
}
|
||||
assert.Equal(t, 10, callCount)
|
||||
assert.Equal(t, uint32(10), callCount.Load())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
)
|
||||
|
||||
const TypeChecksum = "880c466315e22d0b573f6542b4ca1dcc4e2cb3395de3bad901f87460ff914191"
|
||||
const TypeChecksum = "4887c4b1b59f6fa595cc67185d19aec9212680c2316aa452ec39b66d5eea1b83"
|
||||
const (
|
||||
TypePrefix = "_ot"
|
||||
)
|
||||
|
@ -435,17 +435,18 @@ var (
|
|||
},
|
||||
TypeKeyTemplate: {
|
||||
|
||||
Description: "",
|
||||
IconColor: 8,
|
||||
IconName: "copy",
|
||||
Layout: model.ObjectType_basic,
|
||||
Name: "Template",
|
||||
PluralName: "Templates",
|
||||
Readonly: true,
|
||||
RelationLinks: []*model.RelationLink{MustGetRelationLink(RelationKeyTargetObjectType), MustGetRelationLink(RelationKeyTemplateIsBundled)},
|
||||
Revision: 4,
|
||||
Types: []model.SmartBlockType{model.SmartBlockType_Template},
|
||||
Url: TypePrefix + "template",
|
||||
Description: "",
|
||||
IconColor: 8,
|
||||
IconName: "copy",
|
||||
Layout: model.ObjectType_basic,
|
||||
Name: "Template",
|
||||
PluralName: "Templates",
|
||||
Readonly: true,
|
||||
RelationLinks: []*model.RelationLink{MustGetRelationLink(RelationKeyTargetObjectType), MustGetRelationLink(RelationKeyTemplateIsBundled)},
|
||||
RestrictObjectCreation: true,
|
||||
Revision: 4,
|
||||
Types: []model.SmartBlockType{model.SmartBlockType_Template},
|
||||
Url: TypePrefix + "template",
|
||||
},
|
||||
TypeKeyVideo: {
|
||||
|
||||
|
|
|
@ -298,6 +298,7 @@
|
|||
"targetObjectType",
|
||||
"templateIsBundled"
|
||||
],
|
||||
"restrictObjectCreation": true,
|
||||
"revision": 4
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue