diff --git a/server/internal/adapter/gql/generated.go b/server/internal/adapter/gql/generated.go index 72a681d3e9..810d9a886e 100644 --- a/server/internal/adapter/gql/generated.go +++ b/server/internal/adapter/gql/generated.go @@ -3341,6 +3341,7 @@ input UpdateModelInput { name: String description: String key: String + public: Boolean! } input DeleteModelInput { @@ -22066,7 +22067,7 @@ func (ec *executionContext) unmarshalInputUpdateModelInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"modelId", "name", "description", "key"} + fieldsInOrder := [...]string{"modelId", "name", "description", "key", "public"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -22105,6 +22106,14 @@ func (ec *executionContext) unmarshalInputUpdateModelInput(ctx context.Context, if err != nil { return it, err } + case "public": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("public")) + it.Public, err = ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } } } diff --git a/server/internal/adapter/gql/gqlmodel/convert_model.go b/server/internal/adapter/gql/gqlmodel/convert_model.go index 1175f72e20..e60b714654 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_model.go +++ b/server/internal/adapter/gql/gqlmodel/convert_model.go @@ -18,6 +18,7 @@ func ToModel(m *model.Model) *Model { Key: m.Key().String(), Project: nil, Schema: nil, + Public: m.Public(), CreatedAt: m.ID().Timestamp(), UpdatedAt: m.UpdatedAt(), } diff --git a/server/internal/adapter/gql/gqlmodel/convert_model_test.go b/server/internal/adapter/gql/gqlmodel/convert_model_test.go index 210c685616..6fa4ed6707 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_model_test.go +++ b/server/internal/adapter/gql/gqlmodel/convert_model_test.go @@ -38,6 +38,7 @@ func TestToModel(t *testing.T) { Key: k.String(), Project: nil, Schema: nil, + Public: false, CreatedAt: mId.Timestamp(), UpdatedAt: mId.Timestamp(), }, diff --git a/server/internal/adapter/gql/gqlmodel/convert_project.go b/server/internal/adapter/gql/gqlmodel/convert_project.go index f398109354..1c4db43a9c 100644 --- a/server/internal/adapter/gql/gqlmodel/convert_project.go +++ b/server/internal/adapter/gql/gqlmodel/convert_project.go @@ -11,10 +11,43 @@ func ToProject(p *project.Project) *Project { return &Project{ ID: IDFrom(p.ID()), + WorkspaceID: IDFrom(p.Workspace()), CreatedAt: p.CreatedAt(), Alias: p.Alias(), Name: p.Name(), Description: p.Description(), UpdatedAt: p.UpdatedAt(), + Publication: ToProjectPublication(p.Publication()), } } + +func ToProjectPublication(p *project.Publication) *ProjectPublication { + if p == nil { + return nil + } + + return &ProjectPublication{ + Scope: ToProjectPublicationScope(p.Scope()), + AssetPublic: p.AssetPublic(), + } +} + +func ToProjectPublicationScope(p project.PublicationScope) ProjectPublicationScope { + switch p { + case project.PublicationScopePublic: + return ProjectPublicationScopePublic + case project.PublicationScopeLimited: + return ProjectPublicationScopeLimited + } + return ProjectPublicationScopePrivate +} + +func FromProjectPublicationScope(p ProjectPublicationScope) project.PublicationScope { + switch p { + case ProjectPublicationScopePublic: + return project.PublicationScopePublic + case ProjectPublicationScopeLimited: + return project.PublicationScopeLimited + } + return project.PublicationScopePrivate +} diff --git a/server/internal/adapter/gql/gqlmodel/models_gen.go b/server/internal/adapter/gql/gqlmodel/models_gen.go index 428b2cf7db..7c425ba0d0 100644 --- a/server/internal/adapter/gql/gqlmodel/models_gen.go +++ b/server/internal/adapter/gql/gqlmodel/models_gen.go @@ -722,6 +722,7 @@ type UpdateModelInput struct { Name *string `json:"name"` Description *string `json:"description"` Key *string `json:"key"` + Public bool `json:"public"` } type UpdateProjectInput struct { diff --git a/server/internal/adapter/gql/resolver_mutation_model.go b/server/internal/adapter/gql/resolver_mutation_model.go index 53ac090147..11fcf0dcb5 100644 --- a/server/internal/adapter/gql/resolver_mutation_model.go +++ b/server/internal/adapter/gql/resolver_mutation_model.go @@ -6,6 +6,7 @@ import ( "github.com/reearth/reearth-cms/server/internal/adapter/gql/gqlmodel" "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/samber/lo" ) func (r *mutationResolver) CreateModel(ctx context.Context, input gqlmodel.CreateModelInput) (*gqlmodel.ModelPayload, error) { @@ -13,12 +14,12 @@ func (r *mutationResolver) CreateModel(ctx context.Context, input gqlmodel.Creat if err != nil { return nil, err } - res, err := usecases(ctx).Model.Create(ctx, interfaces.CreateModelParam{ ProjectId: pId, Name: input.Name, Description: input.Description, Key: input.Key, + Public: nil, }, getOperator(ctx)) if err != nil { return nil, err @@ -40,6 +41,7 @@ func (r *mutationResolver) UpdateModel(ctx context.Context, input gqlmodel.Updat Name: input.Name, Description: input.Description, Key: input.Key, + Public: lo.ToPtr(input.Public), }, getOperator(ctx)) if err != nil { return nil, err diff --git a/server/internal/adapter/gql/resolver_mutation_project.go b/server/internal/adapter/gql/resolver_mutation_project.go index 71c58fe885..a17c2f0f2a 100644 --- a/server/internal/adapter/gql/resolver_mutation_project.go +++ b/server/internal/adapter/gql/resolver_mutation_project.go @@ -6,6 +6,8 @@ import ( "github.com/reearth/reearth-cms/server/internal/adapter/gql/gqlmodel" "github.com/reearth/reearth-cms/server/internal/usecase/interfaces" "github.com/reearth/reearth-cms/server/pkg/id" + "github.com/reearth/reearth-cms/server/pkg/project" + "github.com/samber/lo" ) func (r *mutationResolver) CreateProject(ctx context.Context, input gqlmodel.CreateProjectInput) (*gqlmodel.ProjectPayload, error) { @@ -33,10 +35,23 @@ func (r *mutationResolver) UpdateProject(ctx context.Context, input gqlmodel.Upd return nil, err } + var pub *interfaces.UpdateProjectPublicationParam + if input.Publication != nil { + var scope *project.PublicationScope + if input.Publication.Scope != nil { + scope = lo.ToPtr(gqlmodel.FromProjectPublicationScope(*input.Publication.Scope)) + } + pub = &interfaces.UpdateProjectPublicationParam{ + Scope: scope, + AssetPublic: input.Publication.AssetPublic, + } + } + res, err := usecases(ctx).Project.Update(ctx, interfaces.UpdateProjectParam{ ID: pid, Name: input.Name, Description: input.Description, + Publication: pub, }, getOperator(ctx)) if err != nil { return nil, err diff --git a/server/internal/infrastructure/mongo/mongodoc/model.go b/server/internal/infrastructure/mongo/mongodoc/model.go index d90821c54a..0d5a8bd39b 100644 --- a/server/internal/infrastructure/mongo/mongodoc/model.go +++ b/server/internal/infrastructure/mongo/mongodoc/model.go @@ -54,7 +54,7 @@ func (d *ModelDocument) Model() (*model.Model, error) { Description(d.Description). UpdatedAt(d.UpdatedAt). Key(key.New(d.Key)). - IsPublic(d.Public). + Public(d.Public). Project(pId). Schema(sId). Build() diff --git a/server/internal/infrastructure/mongo/mongodoc/project.go b/server/internal/infrastructure/mongo/mongodoc/project.go index b43db6a851..2fa7feed85 100644 --- a/server/internal/infrastructure/mongo/mongodoc/project.go +++ b/server/internal/infrastructure/mongo/mongodoc/project.go @@ -17,6 +17,12 @@ type ProjectDocument struct { Alias string ImageURL string Workspace string + Publication *ProjectPublicationDocument +} + +type ProjectPublicationDocument struct { + AssetPublic bool + Scope string } func NewProject(project *project.Project) (*ProjectDocument, string) { @@ -35,9 +41,21 @@ func NewProject(project *project.Project) (*ProjectDocument, string) { Alias: project.Alias(), ImageURL: imageURL, Workspace: project.Workspace().String(), + Publication: NewProjectPublication(project.Publication()), }, pid } +func NewProjectPublication(p *project.Publication) *ProjectPublicationDocument { + if p == nil { + return nil + } + + return &ProjectPublicationDocument{ + AssetPublic: p.AssetPublic(), + Scope: string(p.Scope()), + } +} + func (d *ProjectDocument) Model() (*project.Project, error) { pid, err := id.ProjectIDFrom(d.ID) if err != nil { @@ -63,9 +81,17 @@ func (d *ProjectDocument) Model() (*project.Project, error) { Alias(d.Alias). Workspace(tid). ImageURL(imageURL). + Publication(d.Publication.Model()). Build() } +func (d *ProjectPublicationDocument) Model() *project.Publication { + if d == nil { + return nil + } + return project.NewPublication(project.PublicationScope(d.Scope), d.AssetPublic) +} + type ProjectConsumer = mongox.SliceFuncConsumer[*ProjectDocument, *project.Project] func NewProjectConsumer() *ProjectConsumer { diff --git a/server/internal/usecase/interactor/model.go b/server/internal/usecase/interactor/model.go index f1062eec0d..dc61a3855d 100644 --- a/server/internal/usecase/interactor/model.go +++ b/server/internal/usecase/interactor/model.go @@ -71,7 +71,7 @@ func (i Model) Create(ctx context.Context, param interfaces.CreateModelParam, op New(). NewID(). Schema(s.ID()). - IsPublic(false). + Public(false). Project(param.ProjectId) if param.Name != nil { @@ -80,6 +80,9 @@ func (i Model) Create(ctx context.Context, param interfaces.CreateModelParam, op if param.Description != nil { mb = mb.Description(*param.Description) } + if param.Public != nil { + mb = mb.Public(*param.Public) + } if param.Key != nil { k := key.New(*param.Key) if !k.IsValid() { @@ -126,6 +129,9 @@ func (i Model) Update(ctx context.Context, param interfaces.UpdateModelParam, op return nil, err } } + if param.Public != nil { + m.SetPublic(*param.Public) + } if err := i.repos.Model.Save(ctx, m); err != nil { return nil, err diff --git a/server/internal/usecase/interactor/model_test.go b/server/internal/usecase/interactor/model_test.go index 9b9ec9b542..e9061ffa17 100644 --- a/server/internal/usecase/interactor/model_test.go +++ b/server/internal/usecase/interactor/model_test.go @@ -186,10 +186,11 @@ func TestModel_Create(t *testing.T) { // Name: lo.ToPtr("m1"), // Description: lo.ToPtr("m1"), // Key: lo.ToPtr("k123456"), + // Public: lo.ToPtr(true), // }, // operator: op, // }, - // want: model.New().ID(mId).Schema(sId).Project(pid1).Name("m1").Description("m1").Key(key.New("k123456")).UpdatedAt(mockTime).MustBuild(), + // want: model.New().ID(mId).Schema(sId).Project(pid1).Name("m1").Description("m1").Key(key.New("k123456")).Public(true).UpdatedAt(mockTime).MustBuild(), // mockErr: false, // wantErr: nil, // }, diff --git a/server/internal/usecase/interactor/project.go b/server/internal/usecase/interactor/project.go index c609be37ba..468aacfda3 100644 --- a/server/internal/usecase/interactor/project.go +++ b/server/internal/usecase/interactor/project.go @@ -87,6 +87,20 @@ func (i *Project) Update(ctx context.Context, p interfaces.UpdateProjectParam, o proj.UpdateDescription(*p.Description) } + if p.Publication != nil { + pub := proj.Publication() + if pub == nil { + pub = project.NewPublication(project.PublicationScopePrivate, false) + } + if p.Publication.Scope != nil { + pub.SetScope(*p.Publication.Scope) + } + if p.Publication.AssetPublic != nil { + pub.SetAssetPublic(*p.Publication.AssetPublic) + } + proj.SetPublication(pub) + } + if err := i.repos.Project.Save(ctx, proj); err != nil { return nil, err } diff --git a/server/internal/usecase/interactor/project_test.go b/server/internal/usecase/interactor/project_test.go index ddb8936af7..5ec18d5ed2 100644 --- a/server/internal/usecase/interactor/project_test.go +++ b/server/internal/usecase/interactor/project_test.go @@ -349,8 +349,6 @@ func TestProject_Update(t *testing.T) { pid1 := id.NewProjectID() p1 := project.New().ID(pid1).Workspace(wid1).UpdatedAt(mocktime.Add(-time.Second)).MustBuild() - p1Updated := project.New().ID(pid1).Workspace(wid1).Name("test123").Description("desc321"). - UpdatedAt(mocktime).MustBuild() pid2 := id.NewProjectID() p2 := project.New().ID(pid2).Workspace(wid2).UpdatedAt(mocktime).MustBuild() @@ -385,7 +383,13 @@ func TestProject_Update(t *testing.T) { }, operator: op, }, - want: p1Updated, + want: project.New(). + ID(pid1). + Workspace(wid1). + Name("test123"). + Description("desc321"). + UpdatedAt(mocktime). + MustBuild(), wantErr: nil, }, { @@ -402,6 +406,26 @@ func TestProject_Update(t *testing.T) { want: nil, wantErr: interfaces.ErrOperationDenied, }, + { + name: "update publication", + seeds: project.List{p1, p2}, + args: args{ + upp: interfaces.UpdateProjectParam{ + ID: p1.ID(), + Publication: &interfaces.UpdateProjectPublicationParam{ + Scope: lo.ToPtr(project.PublicationScopePublic), + AssetPublic: lo.ToPtr(true), + }, + }, + operator: op, + }, + want: project.New(). + ID(pid1). + Workspace(wid1). + UpdatedAt(mocktime). + Publication(project.NewPublication(project.PublicationScopePublic, true)). + MustBuild(), + }, { name: "mock error", wantErr: errors.New("test"), diff --git a/server/internal/usecase/interfaces/model.go b/server/internal/usecase/interfaces/model.go index 8d5b07a3dd..02c0caaa4d 100644 --- a/server/internal/usecase/interfaces/model.go +++ b/server/internal/usecase/interfaces/model.go @@ -15,6 +15,7 @@ type CreateModelParam struct { Name *string Description *string Key *string + Public *bool } type UpdateModelParam struct { @@ -22,6 +23,7 @@ type UpdateModelParam struct { Name *string Description *string Key *string + Public *bool } var ( diff --git a/server/internal/usecase/interfaces/project.go b/server/internal/usecase/interfaces/project.go index 48f6d46354..8dbc7428c4 100644 --- a/server/internal/usecase/interfaces/project.go +++ b/server/internal/usecase/interfaces/project.go @@ -21,6 +21,12 @@ type UpdateProjectParam struct { ID id.ProjectID Name *string Description *string + Publication *UpdateProjectPublicationParam +} + +type UpdateProjectPublicationParam struct { + Scope *project.PublicationScope + AssetPublic *bool } var ( diff --git a/server/pkg/model/builder.go b/server/pkg/model/builder.go index 6f3f1e1f25..3b8805039e 100644 --- a/server/pkg/model/builder.go +++ b/server/pkg/model/builder.go @@ -82,7 +82,7 @@ func (b *Builder) RandomKey() *Builder { return b } -func (b *Builder) IsPublic(public bool) *Builder { +func (b *Builder) Public(public bool) *Builder { b.model.public = public return b } diff --git a/server/pkg/model/builder_test.go b/server/pkg/model/builder_test.go index be530395e8..5fdbfe6479 100644 --- a/server/pkg/model/builder_test.go +++ b/server/pkg/model/builder_test.go @@ -411,7 +411,7 @@ func TestBuilder_ID(t *testing.T) { } } -func TestBuilder_IsPublic(t *testing.T) { +func TestBuilder_Public(t *testing.T) { type fields struct { model *Model k key.Key @@ -467,7 +467,7 @@ func TestBuilder_IsPublic(t *testing.T) { model: tt.fields.model, k: tt.fields.k, } - assert.Equal(t, tt.want, b.IsPublic(tt.args.public)) + assert.Equal(t, tt.want, b.Public(tt.args.public)) }) } } diff --git a/server/pkg/model/model_test.go b/server/pkg/model/model_test.go index f1f08512dd..e1163f2100 100644 --- a/server/pkg/model/model_test.go +++ b/server/pkg/model/model_test.go @@ -214,12 +214,19 @@ func TestModel_Public(t *testing.T) { want bool }{ { - name: "test", + name: "public true", model: Model{ public: true, }, want: true, }, + { + name: "public false", + model: Model{ + public: false, + }, + want: false, + }, } for _, tt := range tests { tt := tt @@ -365,43 +372,13 @@ func TestModel_SetName(t *testing.T) { } func TestModel_SetPublic(t *testing.T) { - type args struct { - public bool - } - tests := []struct { - name string - want Model - args args - }{ - { - name: "test", - args: args{ - public: true, - }, - want: Model{ - public: true, - }, - }, - { - name: "test", - args: args{ - public: false, - }, - want: Model{ - public: false, - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() + m := &Model{public: false} + m.SetPublic(true) + assert.Equal(t, &Model{public: true}, m) - m := Model{} - m.SetPublic(tt.args.public) - assert.Equal(t, tt.want, m) - }) - } + m = &Model{public: true} + m.SetPublic(false) + assert.Equal(t, &Model{public: false}, m) } func TestModel_SetUpdatedAt(t *testing.T) { diff --git a/server/pkg/project/builder.go b/server/pkg/project/builder.go index 7302ab14fb..bb22d4bffc 100644 --- a/server/pkg/project/builder.go +++ b/server/pkg/project/builder.go @@ -79,3 +79,8 @@ func (b *Builder) Workspace(team WorkspaceID) *Builder { b.p.workspaceID = team return b } + +func (b *Builder) Publication(publication *Publication) *Builder { + b.p.publication = publication + return b +} diff --git a/server/pkg/project/builder_test.go b/server/pkg/project/builder_test.go index d1fc48d764..0bbaa9dab8 100644 --- a/server/pkg/project/builder_test.go +++ b/server/pkg/project/builder_test.go @@ -90,6 +90,15 @@ func TestBuilder_UpdatedAt(t *testing.T) { assert.True(t, reflect.DeepEqual(res.UpdatedAt(), d)) } +func TestBuilder_Publication(t *testing.T) { + var tb = New().NewID() + p := &Publication{} + res := tb.Publication(p) + assert.Equal(t, &Builder{ + p: &Project{id: tb.p.id, publication: p}, + }, res) +} + func TestBuilder_Build(t *testing.T) { d := time.Date(1900, 1, 1, 00, 00, 0, 1, time.UTC) i, _ := url.Parse("ttt://xxx.aa/") diff --git a/server/pkg/project/project.go b/server/pkg/project/project.go index e4b2484aaf..a9fed2415a 100644 --- a/server/pkg/project/project.go +++ b/server/pkg/project/project.go @@ -22,6 +22,7 @@ type Project struct { alias string imageURL *url.URL updatedAt time.Time + publication *Publication } func (p *Project) ID() ID { @@ -61,6 +62,10 @@ func (p *Project) CreatedAt() time.Time { return p.id.Timestamp() } +func (p *Project) Publication() *Publication { + return p.publication +} + func (p *Project) SetUpdatedAt(updatedAt time.Time) { p.updatedAt = updatedAt } @@ -75,6 +80,10 @@ func (p *Project) SetImageURL(imageURL *url.URL) { } } +func (p *Project) SetPublication(publication *Publication) { + p.publication = publication +} + func (p *Project) UpdateName(name string) { p.name = name } @@ -109,6 +118,7 @@ func (p *Project) Clone() *Project { alias: p.alias, imageURL: util.CopyURL(p.imageURL), updatedAt: p.updatedAt, + publication: p.publication.Clone(), } } diff --git a/server/pkg/project/project_test.go b/server/pkg/project/project_test.go index 08eda4a4fe..606154d254 100644 --- a/server/pkg/project/project_test.go +++ b/server/pkg/project/project_test.go @@ -129,10 +129,12 @@ func TestProject_UpdateAlias(t *testing.T) { } func TestProject_Clone(t *testing.T) { - p := New().NewID().Name("a").MustBuild() + pub := &Publication{} + p := New().NewID().Name("a").Publication(pub).MustBuild() got := p.Clone() assert.Equal(t, p, got) assert.NotSame(t, p, got) + assert.NotSame(t, p, got.publication) assert.Nil(t, (*Project)(nil).Clone()) } diff --git a/server/pkg/project/publication.go b/server/pkg/project/publication.go new file mode 100644 index 0000000000..3ef30a6136 --- /dev/null +++ b/server/pkg/project/publication.go @@ -0,0 +1,55 @@ +package project + +const ( + PublicationScopePrivate PublicationScope = "private" + PublicationScopeLimited PublicationScope = "limited" + PublicationScopePublic PublicationScope = "public" +) + +type PublicationScope string + +type Publication struct { + scope PublicationScope + assetPublic bool +} + +func NewPublication(scope PublicationScope, assetPublic bool) *Publication { + p := &Publication{} + p.SetScope(scope) + p.SetAssetPublic(assetPublic) + return p +} + +func (p *Publication) Scope() PublicationScope { + if p.scope == "" { + return PublicationScopePrivate + } + return p.scope +} + +func (p *Publication) AssetPublic() bool { + return p.assetPublic +} + +func (p *Publication) SetScope(scope PublicationScope) { + if scope != PublicationScopePrivate && scope != PublicationScopeLimited && scope != PublicationScopePublic { + scope = PublicationScopePrivate + } + + p.scope = scope +} + +func (p *Publication) SetAssetPublic(assetPublic bool) { + p.assetPublic = assetPublic +} + +func (p *Publication) Clone() *Publication { + if p == nil { + return nil + } + + return &Publication{ + scope: p.scope, + assetPublic: p.assetPublic, + } +} diff --git a/server/pkg/project/publication_test.go b/server/pkg/project/publication_test.go new file mode 100644 index 0000000000..b09a1fd996 --- /dev/null +++ b/server/pkg/project/publication_test.go @@ -0,0 +1,94 @@ +package project + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewPublication(t *testing.T) { + assert.Equal(t, &Publication{ + scope: PublicationScopePrivate, + assetPublic: false, + }, NewPublication(PublicationScopePrivate, false)) + assert.Equal(t, &Publication{ + scope: PublicationScopeLimited, + assetPublic: true, + }, NewPublication(PublicationScopeLimited, true)) + assert.Equal(t, &Publication{ + scope: PublicationScopePublic, + assetPublic: false, + }, NewPublication(PublicationScopePublic, false)) + assert.Equal(t, &Publication{ + scope: PublicationScopePrivate, + assetPublic: true, + }, NewPublication("", true)) +} + +func TestPublication_Scope(t *testing.T) { + assert.Equal(t, PublicationScopePrivate, (&Publication{}).Scope()) + assert.Equal(t, PublicationScopePublic, (&Publication{scope: PublicationScopePublic}).Scope()) +} + +func TestPublication_AssetPublic(t *testing.T) { + assert.True(t, (&Publication{assetPublic: true}).AssetPublic()) +} + +func TestPublication_SetScope(t *testing.T) { + p := &Publication{ + scope: PublicationScopePublic, + } + p.SetScope(PublicationScopePrivate) + assert.Equal(t, &Publication{ + scope: PublicationScopePrivate, + }, p) + + p = &Publication{} + p.SetScope(PublicationScopeLimited) + assert.Equal(t, &Publication{ + scope: PublicationScopeLimited, + }, p) + + p = &Publication{} + p.SetScope(PublicationScopePublic) + assert.Equal(t, &Publication{ + scope: PublicationScopePublic, + }, p) + + p = &Publication{ + scope: PublicationScopePublic, + } + p.SetScope("") + assert.Equal(t, &Publication{ + scope: PublicationScopePrivate, + }, p) +} + +func TestPublication_SetAssetPublic(t *testing.T) { + p := &Publication{ + assetPublic: false, + } + p.SetAssetPublic(true) + assert.Equal(t, &Publication{ + assetPublic: true, + }, p) + + p = &Publication{ + assetPublic: true, + } + p.SetAssetPublic(false) + assert.Equal(t, &Publication{ + assetPublic: false, + }, p) +} + +func TestPublication_Clone(t *testing.T) { + p := &Publication{ + assetPublic: false, + scope: PublicationScopeLimited, + } + p2 := p.Clone() + assert.Equal(t, p, p2) + assert.NotSame(t, p, p2) + assert.Nil(t, (*Publication)(nil).Clone()) +} diff --git a/server/schemas/model.graphql b/server/schemas/model.graphql index dc5d3e3c0c..06362a3c86 100644 --- a/server/schemas/model.graphql +++ b/server/schemas/model.graphql @@ -25,6 +25,7 @@ input UpdateModelInput { name: String description: String key: String + public: Boolean! } input DeleteModelInput {