Skip to content
Snippets Groups Projects
Commit 4c8a9dfa authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-2599-UpdateCollectionStruct' into 'master'

Обновление протокола, Collection добавлено поля "Без публикации"

See merge request perxis/perxis-go!316
parents a263ec7a 3d2edfb0
No related branches found
No related tags found
No related merge requests found
Subproject commit 64fe5194e41d6d1023d6d78e794e7458ecef1888
Subproject commit 6af1580075902894ee50e26ef27aecdd106278dd
......@@ -53,16 +53,22 @@ func (a Access) Can(action permission.Action) bool {
}
type Collection struct {
ID string `json:"id" bson:"id"`
SpaceID string `json:"spaceId" bson:"-"`
EnvID string `json:"envId" bson:"-"`
Name string `json:"name" bson:"name"`
Single *bool `json:"single" bson:"single,omitempty"` // В коллекции может быть только один документ
System *bool `json:"system" bson:"system,omitempty"` // Системная коллекция
NoData *bool `json:"no_data" bson:"no_data"` // Коллекция не содержит элементы. Схема используется для включения в другие схемы
Hidden bool `json:"hidden" bson:"hidden"` // Коллекция скрыта в административном интерфейсе
Schema *schema.Schema `json:"schema" bson:"schema"`
Access *Access `json:"access" bson:"-"` // Ограничения на доступ к элементам коллекции. Отсутствие объекта означает неограниченный доступ
ID string `json:"id" bson:"id"`
SpaceID string `json:"spaceId" bson:"-"`
EnvID string `json:"envId" bson:"-"`
Name string `json:"name" bson:"name"`
Single *bool `json:"single" bson:"single,omitempty"` // В коллекции может быть только один документ
System *bool `json:"system" bson:"system,omitempty"` // Системная коллекция
NoData *bool `json:"no_data" bson:"no_data"` // Коллекция не содержит элементы. Схема используется для включения в другие схемы
Hidden bool `json:"hidden" bson:"hidden"` // Коллекция скрыта в административном интерфейсе
// Все записи коллекции считаются опубликованными, функции публикации и снятия с публикации недоступны.
// При включении параметра коллекции "без публикации" все записи, независимо от статуса, будут считаться опубликованными.
// При отключении параметра "без публикации" статусы публикации будут восстановлены.
NoPublish bool `json:"no_publish" bson:"no_publish,omitempty"`
Schema *schema.Schema `json:"schema" bson:"schema"`
Access *Access `json:"access" bson:"-"` // Ограничения на доступ к элементам коллекции. Отсутствие объекта означает неограниченный доступ
// StateInfo отображает состояние коллекции:
// - State: идентификатор состояния коллекции (new/preparing/ready/error/changed)
......@@ -137,12 +143,13 @@ const (
func (c Collection) Clone() *Collection {
clone := &Collection{
ID: c.ID,
SpaceID: c.SpaceID,
EnvID: c.EnvID,
Name: c.Name,
NoData: c.NoData,
Hidden: c.Hidden,
ID: c.ID,
SpaceID: c.SpaceID,
EnvID: c.EnvID,
Name: c.Name,
NoData: c.NoData,
Hidden: c.Hidden,
NoPublish: c.NoPublish,
}
if c.Single != nil {
......@@ -222,6 +229,9 @@ func FromSchemaMetadata(schemas ...*schema.Schema) []*Collection {
if hidden, ok := sch.Metadata["collection_hidden"]; ok && hidden == "true" {
coll.Hidden = true
}
if disablePublishing, ok := sch.Metadata["collection_no_publish"]; ok && disablePublishing == "true" {
coll.NoPublish = true
}
if _, ok := sch.Metadata["collection_view_id"]; ok {
coll.View = &View{
......
......@@ -134,19 +134,21 @@ func TestFromSchemaMetadata(t *testing.T) {
"collection_system", "true",
"collection_nodata", "true",
"collection_hidden", "true",
"collection_no_publish", "true",
"collection_view_space", "viewSpaceID",
"collection_view_env", "viewEnvID",
"collection_view_id", "viewCollID",
"collection_view_filter", "viewFilter",
)},
want: []*Collection{{
ID: "collID",
Name: "collName",
Single: optional.True,
System: optional.True,
NoData: optional.True,
Hidden: true,
Schema: schema.New("a", field.String()).WithMetadata("collection_id", "collID", "collection_name", "collName", "collection_single", "true", "collection_system", "true", "collection_nodata", "true", "collection_hidden", "true", "collection_view_space", "viewSpaceID", "collection_view_env", "viewEnvID", "collection_view_id", "viewCollID", "collection_view_filter", "viewFilter"),
ID: "collID",
Name: "collName",
Single: optional.True,
System: optional.True,
NoData: optional.True,
Hidden: true,
NoPublish: true,
Schema: schema.New("a", field.String()).WithMetadata("collection_id", "collID", "collection_name", "collName", "collection_single", "true", "collection_system", "true", "collection_nodata", "true", "collection_hidden", "true", "collection_no_publish", "true", "collection_view_space", "viewSpaceID", "collection_view_env", "viewEnvID", "collection_view_id", "viewCollID", "collection_view_filter", "viewFilter"),
View: &View{
SpaceID: "viewSpaceID",
EnvID: "viewEnvID",
......
......@@ -61,16 +61,17 @@ func PtrCollectionToProto(coll *service.Collection) (*pb.Collection, error) {
}
}
protoCollection := &pb.Collection{
Id: coll.ID,
SpaceId: coll.SpaceID,
EnvId: coll.EnvID,
Name: coll.Name,
Single: coll.Single,
System: coll.System,
NoData: coll.NoData,
Access: access,
Hidden: coll.Hidden,
Tags: coll.Tags,
Id: coll.ID,
SpaceId: coll.SpaceID,
EnvId: coll.EnvID,
Name: coll.Name,
Single: coll.Single,
System: coll.System,
NoData: coll.NoData,
Access: access,
Hidden: coll.Hidden,
NoPublish: coll.NoPublish,
Tags: coll.Tags,
}
if coll.StateInfo != nil {
......@@ -125,16 +126,17 @@ func ProtoToPtrCollection(protoCollection *pb.Collection) (*service.Collection,
}
}
collection := &service.Collection{
ID: protoCollection.Id,
SpaceID: protoCollection.SpaceId,
EnvID: protoCollection.EnvId,
Name: protoCollection.Name,
Single: protoCollection.Single,
System: protoCollection.System,
NoData: protoCollection.NoData,
Access: access,
Hidden: protoCollection.Hidden,
Tags: protoCollection.Tags,
ID: protoCollection.Id,
SpaceID: protoCollection.SpaceId,
EnvID: protoCollection.EnvId,
Name: protoCollection.Name,
Single: protoCollection.Single,
System: protoCollection.System,
NoData: protoCollection.NoData,
Access: access,
Hidden: protoCollection.Hidden,
NoPublish: protoCollection.NoPublish,
Tags: protoCollection.Tags,
}
if protoCollection.StateInfo != nil {
......
package items
import (
"maps"
"slices"
"git.perx.ru/perxis/perxis-go/pkg/options"
pb "git.perx.ru/perxis/perxis-go/proto/items"
)
......@@ -381,6 +384,14 @@ type GetPublishedOptions struct {
TranslationsIDs []string
}
func (opts *GetPublishedOptions) ToGetOptions() *GetOptions {
return &GetOptions{
Options: MergeOptions(opts.Options),
LocaleID: opts.LocaleID,
TranslationsIDs: slices.Clone(opts.TranslationsIDs),
}
}
func NewGetPublishedOptions(oo ...interface{}) *GetPublishedOptions {
fo := &GetPublishedOptions{}
for _, o := range oo {
......@@ -446,6 +457,19 @@ type FindPublishedOptions struct {
TranslationsIDs []string
}
func (opts *FindPublishedOptions) ToFindOptions() *FindOptions {
return &FindOptions{
Options: MergeOptions(opts.Options),
FindOptions: *options.MergeFindOptions(opts.FindOptions),
Deleted: opts.Deleted,
Regular: opts.Regular,
Hidden: opts.Hidden,
Templates: opts.Templates,
LocaleID: opts.LocaleID,
TranslationsIDs: slices.Clone(opts.TranslationsIDs),
}
}
func NewFindPublishedOptions(opts ...interface{}) *FindPublishedOptions {
fo := &FindPublishedOptions{}
for _, o := range opts {
......@@ -741,6 +765,14 @@ func MergeAggregateOptions(opts ...*AggregateOptions) *AggregateOptions {
type AggregatePublishedOptions AggregateOptions
func (opts *AggregatePublishedOptions) ToAggregateOptions() *AggregateOptions {
return &AggregateOptions{
Options: MergeOptions(opts.Options),
SortOptions: options.MergeSortOptions(opts.SortOptions),
Fields: maps.Clone(opts.Fields),
}
}
func MergeAggregatePublishedOptions(opts ...*AggregatePublishedOptions) *AggregatePublishedOptions {
ao := make([]*AggregateOptions, len(opts))
for i, opt := range opts {
......
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v4.25.1
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.27.3
// source: collections/collections.proto
package collections
......@@ -16,8 +16,8 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Collections_Create_FullMethodName = "/content.collections.Collections/Create"
......@@ -63,8 +63,9 @@ func NewCollectionsClient(cc grpc.ClientConnInterface) CollectionsClient {
}
func (c *collectionsClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CreateResponse)
err := c.cc.Invoke(ctx, Collections_Create_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_Create_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -72,8 +73,9 @@ func (c *collectionsClient) Create(ctx context.Context, in *CreateRequest, opts
}
func (c *collectionsClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetResponse)
err := c.cc.Invoke(ctx, Collections_Get_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_Get_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -81,8 +83,9 @@ func (c *collectionsClient) Get(ctx context.Context, in *GetRequest, opts ...grp
}
func (c *collectionsClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListResponse)
err := c.cc.Invoke(ctx, Collections_List_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_List_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -90,8 +93,9 @@ func (c *collectionsClient) List(ctx context.Context, in *ListRequest, opts ...g
}
func (c *collectionsClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, Collections_Update_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_Update_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -99,8 +103,9 @@ func (c *collectionsClient) Update(ctx context.Context, in *UpdateRequest, opts
}
func (c *collectionsClient) SetSchema(ctx context.Context, in *SetSchemaRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, Collections_SetSchema_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_SetSchema_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -108,8 +113,9 @@ func (c *collectionsClient) SetSchema(ctx context.Context, in *SetSchemaRequest,
}
func (c *collectionsClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, Collections_Delete_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Collections_Delete_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -118,7 +124,7 @@ func (c *collectionsClient) Delete(ctx context.Context, in *DeleteRequest, opts
// CollectionsServer is the server API for Collections service.
// All implementations must embed UnimplementedCollectionsServer
// for forward compatibility
// for forward compatibility.
type CollectionsServer interface {
// Создать коллекцию. Установка схемы производится через отдельный метод `SetSchema` и методом `Create` игнорируется
Create(context.Context, *CreateRequest) (*CreateResponse, error)
......@@ -143,9 +149,12 @@ type CollectionsServer interface {
mustEmbedUnimplementedCollectionsServer()
}
// UnimplementedCollectionsServer must be embedded to have forward compatible implementations.
type UnimplementedCollectionsServer struct {
}
// UnimplementedCollectionsServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedCollectionsServer struct{}
func (UnimplementedCollectionsServer) Create(context.Context, *CreateRequest) (*CreateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
......@@ -166,6 +175,7 @@ func (UnimplementedCollectionsServer) Delete(context.Context, *DeleteRequest) (*
return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented")
}
func (UnimplementedCollectionsServer) mustEmbedUnimplementedCollectionsServer() {}
func (UnimplementedCollectionsServer) testEmbeddedByValue() {}
// UnsafeCollectionsServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to CollectionsServer will
......@@ -175,6 +185,13 @@ type UnsafeCollectionsServer interface {
}
func RegisterCollectionsServer(s grpc.ServiceRegistrar, srv CollectionsServer) {
// If the following call pancis, it indicates UnimplementedCollectionsServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Collections_ServiceDesc, srv)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment