Ejemplo n.º 1
0
        public ComponentUpdateValidator(IAlfrescoHttpClient alfrescoHttpClient, INodesService nodesService, IIdentityUser identityUser, IDocumentService documentService)
        {
            _alfrescoHttpClient = alfrescoHttpClient;
            _nodesService       = nodesService;
            _documentService    = documentService;

            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");
            });

            RuleFor(x => x.Body.Properties ?? new Dictionary <string, object>())
            .Must(x => !_ignoreList.Any(x.ContainsKey))
            .WithMessage($"You are not allowed to pass properties {string.Join(", ", _ignoreList)}.");

            RuleFor(x => x)
            .MustAsync(CheckMainComponent);
        }
        public DocumentChangeFileMarkValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);


                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");
            });
        }
Ejemplo n.º 3
0
        public FileDocumentAddValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId);
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");
            });
        }
Ejemplo n.º 4
0
        public ShipmentReturnValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null);
            })
            .WithName(x => nameof(x))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");
            });

            RuleFor(x => x.Reason)
            .MinimumLength(4)
            .MaximumLength(30)
            .WithName("Reason")
            .WithMessage("Reason must be at least 4 chatacters long and maximum 30 characters");
        }
        public DocumentToRepositoryValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupMember = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.RepositoryGroup, ImmutableList <Parameter> .Empty
                                                                        .Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupMember != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.Group))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x)
                .Must(y => _groupMember?.List?.Entries?.Any(q => q.Entry.Id == y.Group) ?? false)
                .WithName(x => "Group")
                .WithMessage(x => $"Group {x.Group} does not exists.");
            });
        }
        public ShipmentCancelValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                await context.NodeIds.ForEachAsync(async x => { _nodeEntries.Add(await alfrescoHttpClient.GetNodeInfo(x)); });

                return(_groupPaging != null && _nodeEntries?.Count != 0);
            })
            .WithName("Document")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x)
                .Must(y => _nodeEntries?.All(q => q.Entry.NodeType.StartsWith("ssl:shipment")) ?? false)
                .WithName(x => "NodeIds")
                .WithMessage("Not all provided nodes are type of shipment.");
            });
        }
        public DocumentReturnForReworkValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));

                return(_groupPaging != null && _nodeEntry?.Entry?.Id != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ??
                      false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceDocumentsForProcessingForSignature(identityUser.RequestGroup)) ||
                      _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesDocumentsForProcessingForSignature(identityUser.RequestGroup)))
                .WithMessage($"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)} or {SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)}.");
            });

            RuleFor(x => x.Body.Reason)
            .MinimumLength(4)
            .MaximumLength(30)
            .When(x => x.Body != null)
            .WithMessage("Reason must be at least 4 characters long but maximum 30 characters long");
        }
Ejemplo n.º 8
0
        public DocumentCreateValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x)
                .Must(y => identityUser.RequestGroup == SpisumNames.Groups.MailroomGroup)
                .WithName(x => "Group")
                .WithMessage($"User is not member of {SpisumNames.Groups.MailroomGroup} group.");
            });

            RuleFor(x => x.DocumentType)
            .Must(x => x == null || CodeLists.DocumentTypes.List.TryGetValue(x, out string _))
            .WithMessage($"DocumentType must be one of [{string.Join(",", CodeLists.DocumentTypes.List.Select(x => x.Key).ToArray())}]");
        }
        public DocumentFromSignatureValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.Path.Name.EndsWith(SpisumNames.Paths.DocumentsForSignature) ||
                      _nodeEntry.Entry.Path.Name.EndsWith(SpisumNames.Paths.FilesDocumentsForSignature))
                .WithMessage(
                    $"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessingForSignature(identityUser.RequestGroup)} or " +
                    $"{SpisumNames.Paths.EvidenceFilesDocumentsForProcessingForSignature(identityUser.RequestGroup)}.");
            });
        }
        public DocumentForSignatureValidator(
            IAlfrescoHttpClient alfrescoHttpClient,
            IIdentityUser identityUser,
            IAlfrescoConfiguration alfrescoConfiguration,
            ISimpleMemoryCache simpleMemoryCache,
            ISystemLoginService systemLoginService)
        {
            var adminHttpClient = new AlfrescoHttpClient(alfrescoConfiguration, new AdminAuthentification(simpleMemoryCache, alfrescoConfiguration, systemLoginService));

            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));
                _groupPagingCurrentUser = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _groupPagingNextOwner   = await adminHttpClient.GetPersonGroups(context.Body.User);

                return(_nodeEntry?.Entry?.Id != null && _groupPagingCurrentUser != null && _groupPagingNextOwner != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPagingCurrentUser?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x)
                .Must(y => _groupPagingNextOwner?.List?.Entries?.Any(q => q.Entry.Id == $"{y.Body.Group}_Sign") ?? false)
                .WithName(x => "Group")
                .WithMessage("User for signing isn't member of group with postfix _Sign.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)) ||
                      _nodeEntry.Entry.Path.Name.Equals(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)))
                .WithMessage($"NodeId must be in path {SpisumNames.Paths.EvidenceDocumentsForProcessing(identityUser.RequestGroup)} or {SpisumNames.Paths.EvidenceFilesDocumentsForProcessing(identityUser.RequestGroup)}.");
            });

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x?.Body?.User))
            .When(x => x?.Body != null)
            .WithName(x => nameof(x.Body.User))
            .WithMessage("You have to fill user.");

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x?.Body?.Group))
            .When(x => x?.Body != null)
            .WithName(x => nameof(x.Body.Group))
            .WithMessage("You have to fill group.");
        }
        public ConceptComponentUpdateContentValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeParents = await alfrescoHttpClient.GetNodeParents(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where,
                                                                                          $"(assocType='{SpisumNames.Associations.Components}')"
                                                                                          , ParameterType.QueryString)));

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Concept}.");

                RuleFor(x => x)
                .Must(c => _nodeParents?.List?.Entries?.Any(y => y?.Entry?.Id == c.NodeId) ?? false)
                .WithMessage("Provided component is not associated with nodeId or cannot be canceled.");
            });
        }
        public DocumentShreddingCancelDiscardValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}",
                                                                                     ParameterType.QueryString)));
                _parentRM = await alfrescoHttpClient.GetNodeParents(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.DocumentInRepository}')", ParameterType.QueryString))
                                                                    .Add(new Parameter(AlfrescoNames.Headers.MaxItems, "1", ParameterType.QueryString)));



                if (_parentRM?.List?.Entries?.Count == 1)
                {
                    var documentInfoRM       = await alfrescoHttpClient.GetNodeInfo(_parentRM?.List?.Entries?.FirstOrDefault()?.Entry?.Id);
                    var rmdocumentProperties = documentInfoRM?.Entry?.Properties?.As <JObject>().ToDictionary();
                    _cutOffDate = rmdocumentProperties.GetNestedValueOrDefault(AlfrescoNames.ContentModel.CutOffDate)?.ToString();
                }

                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != null && _groupPaging != null && _parentRM != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x.NodeId)
                .Must(x => _parentRM?.List?.Entries.Count == 1)
                .WithMessage(x => "Document is not in record management");

                RuleFor(x => x.NodeId)
                .Must(x => !string.IsNullOrWhiteSpace(_cutOffDate))
                .WithMessage(x => "Cut off date is not set yet");

                RuleFor(x => x.NodeId)
                .Must(x =>
                {
                    var documentProperties = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    _discardTo             = documentProperties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardTo)?.ToString();

                    return(!string.IsNullOrWhiteSpace(_discardTo));
                })
                .WithMessage(x => $"{SpisumNames.Properties.DiscardTo} property is not set");
            });
        }
Ejemplo n.º 13
0
        public ShipmentCreatePublishValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));
            });

            RuleFor(x => x.Body.Components)
            .Must(y => y?.Count > 0)
            .When(x => x.Body != null)
            .WithName(x => "Components")
            .WithMessage("Components cannot be empty");

            RuleFor(x => x.Body.DateFrom)
            .Must(y => y.HasValue && CompareDateTime(y.Value))
            .When(x => x.Body != null)
            .WithName(x => "DateFrom")
            .WithMessage("DateFrom cannot be in past");

            RuleFor(x => x.Body.Days)
            .Must(y => y.HasValue ? y.Value > 0 : true)
            .When(x => x.Body != null)
            .WithName(x => "Days")
            .WithMessage("Days must be greater than 0");

            RuleFor(x => x.Body.Note)
            .MaximumLength(255)
            .When(x => x.Body != null)
            .WithName(x => "Note")
            .WithMessage("Message cannot be longer than 255 characters");
        }
Ejemplo n.º 14
0
        public FileCloseValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path},{AlfrescoNames.Includes.Properties}", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null && _nodeEntry?.Entry?.Id != null);
            })
            .WithName("Document")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");
            });

            RuleFor(x => x)
            .Must(x =>
            {
                if (x?.Body?.SettleMethod != "jinyZpusob")
                {
                    return(true);
                }

                if (x?.Body?.CustomSettleMethod == null || x?.Body?.SettleReason == null)
                {
                    return(false);
                }

                if (x.Body.CustomSettleMethod.Length < 4 || x.Body.SettleReason.Length < 4)
                {
                    throw new BadRequestException(ErrorCodes.V_MIN_TEXT);
                }

                x.Body.CustomSettleMethod = x.Body.CustomSettleMethod.CutLength(30);
                x.Body.SettleReason       = x.Body.SettleReason.CutLength(30);

                return(true);
            })
            .WithName(x => nameof(x.Body.SettleMethod))
            .WithMessage("You have to fill CustomSettleMethod and SettleReason.");
        }
        public DocumentComponentOutputFormatValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.ComponentId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.ComponentId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Component ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Email ||
                      _nodeEntry?.Entry?.NodeType == AlfrescoNames.ContentModel.Content ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.EmailComponent ||
                      _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.DataBoxComponent)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Component}.");

                RuleFor(x => x)
                .Must(x =>
                {
                    var properties           = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var fileIsInOutputFormat = properties.GetNestedValueOrDefault(SpisumNames.Properties.FileIsInOutputFormat)?.ToString();

                    return(fileIsInOutputFormat != "yes");
                })
                .WithMessage("Component is already in output format.");
            });

            RuleFor(x => x.Body.Reason)
            .MinimumLength(4)
            .MaximumLength(30)
            .NotNull()
            .When(x => x.Body != null)
            .WithName(x => nameof(x.Body.Reason));
        }
Ejemplo n.º 16
0
        public FileCancelValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _secondaryChildren = await alfrescoHttpClient.GetNodeSecondaryChildren(context.NodeId, ImmutableList <Parameter> .Empty
                                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Documents}')", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _secondaryChildren != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");

                RuleFor(x => x)
                .Must(x => _secondaryChildren?.List?.Entries?.Count == null || !_secondaryChildren.List.Entries.Any())
                .OnAnyFailure(x => throw new BadRequestException(ErrorCodes.V_FILE_CANCEL_CHILDREN));

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceFilesOpen(identityUser.RequestGroup), StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("File can't be cancelled"));

                RuleFor(x => x.NodeId)
                .Must(x => IsNodePathAllowed(x, identityUser.RequestGroup));
            });

            RuleFor(x => x)
            .Must(CheckReasonLength);
        }
        public FileShipmentSendValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

                await context.ShipmentsId?.ForEachAsync(async x =>
                {
                    _parents.Add(new ParentShipmentInfo
                    {
                        ShipmentId = x,
                        Parents    = await nodesService.GetParentsByAssociation(x, new List <string>
                        {
                            SpisumNames.Associations.ShipmentsCreated, SpisumNames.Associations.ShipmentsToReturn
                        })
                    });
                });

                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null && _nodeEntry != null && _parents != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.File}");

                RuleFor(x => x)
                .Must(y => _parents.All(p => p.Parents.Any(c => c.Entry.Id == y.NodeId)))
                .WithName(x => "Shipments")
                .WithMessage($"Not all shipments are type of {SpisumNames.Associations.ShipmentsCreated} or {SpisumNames.Associations.ShipmentsToReturn} or not all shipments are not associated with nodeId");
            });
        }
        public DocumentShreddingSValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties}, {AlfrescoNames.Includes.Path}", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(x =>
                      _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocumentsStored, StringComparison.OrdinalIgnoreCase) == true ||
                      _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocumentsRented, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException($"Document must be in {SpisumNames.Paths.RepositoryDocumentsStored} or {SpisumNames.Paths.RepositoryDocumentsRented} path."));

                RuleFor(x => x.NodeId)
                .Must(x =>
                {
                    var nodeProperties = _nodeEntry.Entry.Properties.As <JObject>().ToDictionary();
                    var retentionMark  = nodeProperties.GetNestedValueOrDefault(SpisumNames.Properties.RetentionMark)?.ToString();

                    return(retentionMark == "A" || retentionMark == "V");
                })
                .WithMessage(x => "RetentionMark isn't A or V.");
            });
        }
Ejemplo n.º 19
0
        public DocumentFavouriteRemoveValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");
            });
        }
Ejemplo n.º 20
0
        public ShipmentDispatchPostValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _nodeParents = await nodesService.GetParentsByAssociation(context.NodeId, new List <string> {
                    SpisumNames.Associations.ShipmentsToDispatch
                });

                return(_groupPaging != null && _nodeEntry != null && _nodeParents != null);
            })
            .WithName("Document")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(q => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.ShipmentPost)
                .WithName("NodeId")
                .WithMessage($"Provided node must be type of {SpisumNames.NodeTypes.ShipmentPost}.");

                RuleFor(x => x.NodeId)
                .Must(q => _nodeEntry?.Entry?.Path?.Name == AlfrescoNames.Prefixes.Path + SpisumNames.Paths.DispatchToDispatch)
                .WithName("NodeId")
                .WithMessage($"Provided node must be located in {AlfrescoNames.Prefixes.Path + SpisumNames.Paths.DispatchToDispatch}.");

                RuleFor(x => x.NodeId)
                .Must(q => _nodeParents?.Count > 0)
                .WithName("NodeId")
                .WithMessage($"Provided node is not child type of {SpisumNames.Associations.ShipmentsToDispatch}");
            });
        }
Ejemplo n.º 21
0
        public ConceptCancelValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Concept}.");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Concept must be in evidence site."));

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.EvidenceConcepts(identityUser.RequestGroup), StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Concept can't be cancelled"));

                RuleFor(x => x.NodeId)
                .Must(IsNodePathAllowed);

                RuleFor(x => x)
                .Must(CheckReasonLength);
            });
        }
Ejemplo n.º 22
0
        public FileCreateValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.DocumentId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties},{AlfrescoNames.Includes.Permissions},{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));
                _associationPaging = await alfrescoHttpClient.GetNodeParents(context.DocumentId, ImmutableList <Parameter> .Empty
                                                                             .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                             .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Documents}')", ParameterType.QueryString))
                                                                             .Add(new Parameter(AlfrescoNames.Headers.MaxItems, "1", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _associationPaging != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.DocumentId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.DocumentId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x.DocumentId)
                .Must(x => _associationPaging.List.Entries.Count == 0)
                .WithMessage(x => "Provided document is already in file");
            });
        }
Ejemplo n.º 23
0
        public DocumentOwnerAcceptValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            _identityUser = identityUser;

            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include,
                                                                                     $"{AlfrescoNames.Includes.Properties},{AlfrescoNames.Includes.Permissions}, {AlfrescoNames.Includes.Path}",
                                                                                     ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(HasAction)
                .WithMessage("NodeIs has no accept action.");

                RuleFor(x => x.NodeId)
                .Must(CanUserMakeAction)
                .WithMessage("User has no access to this action.");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));
            });
        }
        public ConceptToDocumentValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Concept}.");
            });

            RuleFor(x => x.Body.SettleTo)
            .Must(x => x.HasValue ? x.Value.Date >= DateTime.UtcNow.Date : true)
            .When(w => w.Body != null)
            .WithMessage("SettleTo can't be in the past");

            RuleFor(x => x.Body.AttachmentsCount)
            .GreaterThanOrEqualTo(0)
            .When(w => w.Body != null)
            .WithMessage("AttachmentCount can't be negative number");
        }
        public DocumentBorrowValidator(IAlfrescoHttpClient alfrescoHttpClient,
                                       IIdentityUser identityUser,
                                       IAlfrescoConfiguration alfrescoConfiguration,
                                       ISimpleMemoryCache simpleMemoryCache,
                                       ISystemLoginService systemLoginService)
        {
            var adminHttpClient = new AlfrescoHttpClient(alfrescoConfiguration, new AdminAuthentification(simpleMemoryCache, alfrescoConfiguration, systemLoginService));

            _identityUser = identityUser;

            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

                var documentProperties = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                _borrowedUser          = documentProperties.GetNestedValueOrDefault(SpisumNames.Properties.Borrower)?.ToString();

                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                _groupRepository = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.RepositoryGroup,
                                                                            ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));

                _groupPagingNextOwner = await adminHttpClient.GetPersonGroups(context.Body.User);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _groupPagingNextOwner != null && _groupRepository != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y =>
                {
                    return(_groupPagingNextOwner?.List?.Entries?.Any(q => q.Entry.Id == y.Body.Group) ?? false);
                })
                .WithName(x => "User")
                .WithMessage("User isn't member of the Group.");

                RuleFor(x => x)
                .Must(y =>
                {
                    return(_groupRepository?.List?.Entries?.Any(x => x.Entry.Id == identityUser.RequestGroup) ?? false);
                })
                .WithName(x => "User")
                .WithMessage("User isn't member of repository group");

                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.RepositoryDocuments, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in repository site."));

                RuleFor(x => x)
                .Must(x => string.IsNullOrWhiteSpace(_borrowedUser))
                .WithMessage("Document is already borrowed");
            });
        }
Ejemplo n.º 26
0
        public DocumentComponentUpdateContentValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeParents = await alfrescoHttpClient.GetNodeParents(context.ComponentId, ImmutableList <Parameter> .Empty
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString))
                                                                       .Add(new Parameter(AlfrescoNames.Headers.Where,
                                                                                          $"(assocType='{SpisumNames.Associations.Components}')"
                                                                                          , ParameterType.QueryString)));

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(c => _nodeParents?.List?.Entries?.Any(y => y?.Entry?.Id == c.NodeId) ?? false)
                .WithMessage("Provided component is not associated with nodeId or cannot be canceled.");

                RuleFor(x => x)
                .Must(x =>
                {
                    if (_nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Concept)
                    {
                        return(true);
                    }

                    if (_nodeEntry?.Entry?.IsLocked == true)
                    {
                        return(false);
                    }

                    var properties   = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var form         = properties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString();
                    var senderType   = properties.GetNestedValueOrDefault(SpisumNames.Properties.SenderType)?.ToString();
                    var documentType = properties.GetNestedValueOrDefault(SpisumNames.Properties.DocumentType)?.ToString();

                    if (form == "analog" || documentType == "technicalDataCarries" || form == "digital" && senderType == SpisumNames.SenderType.Own)
                    {
                        return(true);
                    }

                    return(false);
                })
                .OnAnyFailure(x => throw new BadRequestException("Adding component is not allowed."));
            });
        }
Ejemplo n.º 27
0
        public ShipmentCreatePostValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));
            });

            RuleFor(x => x.Body.Address1)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("Address1 is too long");

            RuleFor(x => x.Body.Address2)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("Address2 is too long");

            RuleFor(x => x.Body.Address3)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("Address3 is too long");

            RuleFor(x => x.Body.Address4)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("Address4 is too long");

            RuleFor(x => x.Body.AddressStreet)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("AddressStreet is too long");

            RuleFor(x => x.Body.AddressCity)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("AddressCity is too long");

            RuleFor(x => x.Body.AddressZip)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("AddressZip is too long");

            RuleFor(x => x.Body.AddressState)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("AddressState is too long");

            RuleFor(x => x.Body.PostTypeOther)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("PostTypeOther is too long");

            RuleFor(x => x.Body.PostItemTypeOther)
            .Must(x => CheckLength(x, 100))
            .When(x => x.Body != null)
            .WithMessage("PostItemTypeOther is too long");

            RuleFor(x => x.Body.PostItemCashOnDelivery)
            .NotNull()
            .GreaterThanOrEqualTo(0)
            .When(x => x.Body != null && x.Body.PostType.Any(x => x == "Dobirka"))
            .WithMessage("PostItemCashOnDelivery is mandatory and cannot be negative number");

            RuleFor(x => x.Body.PostItemStatedPrice)
            .NotNull()
            .GreaterThanOrEqualTo(0)
            .When(x => x.Body != null && x.Body.PostType.Any(x => x == "UdanaCena"))
            .WithMessage("PostItemStatedPrice is mandatory and cannot be negative number");
        }
Ejemplo n.º 28
0
        public DocumentOwnerHandOverValidator(
            IAlfrescoHttpClient alfrescoHttpClient,
            IIdentityUser identityUser,
            IAlfrescoConfiguration alfrescoConfiguration,
            ISimpleMemoryCache simpleMemoryCache,
            ISystemLoginService systemLoginService)
        {
            var adminHttpClient = new AlfrescoHttpClient(alfrescoConfiguration, new AdminAuthentification(simpleMemoryCache, alfrescoConfiguration, systemLoginService));

            _identityUser = identityUser;

            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Properties},{AlfrescoNames.Includes.Permissions},{AlfrescoNames.Includes.Path}", ParameterType.QueryString)));
                _groupPagingCurrentUser = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                if (context?.Body?.NextOwner != null)
                {
                    _groupPagingNextOwner = await adminHttpClient.GetPersonGroups(context.Body.NextOwner);
                }

                return(_nodeEntry?.Entry?.Id != null && _groupPagingCurrentUser != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y =>
                {
                    if (y?.Body?.NextOwner == null)
                    {
                        return(true);
                    }
                    return(_groupPagingNextOwner?.List?.Entries?.Any(q => q.Entry.Id == y.Body.NextGroup) ?? false);
                })
                .WithName(x => "Group")
                .WithMessage("NextOwner isn't member of group NextGroup.");

                RuleFor(x => x)
                .Must(y => _groupPagingCurrentUser?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x)
                .Must(x => _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.Evidence, StringComparison.OrdinalIgnoreCase) == true)
                .OnAnyFailure(x => throw new BadRequestException("Document must be in evidence site."));

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document || _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.File || _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Concept)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document} or {SpisumNames.NodeTypes.File} or {SpisumNames.NodeTypes.Concept}");

                RuleFor(x => x.NodeId)
                .Must(HasAction)
                .WithName(x => nameof(x.NodeId))
                .WithMessage("NodeIs is being handled to different owner. You have cancel it first.");

                RuleFor(x => x.NodeId)
                .Must(CanUserMakeAction)
                .WithMessage("User has no access to this action.");
            });

            RuleFor(x => x)
            .Must(x => !string.IsNullOrEmpty(x?.Body?.NextOwner) || !string.IsNullOrEmpty(x?.Body?.NextGroup))
            .WithName(x => nameof(x.Body.NextOwner))
            .WithMessage("You have to fill nextGroup or nextOwner.");

            RuleFor(x => x)
            .Must(x => x?.Body?.NextOwner == null || !string.IsNullOrEmpty(x?.Body?.NextGroup))
            .WithName(x => nameof(x.Body.NextGroup))
            .WithMessage("You have to fill NextGroup.");
        }
Ejemplo n.º 29
0
        public DocumentComponentCreateValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                  .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path},{AlfrescoNames.Includes.IsLocked}", ParameterType.QueryString)));
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                return(_groupPaging != null && _nodeEntry?.Entry?.Id != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"NodeId must be type of {SpisumNames.NodeTypes.Document}.");

                RuleFor(x => x)
                .Must(x =>
                {
                    if (_nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.Concept)
                    {
                        return(true);
                    }

                    var properties     = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var senderType     = properties.GetNestedValueOrDefault(SpisumNames.Properties.SenderType)?.ToString();
                    var isPathMailroom = _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomUnfinished,
                                                                                   StringComparison.OrdinalIgnoreCase);

                    if (isPathMailroom != true && senderType != SpisumNames.SenderType.Own)
                    {
                        return(false);
                    }

                    var form         = properties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString();
                    var documentType = properties.GetNestedValueOrDefault(SpisumNames.Properties.DocumentType)?.ToString();

                    var isLocked = _nodeEntry?.Entry?.IsLocked;

                    if (isLocked == true)
                    {
                        return(false);
                    }

                    if (form == "analog" || documentType == "technicalDataCarries" || form == "digital" && senderType == SpisumNames.SenderType.Own)
                    {
                        return(true);
                    }

                    return(false);
                })
                .OnAnyFailure(x => throw new BadRequestException("Adding component is not allowed."));
            });
        }
        public DocumentComponentDeleteValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                _nodeEntry   = await alfrescoHttpClient.GetNodeInfo(context.NodeId, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, $"{AlfrescoNames.Includes.Path},{AlfrescoNames.Includes.IsLocked}", ParameterType.QueryString)));
                await context.ComponentsId.ForEachAsync(async x =>
                {
                    _nodeParents.Add(new ParentsInfo
                    {
                        Parents = await nodesService.GetParentsByAssociation(x, new List <string> {
                            SpisumNames.Associations.DeletedComponents
                        }),
                        ComponentId = x
                    });
                });


                return(_groupPaging != null && _nodeEntry != null && _nodeParents.Count != 0);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(y => _groupPaging?.List?.Entries?.Any(q => q.Entry.Id == identityUser.RequestGroup) ?? false)
                .WithName(x => "Group")
                .WithMessage($"User isn't member of group {identityUser.RequestGroup}.");

                RuleFor(x => x.NodeId)
                .Must(y => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Document)
                .WithMessage($"Provided nodeId must be type of {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x.ComponentsId)
                .Must(y => _nodeParents.All(x => x.Parents.Count == 0))
                .WithMessage("One or more components were already canceleted/deleted");

                RuleFor(x => x)
                .Must(x =>
                {
                    var isPathMailroom = _nodeEntry?.Entry?.Path?.Name?.StartsWith(AlfrescoNames.Prefixes.Path + SpisumNames.Paths.MailRoomUnfinished,
                                                                                   StringComparison.OrdinalIgnoreCase);

                    if (isPathMailroom == null)
                    {
                        throw new BadRequestException("", "Something went wrong with document path");
                    }

                    var properties   = _nodeEntry?.Entry?.Properties?.As <JObject>().ToDictionary();
                    var form         = properties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString();
                    var documentType = properties.GetNestedValueOrDefault(SpisumNames.Properties.DocumentType)?.ToString();
                    var senderType   = properties.GetNestedValueOrDefault(SpisumNames.Properties.SenderType)?.ToString();
                    var isLocked     = _nodeEntry?.Entry?.IsLocked;

                    if (isPathMailroom.Value)
                    {
                        return(form == "analog" || documentType == "technicalDataCarries");
                    }

                    if (isLocked != null && !isLocked.Value && senderType == SpisumNames.SenderType.Own)
                    {
                        return(true);
                    }

                    return(false);
                })
                .OnAnyFailure(x => throw new BadRequestException("Adding component is not allowed."));
            });
        }