private void ProcessChildGroups(Group group, string webUrl, string accessToken)
        {
            // relink all child groups; if the root group is being deleted, set children parent ids to 0; if
            // a sub-group is deleted, set child parent ids to parent id of sub-group
            var childGroups      = _groupRepository.GetAll(webUrl, accessToken, "&$filter=(ParentId eq " + group.Id + ")");
            var childClauses     = _clauseRepository.GetAll(webUrl, accessToken, "&$filter=(GroupId eq " + group.Id + ")");
            var newChildParentId = group.ParentId > 0 ? group.ParentId : 0;

            foreach (var childGroup in childGroups)
            {
                var ownerId = childGroup.Owner.Id;
                childGroup.ParentId = newChildParentId;
                childGroup.ToClient = false;
                childGroup.OwnerId  = ownerId;
                _groupRepository.Update(webUrl, accessToken, childGroup);
            }

            foreach (var childClause in childClauses)
            {
                var ownerId = childClause.Owner.Id;
                childClause.GroupId  = newChildParentId;
                childClause.ToClient = false;
                childClause.OwnerId  = ownerId;
                _clauseRepository.Update(webUrl, accessToken, childClause);
            }
        }
コード例 #2
0
        public void Update_ShouldBeAbleToUpdateAllPropertiesExceptIdAndCreated()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            DateTime tomorrow = DateTime.Now;

            ListItem updateItem = new ListItem
            {
                Id          = 3,
                Title       = "Schedule Date Night",
                Description = "Pick a night to have date night",
                Importance  = "High",
                Type        = "Special",
                Created     = tomorrow,
                Updated     = tomorrow,
                Due         = DateTime.Now.AddDays(14),
            };

            repo.Update(updateItem);

            ListItem newlyUpdatedItem = repo.Get(updateItem.Id);

            Assert.Equal(updateItem.Title, newlyUpdatedItem.Title);
            Assert.Equal(updateItem.Description, newlyUpdatedItem.Description);
            Assert.Equal(updateItem.Importance, newlyUpdatedItem.Importance);
            Assert.Equal(updateItem.Type, newlyUpdatedItem.Type);
            Assert.NotEqual(updateItem.Created, newlyUpdatedItem.Created);
            Assert.Equal(updateItem.Updated.Date, newlyUpdatedItem.Updated.Date);
            Assert.Equal(updateItem.Due.Date, newlyUpdatedItem.Due.Date);
        }
        /// <summary>
        /// Updates the group.
        /// </summary>
        /// <param name="itemRequestModel">The item request model containing a valid group to update.</param>
        /// <param name="webUrl">The web URL.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="currentUserEmail"></param>
        /// <param name="isUserAdmin"></param>
        /// <returns></returns>
        public override Group Update(ItemRequestModel itemRequestModel, string webUrl, string accessToken,
                                     string currentUserEmail, bool isUserAdmin)
        {
            // User cannot edit a group they do not own
            if (!IsOwnerOrDesignee(itemRequestModel.Group, currentUserEmail) && !isUserAdmin)
            {
                throw new Exception("You do not have permission to edit this group.");
            }

            // User cannot add a group to a group they do not own
            //if(groupRequest.Parent != null && !IsOwnerOrDesignee(groupRequest.Parent))
            //    throw new Exception("You do not have permission to modify the selected group.");

            // User cannot edit a locked group
            if (itemRequestModel.Group.IsLocked && !isUserAdmin)
            {
                throw new Exception("You cannot modify a locked group.");
            }

            try
            {
                _groupRepository.Update(webUrl, accessToken, itemRequestModel.Group);
                // need to explicitly retrieve the new group in order to get its full set of properties
                var retrievedUpdatedGroup = _groupRepository.Get(webUrl, itemRequestModel.Group.Id, accessToken,
                                                                 SpApiConstants.Lists.GROUP_EXPAND);
                return
                    (BuildGroups(new List <Group> {
                    retrievedUpdatedGroup
                }, webUrl, accessToken, currentUserEmail,
                                 isUserAdmin).First());
            }
            catch (Exception)
            {
                throw new Exception("Failed to update group");
            }
        }
コード例 #4
0
        /// <summary>
        /// Updates the clause.
        /// </summary>
        public override Clause Update(ItemRequestModel itemRequestModel, string webUrl, string accessToken,
                                      string currentUserEmail, bool isUserAdmin)
        {
            // User cannot edit a clause they do not own
            if (!IsOwnerOrDesignee(itemRequestModel.Clause, currentUserEmail) && !isUserAdmin)
            {
                throw new Exception("You do not have permission to edit this clause.");
            }

            // User cannot add a clause to a group they do not own
            //if(clauseRequest.Group != null && !IsOwnerOrDesignee(clauseRequest.Group))
            //    throw new Exception("You do not have permission to modify the selected group.");

            // User cannot edit a locked clause unless they are admin
            if (itemRequestModel.Clause.IsLocked && !isUserAdmin)
            {
                throw new Exception("You cannot modify a locked clause.");
            }

            try
            {
                var preparedClause = PrepareClause(itemRequestModel, webUrl, accessToken);

                _clauseRepository.Update(webUrl, accessToken, preparedClause);

                // need to explicitly retrieve the new clause in order to get its full set of properties
                var updatedClause = _clauseRepository.Get(webUrl, itemRequestModel.Clause.Id, accessToken,
                                                          SpApiConstants.Lists.CLAUSE_EXPAND);

                // now that the clause has been created, create any new external links; there is a dependency
                // on the clause id (which is not set before the clause is created)
                ProcessExternalLinks(updatedClause, itemRequestModel.ExternalLinks, webUrl, accessToken);

                return
                    (BuildClauses(new List <Clause> {
                    updatedClause
                }, webUrl, accessToken, currentUserEmail, isUserAdmin)
                     .First());
            }
            catch (Exception)
            {
                throw new Exception("Failed to update clause");
            }
        }
        public virtual string Put(string webUrl, [FromBody] T item, string userEmail, bool isLocked = false,
                                  string accessToken = "")
        {
            accessToken = GetAccessToken(accessToken);
            var currentUserEmail = GetCurrentUserEmail();
            var isAdmin          = IsUserAdmin();

            if (currentUserEmail != userEmail)
            {
                throw new Exception("You do not have permission to update this item.");
            }

            if (!isAdmin && isLocked)
            {
                throw new Exception("You cannot update a locked item.");
            }

            item.ToClient = false;
            return(Repository.Update(webUrl, accessToken, item));
        }
コード例 #6
0
        public void Update_ShouldReturnAnEntityQueryableOfListItems()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();


            DateTime tomorrow = DateTime.Now;

            ListItem updateItem = new ListItem
            {
                Id          = 3,
                Title       = "Schedule Date Night",
                Description = "Pick a night to have date night",
                Importance  = "High",
                Type        = "Special",
                Created     = tomorrow,
                Updated     = tomorrow,
                Due         = DateTime.Now.AddDays(14),
            };

            var actual   = repo.Update(updateItem);
            var expected = typeof(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable <ListItem>);

            Assert.IsType(expected, actual);
        }