Exemplo n.º 1
0
        public void Delete(WorkflowComment request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityWorkflowComment.GetWorkflowComment(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No WorkflowComment could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

                    if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route.");
                    }

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.WORKFLOWCOMMENT);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Exemplo n.º 2
0
        private WorkflowComment GetWorkflowComment(WorkflowComment request)
        {
            var             id    = request?.Id;
            WorkflowComment ret   = null;
            var             query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetVisibleFields <WorkflowComment>(currentUser, "WorkflowComment", request.VisibleFields);

            DocEntityWorkflowComment entity = null;

            if (id.HasValue)
            {
                entity = DocEntityWorkflowComment.GetWorkflowComment(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No WorkflowComment found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
Exemplo n.º 3
0
        public WorkflowComment Post(WorkflowComment request)
        {
            if (request == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null.");
            }

            request.VisibleFields = request.VisibleFields ?? new List <string>();

            WorkflowComment ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "WorkflowComment"))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    ret = _AssignValues(request, DocConstantPermission.ADD, ssn);
                });
            }
            return(ret);
        }
Exemplo n.º 4
0
 /// <summary>
 /// SaveWorkflowComment
 /// </summary>
 /// <param name="workflowComment"></param>
 public void SaveWorkflowComment(WorkflowComment workflowComment)
 {
     workflowComment.CreatedById = UserContextDetails.UserId;
     workflowComment.CreatedOn   = DateTime.UtcNow;
     eCollabroDbContext.Repository <WorkflowComment>().Insert(workflowComment);
     eCollabroDbContext.Save();
 }
Exemplo n.º 5
0
        public async Task <ViewResultBase> Edit(NullableIdInput input)
        {
            var comment = new WorkflowComment();

            if (input != null)
            {
                if (!input.Id.IsNullOrEmptyGuid())
                {
                    comment = await _commentLogic.GetByIdAsync(input.Id);
                }
            }
            return(View(comment));
        }
Exemplo n.º 6
0
        public WorkflowComment Post(WorkflowCommentCopy request)
        {
            WorkflowComment ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityWorkflowComment.GetWorkflowComment(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pChildren = entity.Children.ToList();
                    var pParent   = entity.Parent;
                    var pText     = entity.Text;
                    var pUser     = entity.User;
                    var pWorkflow = entity.Workflow;
                    #region Custom Before copyWorkflowComment
                    #endregion Custom Before copyWorkflowComment
                    var copy = new DocEntityWorkflowComment(ssn)
                    {
                        Hash       = Guid.NewGuid()
                        , Parent   = pParent
                        , Text     = pText
                        , User     = pUser
                        , Workflow = pWorkflow
                    };
                    foreach (var item in pChildren)
                    {
                        entity.Children.Add(item);
                    }

                    #region Custom After copyWorkflowComment
                    #endregion Custom After copyWorkflowComment
                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
Exemplo n.º 7
0
        public WorkflowComment Patch(WorkflowComment request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the WorkflowComment to patch.");
            }

            request.VisibleFields = request.VisibleFields ?? new List <string>();

            WorkflowComment ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
Exemplo n.º 8
0
 public async Task <JsonResult> SaveComment(WorkflowComment comment)
 {
     comment.CreateUserId   = CurrentUser.UserId;
     comment.CreateUserName = CurrentUser.Name;
     return(Json(await _commentLogic.SaveComment(comment)));
 }
Exemplo n.º 9
0
 public WorkflowComment Put(WorkflowComment request)
 {
     return(Patch(request));
 }
Exemplo n.º 10
0
        private WorkflowComment _AssignValues(WorkflowComment request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "WorkflowComment"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.VisibleFields = request.VisibleFields ?? new List <string>();

            WorkflowComment ret = null;

            request = _InitAssignValues <WorkflowComment>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <WorkflowComment>(DocConstantModelName.WORKFLOWCOMMENT, nameof(WorkflowComment), request);

            //First, assign all the variables, do database lookups and conversions
            var pChildren = request.Children?.ToList();
            var pParent   = (request.Parent?.Id > 0) ? DocEntityWorkflowComment.GetWorkflowComment(request.Parent.Id) : null;
            var pText     = request.Text;
            var pUser     = (request.User?.Id > 0) ? DocEntityUser.GetUser(request.User.Id) : null;
            var pWorkflow = (request.Workflow?.Id > 0) ? DocEntityWorkflow.GetWorkflow(request.Workflow.Id) : null;

            DocEntityWorkflowComment entity = null;

            if (permission == DocConstantPermission.ADD)
            {
                var now = DateTime.UtcNow;
                entity = new DocEntityWorkflowComment(session)
                {
                    Created = now,
                    Updated = now
                };
            }
            else
            {
                entity = DocEntityWorkflowComment.GetWorkflowComment(request.Id);
                if (null == entity)
                {
                    throw new HttpError(HttpStatusCode.NotFound, $"No record");
                }
            }

            //Special case for Archived
            var pArchived = true == request.Archived;

            if (DocPermissionFactory.IsRequestedHasPermission <bool>(currentUser, request, pArchived, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Archived)))
            {
                if (DocPermissionFactory.IsRequested(request, pArchived, entity.Archived, nameof(request.Archived)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Archived)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Archived)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pArchived) && DocResources.Metadata.IsRequired(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Archived)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Archived)} requires a value.");
                }
                entity.Archived = pArchived;
                if (DocPermissionFactory.IsRequested <bool>(request, pArchived, nameof(request.Archived)) && !request.VisibleFields.Matches(nameof(request.Archived), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Archived));
                }
            }

            if (DocPermissionFactory.IsRequestedHasPermission <DocEntityWorkflowComment>(currentUser, request, pParent, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Parent)))
            {
                if (DocPermissionFactory.IsRequested(request, pParent, entity.Parent, nameof(request.Parent)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Parent)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Parent)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pParent) && DocResources.Metadata.IsRequired(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Parent)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Parent)} requires a value.");
                }
                entity.Parent = pParent;
                if (DocPermissionFactory.IsRequested <DocEntityWorkflowComment>(request, pParent, nameof(request.Parent)) && !request.VisibleFields.Matches(nameof(request.Parent), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Parent));
                }
            }
            if (DocPermissionFactory.IsRequestedHasPermission <string>(currentUser, request, pText, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Text)))
            {
                if (DocPermissionFactory.IsRequested(request, pText, entity.Text, nameof(request.Text)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Text)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Text)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pText) && DocResources.Metadata.IsRequired(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Text)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Text)} requires a value.");
                }
                entity.Text = pText;
                if (DocPermissionFactory.IsRequested <string>(request, pText, nameof(request.Text)) && !request.VisibleFields.Matches(nameof(request.Text), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Text));
                }
            }
            if (DocPermissionFactory.IsRequestedHasPermission <DocEntityUser>(currentUser, request, pUser, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.User)))
            {
                if (DocPermissionFactory.IsRequested(request, pUser, entity.User, nameof(request.User)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.User)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.User)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pUser) && DocResources.Metadata.IsRequired(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.User)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.User)} requires a value.");
                }
                entity.User = pUser;
                if (DocPermissionFactory.IsRequested <DocEntityUser>(request, pUser, nameof(request.User)) && !request.VisibleFields.Matches(nameof(request.User), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.User));
                }
            }
            if (DocPermissionFactory.IsRequestedHasPermission <DocEntityWorkflow>(currentUser, request, pWorkflow, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Workflow)))
            {
                if (DocPermissionFactory.IsRequested(request, pWorkflow, entity.Workflow, nameof(request.Workflow)))
                {
                    if (DocResources.Metadata.IsInsertOnly(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Workflow)) && DocConstantPermission.ADD != permission)
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, $"{nameof(request.Workflow)} cannot be modified once set.");
                    }
                }
                if (DocTools.IsNullOrEmpty(pWorkflow) && DocResources.Metadata.IsRequired(DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Workflow)))
                {
                    throw new HttpError(HttpStatusCode.BadRequest, $"{nameof(request.Workflow)} requires a value.");
                }
                entity.Workflow = pWorkflow;
                if (DocPermissionFactory.IsRequested <DocEntityWorkflow>(request, pWorkflow, nameof(request.Workflow)) && !request.VisibleFields.Matches(nameof(request.Workflow), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Workflow));
                }
            }

            if (request.Locked)
            {
                entity.Locked = request.Locked;
            }

            entity.SaveChanges(permission);

            if (DocPermissionFactory.IsRequestedHasPermission <List <Reference> >(currentUser, request, pChildren, permission, DocConstantModelName.WORKFLOWCOMMENT, nameof(request.Children)))
            {
                if (true == pChildren?.Any())
                {
                    var requestedChildren = pChildren.Select(p => p.Id).Distinct().ToList();
                    var existsChildren    = Execute.SelectAll <DocEntityWorkflowComment>().Where(e => e.Id.In(requestedChildren)).Select(e => e.Id).ToList();
                    if (existsChildren.Count != requestedChildren.Count)
                    {
                        var nonExists = requestedChildren.Where(id => existsChildren.All(eId => eId != id));
                        throw new HttpError(HttpStatusCode.NotFound, $"Cannot patch collection Children with objects that do not exist. No matching Children(s) could be found for Ids: {nonExists.ToDelimitedString()}.");
                    }
                    var toAdd = requestedChildren.Where(id => entity.Children.All(e => e.Id != id)).ToList();
                    toAdd?.ForEach(id =>
                    {
                        var target = DocEntityWorkflowComment.GetWorkflowComment(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD, targetEntity: target, targetName: nameof(WorkflowComment), columnName: nameof(request.Children)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to add {nameof(request.Children)} to {nameof(WorkflowComment)}");
                        }
                        entity.Children.Add(target);
                    });
                    var toRemove = entity.Children.Where(e => requestedChildren.All(id => e.Id != id)).Select(e => e.Id).ToList();
                    toRemove.ForEach(id =>
                    {
                        var target = DocEntityWorkflowComment.GetWorkflowComment(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.REMOVE, targetEntity: target, targetName: nameof(WorkflowComment), columnName: nameof(request.Children)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to remove {nameof(request.Children)} from {nameof(WorkflowComment)}");
                        }
                        entity.Children.Remove(target);
                    });
                }
                else
                {
                    var toRemove = entity.Children.Select(e => e.Id).ToList();
                    toRemove.ForEach(id =>
                    {
                        var target = DocEntityWorkflowComment.GetWorkflowComment(id);
                        if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.REMOVE, targetEntity: target, targetName: nameof(WorkflowComment), columnName: nameof(request.Children)))
                        {
                            throw new HttpError(HttpStatusCode.Forbidden, "You do not have permission to remove {nameof(request.Children)} from {nameof(WorkflowComment)}");
                        }
                        entity.Children.Remove(target);
                    });
                }
                if (DocPermissionFactory.IsRequested <List <Reference> >(request, pChildren, nameof(request.Children)) && !request.VisibleFields.Matches(nameof(request.Children), ignoreSpaces: true))
                {
                    request.VisibleFields.Add(nameof(request.Children));
                }
            }
            DocPermissionFactory.SetVisibleFields <WorkflowComment>(currentUser, nameof(WorkflowComment), request.VisibleFields);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.WORKFLOWCOMMENT);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.WORKFLOWCOMMENT, cacheExpires);

            return(ret);
        }
Exemplo n.º 11
0
 public object Get(WorkflowComment request) => GetEntityWithCache <WorkflowComment>(DocConstantModelName.WORKFLOWCOMMENT, request, GetWorkflowComment);