public ContentOperationContext(
            IAppProvider appProvider,
            IEnumerable <IValidatorsFactory> validators,
            IContentWorkflow contentWorkflow,
            IContentRepository contentRepository,
            IJsonSerializer jsonSerializer,
            IScriptEngine scriptEngine,
            ISemanticLog log)
        {
            Guard.NotDefault(appProvider, nameof(appProvider));
            Guard.NotDefault(validators, nameof(validators));
            Guard.NotDefault(contentWorkflow, nameof(contentWorkflow));
            Guard.NotDefault(contentRepository, nameof(contentRepository));
            Guard.NotDefault(jsonSerializer, nameof(jsonSerializer));
            Guard.NotDefault(scriptEngine, nameof(scriptEngine));
            Guard.NotDefault(log, nameof(log));

            this.appProvider       = appProvider;
            this.validators        = validators;
            this.contentWorkflow   = contentWorkflow;
            this.contentRepository = contentRepository;
            this.jsonSerializer    = jsonSerializer;
            this.scriptEngine      = scriptEngine;

            this.log = log;
        }
Example #2
0
        public ContentGrain(
            IStore <Guid> store,
            ISemanticLog log,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IScriptEngine scriptEngine,
            IContentWorkflow contentWorkflow,
            IContentRepository contentRepository,
            IActivationLimit limit)
            : base(store, log)
        {
            Guard.NotNull(appProvider, nameof(appProvider));
            Guard.NotNull(scriptEngine, nameof(scriptEngine));
            Guard.NotNull(assetRepository, nameof(assetRepository));
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));
            Guard.NotNull(contentRepository, nameof(contentRepository));

            this.appProvider       = appProvider;
            this.scriptEngine      = scriptEngine;
            this.assetRepository   = assetRepository;
            this.contentWorkflow   = contentWorkflow;
            this.contentRepository = contentRepository;

            limit?.SetLimit(5000, Lifetime);
        }
Example #3
0
 private static async Task ValidateCanUpdate(IContentEntity content, IContentWorkflow contentWorkflow)
 {
     if (!await contentWorkflow.CanUpdateAsync(content))
     {
         throw new DomainException($"The workflow does not allow updates at status {content.Status}");
     }
 }
Example #4
0
 private static async Task ValidateCanUpdate(ContentState content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
 {
     if (!await contentWorkflow.CanUpdateAsync(content, content.EditingStatus, user))
     {
         throw new DomainException(T.Get("contents.workflowErrorUpdate", new { status = content.EditingStatus }));
     }
 }
Example #5
0
 private static async Task ValidateCanUpdate(ContentState content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
 {
     if (!await contentWorkflow.CanUpdateAsync(content, content.EditingStatus, user))
     {
         throw new DomainException($"The workflow does not allow updates at status {content.Status}");
     }
 }
Example #6
0
        public ContentEnricher(IContentWorkflow contentWorkflow, IContextProvider contextProvider)
        {
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));
            Guard.NotNull(contextProvider, nameof(contextProvider));

            this.contentWorkflow = contentWorkflow;
            this.contextProvider = contextProvider;
        }
Example #7
0
        public ContentEnricher(Lazy <IContentQueryService> contentQuery, IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(contentQuery, nameof(contentQuery));
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));

            this.contentQuery    = contentQuery;
            this.contentWorkflow = contentWorkflow;
        }
        public ContentDomainObject(IStore <DomainId> store, IContentWorkflow contentWorkflow, ContentOperationContext context, ISemanticLog log)
            : base(store, log)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));

            this.contentWorkflow = contentWorkflow;
            this.context         = context;
        }
Example #9
0
        private static async Task ValidateCanUpdate(IContentEntity content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
        {
            var status = content.NewStatus ?? content.Status;

            if (!await contentWorkflow.CanUpdateAsync(content, status, user))
            {
                throw new DomainException(T.Get("contents.workflowErrorUpdate", new { status }));
            }
        }
Example #10
0
        public static async Task CanChangeStatus(ChangeContentStatus command,
                                                 IContentEntity content,
                                                 IContentWorkflow contentWorkflow,
                                                 IContentRepository contentRepository,
                                                 ISchemaEntity schema)
        {
            Guard.NotNull(command, nameof(command));

            CheckPermission(content, command, Permissions.AppContentsChangeStatus, Permissions.AppContentsUpsert);

            var newStatus = command.Status;

            if (schema.SchemaDef.IsSingleton)
            {
                if (content.NewStatus == null || newStatus != Status.Published)
                {
                    throw new DomainException(T.Get("contents.singletonNotChangeable"));
                }

                return;
            }

            var oldStatus = content.NewStatus ?? content.Status;

            if (oldStatus == Status.Published && command.CheckReferrers)
            {
                var hasReferrer = await contentRepository.HasReferrersAsync(content.AppId.Id, command.ContentId, SearchScope.Published);

                if (hasReferrer)
                {
                    throw new DomainException(T.Get("contents.referenced"));
                }
            }

            await Validate.It(async e =>
            {
                if (!command.DoNotValidateWorkflow)
                {
                    if (!await contentWorkflow.CanMoveToAsync(content, oldStatus, newStatus, command.User))
                    {
                        var values = new { oldStatus, newStatus };

                        e(T.Get("contents.statusTransitionNotAllowed", values), "Status");
                    }
                }
                else
                {
                    var info = await contentWorkflow.GetInfoAsync(content, newStatus);

                    if (info == null)
                    {
                        e(T.Get("contents.statusNotValid"), "Status");
                    }
                }
            });
        }
        public ContentsController(ICommandBus commandBus,
                                  IContentQueryService contentQuery,
                                  IContentWorkflow contentWorkflow,
                                  IGraphQLService graphQl)
            : base(commandBus)
        {
            this.contentQuery    = contentQuery;
            this.contentWorkflow = contentWorkflow;

            this.graphQl = graphQl;
        }
Example #12
0
        public static async Task CanUpdate(IContentEntity content, IContentWorkflow contentWorkflow, UpdateContent command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot update content.", e =>
            {
                ValidateData(command, e);
            });

            await ValidateCanUpdate(content, contentWorkflow);
        }
Example #13
0
        public static async Task CanPatch(ContentState content, IContentWorkflow contentWorkflow, PatchContent command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot patch content.", e =>
            {
                ValidateData(command, e);
            });

            await ValidateCanUpdate(content, contentWorkflow, command.User);
        }
Example #14
0
        public ContentsController(ICommandBus commandBus,
                                  IContentQueryService contentQuery,
                                  IContentWorkflow contentWorkflow,
                                  GraphQLMiddleware graphQLMiddleware)
            : base(commandBus)
        {
            this.contentQuery    = contentQuery;
            this.contentWorkflow = contentWorkflow;

            this.graphQLMiddleware = graphQLMiddleware;
        }
Example #15
0
        public static async Task CanUpdate(ContentState content, IContentWorkflow contentWorkflow, UpdateContent command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                ValidateData(command, e);
            });

            await ValidateCanUpdate(content, contentWorkflow, command.User);
        }
Example #16
0
        public ContentEnricher(IAssetQueryService assetQuery, IAssetUrlGenerator assetUrlGenerator, Lazy <IContentQueryService> contentQuery, IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(assetQuery);
            Guard.NotNull(assetUrlGenerator);
            Guard.NotNull(contentQuery);
            Guard.NotNull(contentWorkflow);

            this.assetQuery        = assetQuery;
            this.assetUrlGenerator = assetUrlGenerator;
            this.contentQuery      = contentQuery;
            this.contentWorkflow   = contentWorkflow;
        }
Example #17
0
        public ContentsController(ICommandBus commandBus,
                                  IContentQueryService contentQuery,
                                  IContentWorkflow contentWorkflow,
                                  IGraphQLService graphQl,
                                  IOptions <MyContentsControllerOptions> controllerOptions)
            : base(commandBus)
        {
            this.contentQuery      = contentQuery;
            this.contentWorkflow   = contentWorkflow;
            this.controllerOptions = controllerOptions.Value;

            this.graphQl = graphQl;
        }
Example #18
0
        public static async Task CanPatch(IContentEntity content, IContentWorkflow contentWorkflow, PatchContent command, bool isProposal)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot patch content.", e =>
            {
                ValidateData(command, e);
            });

            if (!isProposal)
            {
                await ValidateCanUpdate(content, contentWorkflow);
            }
        }
Example #19
0
        public static async Task CanUpdate(IContentEntity content, IContentWorkflow contentWorkflow, UpdateContent command, bool isProposal)
        {
            Guard.NotNull(command);

            Validate.It(() => "Cannot update content.", e =>
            {
                ValidateData(command, e);
            });

            if (!isProposal)
            {
                await ValidateCanUpdate(content, contentWorkflow, command.User);
            }
        }
Example #20
0
        public static async Task CanPatch(PatchContent command,
                                          IContentEntity content,
                                          IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(command, nameof(command));

            CheckPermission(content, command, Permissions.AppContentsUpdate);

            Validate.It(e =>
            {
                ValidateData(command, e);
            });

            await ValidateCanUpdate(content, contentWorkflow, command.User);
        }
Example #21
0
        public static Task CanChangeStatus(ChangeContentStatus command,
                                           IContentEntity content,
                                           IContentWorkflow contentWorkflow,
                                           IContentRepository contentRepository,
                                           ISchemaEntity schema)
        {
            Guard.NotNull(command, nameof(command));

            CheckPermission(content, command, Permissions.AppContentsChangeStatus);

            if (schema.SchemaDef.IsSingleton)
            {
                if (content.NewStatus == null || command.Status != Status.Published)
                {
                    throw new DomainException(T.Get("contents.singletonNotChangeable"));
                }

                return(Task.CompletedTask);
            }

            return(Validate.It(async e =>
            {
                var status = content.NewStatus ?? content.Status;

                if (!await contentWorkflow.CanMoveToAsync(content, status, command.Status, command.User))
                {
                    var values = new { oldStatus = status, newStatus = command.Status };

                    e(T.Get("contents.statusTransitionNotAllowed", values), nameof(command.Status));
                }

                if (content.Status == Status.Published && command.CheckReferrers)
                {
                    var hasReferrer = await contentRepository.HasReferrersAsync(content.AppId.Id, command.ContentId, SearchScope.Published);

                    if (hasReferrer)
                    {
                        throw new DomainException(T.Get("contents.referenced"));
                    }
                }

                if (command.DueTime.HasValue && command.DueTime.Value < SystemClock.Instance.GetCurrentInstant())
                {
                    e(T.Get("contents.statusSchedulingNotInFuture"), nameof(command.DueTime));
                }
            }));
        }
Example #22
0
        private async Task CreateLinksAsync(Resources resources, IContentWorkflow workflow, ISchemaEntity schema)
        {
            var values = new { app = resources.App, schema = schema.SchemaDef.Name };

            AddSelfLink(resources.Url <ContentsController>(x => nameof(x.GetContents), values));

            if (resources.CanCreateContent(values.schema))
            {
                AddPostLink("create", resources.Url <ContentsController>(x => nameof(x.PostContent), values));

                if (resources.CanChangeStatus(values.schema) && await workflow.CanPublishInitialAsync(schema, resources.Context.User))
                {
                    var publishValues = new { values.app, values.schema, publish = true };

                    AddPostLink("create/publish", resources.Url <ContentsController>(x => nameof(x.PostContent), publishValues));
                }
            }
        }
Example #23
0
        public static async Task CanCreate(ISchemaEntity schema, IContentWorkflow contentWorkflow, CreateContent command)
        {
            Guard.NotNull(command, nameof(command));

            if (schema.SchemaDef.IsSingleton && command.ContentId != schema.Id)
            {
                throw new DomainException("Singleton content cannot be created.");
            }

            if (command.Publish && !await contentWorkflow.CanPublishOnCreateAsync(schema, command.Data, command.User))
            {
                throw new DomainException("Content workflow prevents publishing.");
            }

            Validate.It(() => "Cannot created content.", e =>
            {
                ValidateData(command, e);
            });
        }
Example #24
0
        public static async Task CanCreate(CreateContent command, IContentWorkflow contentWorkflow, ISchemaEntity schema)
        {
            Guard.NotNull(command, nameof(command));

            if (schema.SchemaDef.IsSingleton && command.ContentId != schema.Id)
            {
                throw new DomainException(T.Get("contents.singletonNotCreatable"));
            }

            if (command.Publish && !await contentWorkflow.CanPublishOnCreateAsync(schema, command.Data, command.User))
            {
                throw new DomainException(T.Get("contents.workflowErorPublishing"));
            }

            Validate.It(e =>
            {
                ValidateData(command, e);
            });
        }
Example #25
0
        public ContentDomainObject(
            IStore <Guid> store,
            ISemanticLog log,
            IAppProvider appProvider,
            IAssetRepository assetRepository,
            IScriptEngine scriptEngine,
            IContentWorkflow contentWorkflow,
            IContentRepository contentRepository)
            : base(store, log)
        {
            Guard.NotNull(appProvider);
            Guard.NotNull(scriptEngine);
            Guard.NotNull(assetRepository);
            Guard.NotNull(contentWorkflow);
            Guard.NotNull(contentRepository);

            this.appProvider       = appProvider;
            this.scriptEngine      = scriptEngine;
            this.assetRepository   = assetRepository;
            this.contentWorkflow   = contentWorkflow;
            this.contentRepository = contentRepository;
        }
Example #26
0
        public static async Task <ContentsDto> FromContentsAsync(IResultList <IEnrichedContentEntity> contents, Resources resources,
                                                                 ISchemaEntity?schema, IContentWorkflow workflow)
        {
            var result = new ContentsDto
            {
                Total = contents.Total,
                Items = contents.Select(x => ContentDto.FromDomain(x, resources)).ToArray()
            };

            if (schema != null)
            {
                await result.AssignStatusesAsync(workflow, schema);

                await result.CreateLinksAsync(resources, workflow, schema);
            }

            return(result);
        }
Example #27
0
        private async Task AssignStatusesAsync(IContentWorkflow workflow, ISchemaEntity schema)
        {
            var allStatuses = await workflow.GetAllAsync(schema);

            Statuses = allStatuses.Select(StatusInfoDto.FromStatusInfo).ToArray();
        }
Example #28
0
        public static async Task <ContentsDto> FromContentsAsync(IResultList <IEnrichedContentEntity> contents, Context context, ApiController controller,
                                                                 ISchemaEntity?schema, IContentWorkflow workflow)
        {
            var result = new ContentsDto
            {
                Total = contents.Total,
                Items = contents.Select(x => ContentDto.FromContent(context, x, controller)).ToArray()
            };

            if (schema != null)
            {
                await result.AssignStatusesAsync(workflow, schema);

                result.CreateLinks(controller, schema.AppId.Name, schema.SchemaDef.Name);
            }

            return(result);
        }
Example #29
0
 public EnrichWithWorkflows(IContentWorkflow contentWorkflow)
 {
     this.contentWorkflow = contentWorkflow;
 }
Example #30
0
        public EnrichWithWorkflows(IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(contentWorkflow, nameof(contentWorkflow));

            this.contentWorkflow = contentWorkflow;
        }