Ejemplo n.º 1
0
        public async Task <UpdateDocumentAssetCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateDocumentAssetCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .DocumentAssets
                           .Include(a => a.DocumentAssetTags)
                           .ThenInclude(a => a.Tag)
                           .AsNoTracking()
                           .FilterById(query.Id)
                           .SingleOrDefaultAsync();

            var result = new UpdateDocumentAssetCommand()
            {
                Description     = dbResult.Description,
                DocumentAssetId = dbResult.DocumentAssetId,
                Title           = dbResult.Title
            };

            result.Tags = dbResult
                          .DocumentAssetTags
                          .Select(t => t.Tag.TagText)
                          .OrderBy(t => t)
                          .ToArray();

            return(result);
        }
        public async Task <UpdateCustomEntityDraftVersionCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateCustomEntityDraftVersionCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .CustomEntityVersions
                           .Include(v => v.CustomEntity)
                           .AsNoTracking()
                           .FilterActive()
                           .FilterByCustomEntityId(query.Id)
                           .Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft)
                           .SingleOrDefaultAsync();

            if (dbResult == null)
            {
                return(null);
            }
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext);

            var command = new UpdateCustomEntityDraftVersionCommand()
            {
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbResult.CustomEntityId,
                Title = dbResult.Title
            };

            var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(command.CustomEntityDefinitionCode);
            var definition      = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext);

            EntityNotFoundException.ThrowIfNull(definition, command.CustomEntityDefinitionCode);
            command.Model = (ICustomEntityDataModel)_dbUnstructuredDataSerializer.Deserialize(dbResult.SerializedData, definition.DataModelType);

            return(command);
        }
Ejemplo n.º 3
0
        public async Task <UpdatePageDirectoryCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdatePageDirectoryCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .PageDirectories
                           .AsNoTracking()
                           .Where(w => w.PageDirectoryId == query.Id && w.IsActive)
                           .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbResult, query.Id);

            if (!dbResult.ParentPageDirectoryId.HasValue)
            {
                throw new NotPermittedException("The root directory cannot be updated.");
            }

            var command = new UpdatePageDirectoryCommand()
            {
                Name                  = dbResult.Name,
                PageDirectoryId       = dbResult.PageDirectoryId,
                ParentPageDirectoryId = dbResult.ParentPageDirectoryId.Value,
                UrlPath               = dbResult.UrlPath
            };

            return(command);
        }
        public async Task <UpdatePageCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdatePageCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .Pages
                           .AsNoTracking()
                           .Include(p => p.PageTags)
                           .ThenInclude(t => t.Tag)
                           .FilterActive()
                           .FilterByPageId(query.Id)
                           .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbResult, query.Id);

            var command = new UpdatePageCommand()
            {
                PageId = dbResult.PageId,
                Tags   = dbResult
                         .PageTags
                         .Select(t => t.Tag.TagText)
                         .OrderBy(t => t)
                         .ToArray()
            };

            return(command);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes a command in a "Patch" style, allowing for a partial update of a resource. In
        /// order to support this method, there must be a query handler defined that implements
        /// IQueryHandler&lt;GetByIdQuery&lt;TCommand&gt;&gt; so the full command object can be fecthed
        /// prior to patching. Once patched and executed, a formatted IHttpActionResult is returned,
        /// handling any validation errors and permission errors.
        /// </summary>
        /// <typeparam name="TCommand">Type of the command to execute</typeparam>
        /// <param name="controller">The Controller instance using the helper</param>
        /// <param name="delta">The delta of the command to patch and execute</param>
        public async Task <IActionResult> RunCommandAsync <TCommand>(ControllerBase controller, int id, IDelta <TCommand> delta) where TCommand : class, ICommand
        {
            var query   = new GetUpdateCommandByIdQuery <TCommand>(id);
            var command = await _queryExecutor.ExecuteAsync(query);

            if (delta != null)
            {
                delta.Patch(command);
            }

            return(await RunCommandAsync(controller, command));
        }
        public async Task <IActionResult> Get(int pageVersionBlockId, PageVersionRegionBlocksActionDataType dataType = PageVersionRegionBlocksActionDataType.RenderDetails)
        {
            if (dataType == PageVersionRegionBlocksActionDataType.UpdateCommand)
            {
                var updateCommandQuery  = new GetUpdateCommandByIdQuery <UpdatePageVersionBlockCommand>(pageVersionBlockId);
                var updateCommandResult = await _queryExecutor.ExecuteAsync(updateCommandQuery);

                return(_apiResponseHelper.SimpleQueryResponse(this, updateCommandResult));
            }

            var query = new GetPageVersionBlockRenderDetailsByIdQuery()
            {
                PageVersionBlockId = pageVersionBlockId, PublishStatus = PublishStatusQuery.Latest
            };
            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
Ejemplo n.º 7
0
        public async Task <JsonResult> Get(int customEntityVersionPageBlockId, CustomEntityVersionPageBlocksActionDataType dataType = CustomEntityVersionPageBlocksActionDataType.RenderDetails)
        {
            if (dataType == CustomEntityVersionPageBlocksActionDataType.UpdateCommand)
            {
                var updateCommandQuery  = new GetUpdateCommandByIdQuery <UpdateCustomEntityVersionPageBlockCommand>(customEntityVersionPageBlockId);
                var updateCommandResult = await _queryExecutor.ExecuteAsync(updateCommandQuery);

                return(_apiResponseHelper.SimpleQueryResponse(updateCommandResult));
            }

            var query = new GetCustomEntityVersionPageBlockRenderDetailsByIdQuery()
            {
                CustomEntityVersionPageBlockId = customEntityVersionPageBlockId, PublishStatus = PublishStatusQuery.Latest
            };
            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(results));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PatchDraft(int pageId, [FromBody] IDelta <UpdatePageDraftVersionCommand> delta)
        {
            // Custom patching because we may need to create a draft version first
            var query   = new GetUpdateCommandByIdQuery <UpdatePageDraftVersionCommand>(pageId);
            var command = await _queryExecutor.ExecuteAsync(query);

            if (command == null)
            {
                var createDraftCommand = new AddPageDraftVersionCommand();
                createDraftCommand.PageId = pageId;
                await _commandExecutor.ExecuteAsync(createDraftCommand);

                command = await _queryExecutor.ExecuteAsync(query);
            }

            delta.Patch(command);

            return(await _apiResponseHelper.RunCommandAsync(this, command));
        }
        public async Task <UpdateRoleCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateRoleCommand> query, IExecutionContext executionContext)
        {
            var role = await _internalRoleRepository.GetByIdAsync(query.Id);

            var command = new UpdateRoleCommand()
            {
                RoleId = role.RoleId,
                Title  = role.Title
            };

            command.Permissions = role
                                  .Permissions
                                  .Select(p => new PermissionCommandData()
            {
                EntityDefinitionCode = p.GetUniqueCode(),
                PermissionCode       = p is IEntityPermission ? ((IEntityPermission)p).EntityDefinition.EntityDefinitionCode : null
            })
                                  .ToArray();

            return(command);
        }
Ejemplo n.º 10
0
        public async Task <UpdatePageVersionBlockCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdatePageVersionBlockCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .PageVersionBlocks
                           .AsNoTracking()
                           .Where(b => b.PageVersionBlockId == query.Id)
                           .Select(b => new
            {
                PageBlock         = b,
                BlockTypeFileName = b.PageBlockType.FileName
            })
                           .SingleOrDefaultAsync();

            if (dbResult == null)
            {
                return(null);
            }

            var result = Map(dbResult.PageBlock, dbResult.BlockTypeFileName);

            return(result);
        }
Ejemplo n.º 11
0
        public async Task <UpdateCurrentUserAccountCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateCurrentUserAccountCommand> query, IExecutionContext executionContext)
        {
            if (!executionContext.UserContext.UserId.HasValue)
            {
                return(null);
            }

            var user = await _dbContext
                       .Users
                       .AsNoTracking()
                       .FilterCanLogIn()
                       .FilterById(executionContext.UserContext.UserId.Value)
                       .Select(u => new UpdateCurrentUserAccountCommand()
            {
                Email     = u.Email,
                FirstName = u.FirstName,
                LastName  = u.LastName
            })
                       .SingleOrDefaultAsync();

            return(user);
        }
Ejemplo n.º 12
0
        public async Task <UpdatePageDraftVersionCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdatePageDraftVersionCommand> query, IExecutionContext executionContext)
        {
            var command = await _dbContext
                          .PageVersions
                          .AsNoTracking()
                          .FilterActive()
                          .FilterByPageId(query.Id)
                          .Where(p => p.WorkFlowStatusId == (int)WorkFlowStatus.Draft)
                          .Select(v => new UpdatePageDraftVersionCommand
            {
                MetaDescription      = v.MetaDescription,
                OpenGraphDescription = v.OpenGraphDescription,
                OpenGraphImageId     = v.OpenGraphImageId,
                OpenGraphTitle       = v.OpenGraphTitle,
                PageId        = v.PageId,
                ShowInSiteMap = !v.ExcludeFromSitemap,
                Title         = v.Title
            })
                          .SingleOrDefaultAsync();

            return(command);
        }
Ejemplo n.º 13
0
        public async Task <UpdateUserCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateUserCommand> query, IExecutionContext executionContext)
        {
            var dbUser = await _dbContext
                         .Users
                         .AsNoTracking()
                         .FilterCanLogIn()
                         .FilterById(query.Id)
                         .SingleOrDefaultAsync();

            if (dbUser == null)
            {
                return(null);
            }

            if (dbUser.UserAreaCode == CofoundryAdminUserArea.AreaCode)
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <CofoundryUserReadPermission>(query.Id, executionContext.UserContext);
            }
            else
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <NonCofoundryUserReadPermission>(query.Id, executionContext.UserContext);
            }

            var user = new UpdateUserCommand()
            {
                Email                 = dbUser.Email,
                FirstName             = dbUser.FirstName,
                IsEmailConfirmed      = dbUser.IsEmailConfirmed,
                LastName              = dbUser.LastName,
                RequirePasswordChange = dbUser.RequirePasswordChange,
                RoleId                = dbUser.RoleId,
                UserId                = dbUser.RoleId,
                Username              = dbUser.Username
            };

            return(user);
        }
Ejemplo n.º 14
0
        public async Task <UpdateCustomEntityVersionPageBlockCommand> ExecuteAsync(GetUpdateCommandByIdQuery <UpdateCustomEntityVersionPageBlockCommand> query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .CustomEntityVersionPageBlocks
                           .AsNoTracking()
                           .Where(b => b.CustomEntityVersionPageBlockId == query.Id)
                           .Select(b => new
            {
                PageBlock                  = b,
                PageBlockTypeFileName      = b.PageBlockType.FileName,
                CustomEntityDefinitionCode = b.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode
            })
                           .SingleOrDefaultAsync();

            if (dbResult == null)
            {
                return(null);
            }
            await _permissionValidationService.EnforceCustomEntityPermissionAsync <CustomEntityReadPermission>(dbResult.CustomEntityDefinitionCode);

            var result = Map(dbResult.PageBlock, dbResult.PageBlockTypeFileName);

            return(result);
        }
Ejemplo n.º 15
0
 public IEnumerable <IPermissionApplication> GetPermissions(GetUpdateCommandByIdQuery <UpdateDocumentAssetCommand> query)
 {
     yield return(new DocumentAssetReadPermission());
 }
Ejemplo n.º 16
0
 public IEnumerable <IPermissionApplication> GetPermissions(GetUpdateCommandByIdQuery <UpdatePageDirectoryCommand> command)
 {
     yield return(new PageDirectoryReadPermission());
 }
 public IEnumerable <IPermissionApplication> GetPermissions(GetUpdateCommandByIdQuery <UpdateRoleCommand> command)
 {
     yield return(new RoleReadPermission());
 }
 public IEnumerable <IPermissionApplication> GetPermissions(GetUpdateCommandByIdQuery <UpdateImageAssetCommand> query)
 {
     yield return(new ImageAssetUpdatePermission());
 }
Ejemplo n.º 19
0
 public IEnumerable <IPermissionApplication> GetPermissions(GetUpdateCommandByIdQuery <UpdatePageDraftVersionCommand> query)
 {
     yield return(new PageReadPermission());
 }