Beispiel #1
0
        public void TestUpdateAssignments()
        {
            //This exists mostly for code coverage as well
            var assignmentUpdate = new AssignmentUpdate();

            assignmentUpdate.SetDefaults();
            Assert.NotNull(assignmentUpdate.ToJson());
            Assert.NotNull(assignmentUpdate.ToString());
        }
Beispiel #2
0
        public ActionResult SetArticleAssignment(AssignmentUpdate model)
        {
            var     id     = model.EntityId;
            Article curArt = dbContext.Article.FirstOrDefault(a => a.Id == id);

            if (curArt == null)
            {
                return(BadRequest("The requested article does not exist in the data base"));
            }

            var curUser   = GetUserInfo();
            var curUserId = curUser.id;

            const String eventName = "AssignedTo";

            if (model.ShouldAssign)
            {
                curArt.AssignedToId = curUserId;
                curArt.Status       = ArticleStatus.ON_REVIEW;

                var history = AddHistory(id, curUserId, eventName, curUser.name, null);
                AddNotification($"{curUser.name} has signed up for reviewing an article '{curArt.Name}'",
                                history, true, curArt.AuthorId);
            }
            else
            {
                curArt.Status = ArticleStatus.CREATED;

                foreach (var am in curArt.Amendments
                         .Where(a => a.AuthorId == curArt.AssignedToId && !a.Resolved).ToArray())
                {
                    curArt.Amendments.Remove(am);
                }

                var history = AddHistory(id, curUserId, eventName, null,
                                         curArt.AssignedTo.Login);
                AddNotification($"{curUser.name} has backed out of reviewing an article '{curArt.Name}'",
                                history, true, curArt.AuthorId);

                curArt.AssignedToId = null;
            }

            dbContext.SaveChanges();

            return(Ok());
        }
Beispiel #3
0
        public async Task TestUpdatedQueryAssignments()
        {
            var assignment   = CreateSimpleAssignmentNew();
            var assignmentId = await AssignmentUtils.CreateAssignment(assignment);

            var assignmentUpdate = new AssignmentUpdate()
            {
                Name                = new Guid().ToString()
                , AssignedTo        = TestUserId
                , CompletedAt       = null
                , CompletedBy       = ""
                , CompletionDetails = ""
                , ConfirmCaptures   = false
                , Description       = ""
                , Fade              = new Fade()
                , IntegrationId     = SkyManager.IntegrationId
                , IsComplete        = false
                , RootSequence      = AssignmentUtils.ROOT_SEQUENCE_ID
                , WorkflowId        = ""
            };

            var assignmentUpdateRequest = new UpdateAssignmentRequest(assignmentUpdate, assignmentId);
            await SkyManager.ApiClient.ExecuteRequestAsync(assignmentUpdateRequest);

            var getAssignmentsRequest = new GetAssignmentsRequest();

            getAssignmentsRequest.AddAllRealmQuery(true);
            getAssignmentsRequest.AddUpdatedByQuery(SkyManager.IntegrationId); //As noted above, this assignment will have been updated by the integration id
            var getAssignmentsResponse = await SkyManager.ApiClient.ExecuteRequestAsync(getAssignmentsRequest);

            var queriedAssignments = getAssignmentsResponse.Content;

            //There should exist at least one assignment in the realm, as we just made one
            Assert.InRange(queriedAssignments.Count, 1, Int16.MaxValue);
            await AssignmentUtils.DeleteAssignment(assignmentId);
        }
        public ActionResult SetComplaintAssignment(AssignmentUpdate model)
        {
            var id     = model.EntityId;
            var entity = dbContext.UserComplaint.FirstOrDefault(a => a.Id == id);

            if (entity == null)
            {
                return(BadRequest("The requested complaint does not exist in the data base"));
            }

            var curUser   = GetUserInfo();
            var curUserId = curUser.id;

            const String eventName = "Complaint.AssignedTo";
            var          now       = DateTime.Now;

            ArticleHistory history;
            List <Int32>   recipients = new List <Int32>();

            String notificationStr = "A complaint about ";

            var art = entity.Article;

            if (entity.UserCommentId.HasValue)
            {
                notificationStr += $"a comment #{entity.UserCommentId.Value.ToString()} for ";
            }

            notificationStr += $"an article '{art.Name}' ";

            if (model.ShouldAssign)
            {
                entity.AssignedToId = curUserId;
                history             = AddHistory(entity.ArticleId, curUserId, eventName, curUser.name, null,
                                                 now, entity.Id);
                notificationStr += $"has been assigned to {curUser.name}";
            }
            else
            {
                history = AddHistory(entity.ArticleId, curUserId, eventName, null, entity.AssignedTo.Login,
                                     now, entity.Id);
                entity.AssignedToId = null;
                notificationStr    += $"has been removed from the {curUser.name}'s assignments";
            }

            recipients.Add(entity.AuthorId);

            if (entity.UserCommentId.HasValue)
            {
                Int32 cmntAuthorId = entity.UserComment.AuthorId;
                recipients.Add(cmntAuthorId);

                Int32 artAuthorId = art.AuthorId;
                if (entity.AuthorId != artAuthorId && cmntAuthorId != artAuthorId)
                {
                    recipients.Add(artAuthorId);
                }
            }
            else
            {
                recipients.Add(entity.Article.AuthorId);
            }

            AddNotification(notificationStr, history, true, recipients.ToArray());
            dbContext.SaveChanges();

            return(Ok());
        }