Example #1
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);
        }
Example #2
0
 public FileController(
     IAlfrescoHttpClient alfrescoHttpClient,
     IAuditLogService auditLogService,
     IFileService fileService,
     IIdentityUser identityUser,
     INodesService nodesService,
     IShipmentsService shipmentsService,
     ITransactionHistoryService transactionHistoryService
     )
 {
     _alfrescoHttpClient        = alfrescoHttpClient;
     _auditLogService           = auditLogService;
     _fileService               = fileService;
     _identityUser              = identityUser;
     _nodesService              = nodesService;
     _shipmentsService          = shipmentsService;
     _transactionHistoryService = transactionHistoryService;
 }
Example #3
0
 public GroupValidator(IAlfrescoHttpClient alfrescoHttpClient)
 {
     RuleFor(o => o)
     .Cascade(CascadeMode.StopOnFirstFailure)
     .Must(o => new Regex(@"^([a-zA-Z0-9_]+)$").IsMatch(o.Id))
     .MustAsync(async(context, cancellationToken) =>
     {
         try
         {
             await alfrescoHttpClient.GetGroup($"{SpisumNames.Prefixes.Group}{context.Id}");
             return(false);
         }
         catch
         {
             return(true);
         }
     });
 }
        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");
            });
        }
Example #5
0
        public ComponentValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId);

                return(_nodeEntry?.Entry?.Id != null);
            })
            .WithName(x => nameof(x.NodeId))
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry?.Entry?.NodeType == SpisumNames.NodeTypes.Component)
                .OnAnyFailure(x => throw new BadRequestException($"NodeId {x.NodeId} must be type of {SpisumNames.NodeTypes.Component}"));
            });
        }
        public FileToRepositoryFileValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                _nodeEntry = await alfrescoHttpClient.GetNodeInfo(context.NodeId);

                return(_nodeEntry?.Entry?.Id != null);
            })
            .WithName("File")
            .WithMessage("Something went wrong with alfresco server.")
            .DependentRules(() =>
            {
                RuleFor(x => x.NodeId)
                .Must(x => _nodeEntry.Entry.NodeType == SpisumNames.NodeTypes.File)
                .OnAnyFailure(x => throw new Exception($"Provided nodeId must be NodeType of {SpisumNames.NodeTypes.File}"));
            });
        }
        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.");
            });
        }
Example #8
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}.");
            });
        }
Example #9
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);
            });
        }
Example #10
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}");
            });
        }
Example #11
0
        public UserUpdateValidator(IAlfrescoHttpClient alfrescoHttpClient)
        {
            RuleFor(o => o)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .MustAsync(async(context, cancellationToken) =>
            {
                var groups = new List <string>();
                groups.AddRangeUnique(context.Groups);
                groups.AddRangeUnique(context.SignGroups);
                groups.Add(context.MainGroup);

                foreach (var group in groups)
                {
                    if (!await groupExist(alfrescoHttpClient, group))
                    {
                        return(false);
                    }
                }

                return(true);
            });
        }
Example #12
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 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");
            });
        }
        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 MetadataController(IAlfrescoHttpClient alfrescoHttpClient)
 {
     _alfrescoHttpClient = alfrescoHttpClient;
 }
Example #16
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."));
            });
        }
Example #18
0
 public NodeController(IAlfrescoHttpClient alfrescoHttpClient)
 {
     _alfrescoHttpClient = alfrescoHttpClient;
 }
        public FileReturnValidator(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)));

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

                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);
                try
                {
                    var properties = _nodeEntry?.Entry?.Properties.As <JObject>().ToDictionary();
                    _form          = properties.GetNestedValueOrDefault(SpisumNames.Properties.Form)?.ToString();
                    _borrowedGroup = properties.GetNestedValueOrDefault(SpisumNames.Properties.BorrowGroup)?.ToString();
                    _group         = properties.GetNestedValueOrDefault(SpisumNames.Properties.Group)?.ToString();
                }
                catch
                {
                    // Just to be safe
                }

                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)
                .Must(y =>
                {
                    if ((_form == SpisumNames.Form.Analog || _form == SpisumNames.Form.Hybrid) && identityUser.RequestGroup == _group)
                    {
                        return(true);
                    }
                    if (_form == SpisumNames.Form.Digital && (identityUser.RequestGroup == _group || identityUser.RequestGroup == _borrowedGroup))
                    {
                        return(true);
                    }
                    return(false);
                })
                .WithName(x => "User")
                .WithMessage("User isn't member of group that can return this file.");

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

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

                RuleFor(x => x)
                .Must(x => !string.IsNullOrWhiteSpace(_borrowedUser))
                .WithMessage("File is not borrowed");
            });
        }
Example #20
0
 public QueriesController(IAlfrescoHttpClient alfrescoHttpClient)
 {
     _alfrescoHttpClient = alfrescoHttpClient;
 }
        public ShipmentUpdatePersonallyValidator(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)));
                _nodeParents = await nodesService.GetParentsByAssociation(context.NodeId, new List <string>
                {
                    SpisumNames.Associations.ShipmentsCreated,
                    SpisumNames.Associations.ShipmentsToReturn,
                    SpisumNames.Associations.ShipmentsToDispatch
                });
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                if (_nodeParents?.Any(x => x?.Entry?.Association?.AssocType == SpisumNames.Associations.ShipmentsToDispatch) ?? false)
                {
                    _groupToDispatch = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.DispatchGroup,
                                                                                ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));
                }

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _nodeParents != 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.ShipmentPersonally)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.ShipmentPersonally}");

                RuleFor(x => x)
                .Must(y => _nodeParents?.Any(q => q.Entry.NodeType == SpisumNames.NodeTypes.Document || q.Entry.NodeType == SpisumNames.NodeTypes.File) ?? false)
                .WithName(x => "Parent")
                .WithMessage($"Provided shipment does not have a parent type of {SpisumNames.NodeTypes.Document} or {SpisumNames.NodeTypes.File}");

                RuleFor(x => x)
                .Must(y => CheckDispatchGroup(identityUser.RequestGroup))
                .WithMessage(x => "Dispatch group")
                .WithMessage($"Requested group in not part of {SpisumNames.Groups.DispatchGroup}");
            });

            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");
        }
Example #22
0
 public GroupController(IAlfrescoHttpClient alfrescoHttpClient)
 {
     _alfrescoHttpClient = alfrescoHttpClient;
 }
Example #23
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."));
            });
        }
Example #24
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.");
        }
Example #25
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");
        }
Example #26
0
 public UsersController(IAlfrescoHttpClient alfrescoHttpClient, IInitialUserService initialUser, IUsersService usersService)
 {
     _alfrescoHttpClient = alfrescoHttpClient;
     _initialUser        = initialUser;
     _usersService       = usersService;
 }
Example #27
0
 public PersonService(IIdentityUser identityUser, IAlfrescoHttpClient alfrescoHttpClient)
 {
     _identityUser       = identityUser;
     _alfrescoHttpClient = alfrescoHttpClient;
 }
Example #28
0
        public ShipmentUpdateEmailValidator(IAlfrescoHttpClient alfrescoHttpClient, IIdentityUser identityUser, INodesService nodesService, IEmailHttpClient emailHttpClient)
        {
            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)));
                _nodeParents = await nodesService.GetParentsByAssociation(context.NodeId, new List <string>
                {
                    SpisumNames.Associations.ShipmentsCreated,
                    SpisumNames.Associations.ShipmentsToReturn,
                    SpisumNames.Associations.ShipmentsToDispatch
                });
                _groupPaging = await alfrescoHttpClient.GetPersonGroups(identityUser.Id);

                try { _accounts = await emailHttpClient.Accounts(); } catch { }


                if (_nodeParents?.Any(x => x?.Entry?.Association?.AssocType == SpisumNames.Associations.ShipmentsToDispatch) ?? false)
                {
                    _groupToDispatch = await alfrescoHttpClient.GetGroupMembers(SpisumNames.Groups.DispatchGroup,
                                                                                ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));
                }

                return(_nodeEntry?.Entry?.Id != null && _groupPaging != null && _nodeParents != null && _accounts != 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.ShipmentEmail)
                .WithMessage(x => $"Provided nodeId must be NodeType {SpisumNames.NodeTypes.ShipmentEmail}");

                RuleFor(x => x)
                .Must(y => _nodeParents?.Any(q => q.Entry.NodeType == SpisumNames.NodeTypes.Document) ?? false)
                .WithName(x => "Parent")
                .WithMessage($"Provided shipment does not have a parent type of {SpisumNames.NodeTypes.Document}");

                RuleFor(x => x)
                .Must(y => CheckDispatchGroup(identityUser.RequestGroup))
                .WithMessage(x => "Dispatch group")
                .WithMessage($"Requested group in not part of {SpisumNames.Groups.DispatchGroup}");

                RuleFor(x => x)
                .Must(x => _accounts.Count > 0)
                .WithMessage(x => "No email configuration on email server");

                RuleFor(x => x.Body.Sender)
                .Must(y => _accounts?.Any(x => x.Username == y) ?? false)
                .WithMessage(x => "Sender was not found in email configuration on email server");
            });

            RuleFor(x => x.Body.Recipient)
            .Must(x => EmailUtils.IsValidEmail(x))
            .When(x => x.Body != null)
            .WithName(x => "Recipient")
            .WithMessage("Recipient is not a valid email address");

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

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

            RuleFor(x => x.Body.Components)
            .Must(y => y.Count > 0)
            .WithName(x => "Components")
            .WithMessage("Components cannot be empty");
        }
        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");
            });
        }
Example #30
0
 public TestController(IAlfrescoHttpClient alfrescoHttpClient) => _alfrescoHttpClient = alfrescoHttpClient;