Exemplo n.º 1
0
        public void Before(Services.tmp.EntityOperation operation, EntityOperationContext context)
        {
            if (operation.IsEntity(Payment.ENTITY) && operation is EntityUpdate)
            {
                var update = operation as EntityUpdate;
                if (update.IsCreate())
                {
                    List <int> usersToAttach = new List <int>();
                    foreach (var attach in update.RelationUpdates.Where(ru => ru.Operation == Services.tmp.RelationOperation.Attach))
                    {
                        var em          = _domainService.Domain.Entities[attach.Entity];
                        var customerRel = em.Relations[em.Name, User.ENTITY, Payment.ROLE_CUSTOMER];
                        if (customerRel != null && customerRel.TypeFor(User.ENTITY) == RelationType.OneToMany)
                        {
                            var q = new EntityQuery2(User.ENTITY);
                            q.WhereRelated(new RelationQuery(em.Name, customerRel.Role, attach.Id.Value));
                            var cust = _repository.Read(q);
                            if (cust != null)
                            {
                                usersToAttach.Add(cust.Id);
                            }
                        }
                    }

                    foreach (var id in usersToAttach)
                    {
                        update.Attach(User.ENTITY, Payment.ROLE_CUSTOMER, id);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result)
 {
     if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) &&
         operation is EntityDelete &&
         result.Success)
     {
         var file = context.Get <NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION);
         if (file != null)
         {
             _fileService.DeleteFileContent(Guid.Parse(file.ContentPath));
         }
     }
 }
Exemplo n.º 3
0
        public void Before(Services.tmp.EntityOperation operation, EntityOperationContext context)
        {
            if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityUpdate)
            {
                var update = operation as EntityUpdate;
                if (update.IsCreate())
                {
                    var access = update.Attach(NbuLibrary.Core.Domain.User.ENTITY, Roles.Access, _securityService.CurrentUser.Id);
                    access.Set("Type", FileAccessType.Owner);
                }
                else
                {
                    var accessUpdates = update.GetMultipleRelationUpdates(User.ENTITY, Roles.Access);
                    if (accessUpdates != null)
                    {
                        foreach (var ac in accessUpdates)
                        {
                            if (ac.Operation == RelationOperation.Detach)
                            {
                                continue;
                            }

                            if (ac.ContainsProperty("Type") && ac.Get <FileAccessType>("Type") == FileAccessType.Token)
                            {
                                ac.Set("Token", Guid.NewGuid());//TODO: token based file access
                            }
                        }
                    }
                }
            }
            else if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityDelete)
            {
                var file = _fileService.GetFile(operation.Id.Value);
                context.Set <NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION, file);
            }
        }
Exemplo n.º 4
0
 public InspectionResult Inspect(Services.tmp.EntityOperation operation)
 {
     if (operation.IsEntity(Payment.ENTITY) && operation is EntityUpdate)
     {
         var update = operation as EntityUpdate;
         if (update.IsCreate() && !update.ContainsProperty("Status"))
         {
             return(InspectionResult.Allow); //TODO-Finance: Everyone is allowed to create payments
         }
         else if (_securityService.HasModulePermission(_securityService.CurrentUser, FinanceModule.Id, Permissions.Approve))
         {
             return(InspectionResult.Allow);
         }
     }
     return(InspectionResult.None);
 }