Ejemplo n.º 1
0
        public void User_Can_Not_Update_Wall()
        {
            // Arrange
            var moderators = new List <WallModerator> {
                new WallModerator {
                    Id = 1, UserId = "user1"
                }
            };
            var walls = new List <Wall>
            {
                new Wall {
                    Id = 1, OrganizationId = 2, Type = WallType.UserCreated, Name = "testname", Description = "testdesc", Logo = "testlogo", Moderators = moderators
                }
            };

            var updateWallDto = new UpdateWallDto
            {
                Description    = "desc",
                Logo           = "logo",
                Name           = "name",
                Id             = 1,
                UserId         = "user",
                OrganizationId = 2
            };

            var isWallAdministrator = false;

            _permissionService.UserHasPermission(updateWallDto, AdministrationPermissions.Wall).Returns(isWallAdministrator);
            _wallsDbSet.SetDbSetData(walls.AsQueryable());

            // Act
            // Assert
            Assert.Throws <UnauthorizedException>(() => _wallService.UpdateWall(updateWallDto));
        }
Ejemplo n.º 2
0
        public async Task UpdateWallAsync(UpdateWallDto updateWallDto)
        {
            var wall = await _wallsDbSet
                       .Include(w => w.Moderators)
                       .Include(w => w.Members)
                       .FirstOrDefaultAsync(w =>
                                            w.Id == updateWallDto.Id &&
                                            w.OrganizationId == updateWallDto.OrganizationId);

            if (wall == null)
            {
                throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Wall not found");
            }

            var isWallAdmin = await _permissionService.UserHasPermissionAsync(updateWallDto, AdministrationPermissions.Wall);

            var isModerator = wall.Moderators.Any(m => m.UserId == updateWallDto.UserId);

            if (!isWallAdmin && !isModerator)
            {
                throw new UnauthorizedException();
            }

            IEnumerable <string>        newMembersIds     = new List <string>();
            IEnumerable <string>        newModeratorsIds  = new List <string>();
            ICollection <WallModerator> removedModerators = new List <WallModerator>();

            if (updateWallDto.ModeratorsIds != null)
            {
                newMembersIds     = updateWallDto.ModeratorsIds.Where(x => !wall.Members.Select(m => m.UserId).Contains(x));
                newModeratorsIds  = updateWallDto.ModeratorsIds.Where(x => !wall.Moderators.Select(m => m.UserId).Contains(x));
                removedModerators = wall.Moderators.Where(x => !updateWallDto.ModeratorsIds.Contains(x.UserId)).ToList();
            }

            wall.Description = updateWallDto.Description;
            wall.Logo        = updateWallDto.Logo;
            wall.Name        = updateWallDto.Name;

            foreach (var newMemberId in newMembersIds)
            {
                wall.Members.Add(new WallMember {
                    UserId = newMemberId
                });
            }

            foreach (var newModeratorId in newModeratorsIds)
            {
                wall.Moderators.Add(new WallModerator {
                    UserId = newModeratorId
                });
            }

            foreach (var removedModerator in removedModerators)
            {
                _moderatorsDbSet.Remove(removedModerator);
                wall.Moderators.Remove(removedModerator);
            }

            await _uow.SaveChangesAsync(updateWallDto.UserId);
        }
Ejemplo n.º 3
0
        private void UpdateWall(EditProjectDto dto, int wallId)
        {
            var updateWallDto = new UpdateWallDto
            {
                Id             = wallId,
                Description    = dto.Description,
                Logo           = dto.Logo,
                Name           = dto.Title,
                OrganizationId = dto.OrganizationId,
                UserId         = dto.UserId
            };

            _wallService.UpdateWall(updateWallDto);
        }
Ejemplo n.º 4
0
        private async Task UpdateWallAsync(EditProjectDto dto, int wallId)
        {
            var updateWallDto = new UpdateWallDto
            {
                Id             = wallId,
                Description    = dto.Description,
                Logo           = dto.Logo,
                Name           = dto.Title,
                OrganizationId = dto.OrganizationId,
                UserId         = dto.UserId
            };

            await _wallService.UpdateWallAsync(updateWallDto);
        }
Ejemplo n.º 5
0
        public void Moderator_Can_Update_Wall()
        {
            // Arrange
            var moderators = new List <WallModerator> {
                new WallModerator {
                    Id = 1, UserId = "user"
                }
            };
            var members = new List <WallMember> {
                new WallMember {
                    Id = 1, UserId = "user1"
                }
            };
            var walls = new List <Wall>
            {
                new Wall {
                    Id = 1, OrganizationId = 2, Type = WallType.UserCreated, Name = "testname", Description = "testdesc", Logo = "testlogo", Moderators = moderators, Members = members
                }
            };

            var updateWallDto = new UpdateWallDto
            {
                Description    = "desc",
                Logo           = "logo",
                Name           = "name",
                Id             = 1,
                UserId         = "user",
                OrganizationId = 2,
                ModeratorsIds  = new[] { "1" }
            };

            var isWallAdministrator = false;

            _permissionService.UserHasPermission(updateWallDto, AdministrationPermissions.Wall).Returns(isWallAdministrator);
            _wallsDbSet.SetDbSetData(walls.AsQueryable());

            // Act
            _wallService.UpdateWall(updateWallDto);

            // Assert
            var result = _wallsDbSet.First();

            Assert.AreEqual(updateWallDto.Name, result.Name);
            Assert.AreEqual(updateWallDto.Logo, result.Logo);
            Assert.AreEqual(updateWallDto.Description, result.Description);
            Assert.AreEqual(updateWallDto.Id, result.Id);
        }
Ejemplo n.º 6
0
        private async Task UpdateWallAsync(Event currentEvent, EditEventDto updatedEvent)
        {
            var updateWallDto = new UpdateWallDto
            {
                Id             = currentEvent.WallId,
                Description    = updatedEvent.Description,
                Logo           = updatedEvent.ImageName,
                Name           = updatedEvent.Name,
                OrganizationId = updatedEvent.OrganizationId,
                UserId         = updatedEvent.UserId
            };

            await _wallService.UpdateWallAsync(updateWallDto);

            var responsibleUserChanged     = currentEvent.ResponsibleUserId != updatedEvent.ResponsibleUserId;
            var currentHostIsParticipating = currentEvent.EventParticipants.Any(x => x.ApplicationUserId == currentEvent.ResponsibleUserId);
            var newHostIsParticipating     = currentEvent.EventParticipants.Any(p => p.ApplicationUserId == updatedEvent.ResponsibleUserId);

            if (!responsibleUserChanged)
            {
                return;
            }

            await _wallService.RemoveModeratorAsync(currentEvent.WallId, currentEvent.ResponsibleUserId, updatedEvent);

            await _wallService.AddModeratorAsync(currentEvent.WallId, updatedEvent.ResponsibleUserId, updatedEvent);

            if (!newHostIsParticipating)
            {
                await _wallService.JoinOrLeaveWallAsync(currentEvent.WallId, updatedEvent.ResponsibleUserId, updatedEvent.ResponsibleUserId, updatedEvent.OrganizationId, true);
            }

            if (!currentHostIsParticipating)
            {
                await _wallService.JoinOrLeaveWallAsync(currentEvent.WallId, currentEvent.ResponsibleUserId, currentEvent.ResponsibleUserId, updatedEvent.OrganizationId, true);
            }
        }
Ejemplo n.º 7
0
        public void Throw_If_Wall_Does_Not_Exist_During_Update()
        {
            // Arrange
            var moderators = new List <WallModerator> {
                new WallModerator {
                    Id = 1, UserId = "user1"
                }
            };
            var walls = new List <Wall>
            {
                new Wall {
                    Id = 2, OrganizationId = 2, Type = WallType.UserCreated, Name = "testname", Description = "testdesc", Logo = "testlogo", Moderators = moderators
                }
            };

            var updateWallDto = new UpdateWallDto
            {
                Description    = "desc",
                Logo           = "logo",
                Name           = "name",
                Id             = 1,
                UserId         = "user",
                OrganizationId = 2
            };

            var isWallAdministrator = false;

            _permissionService.UserHasPermission(updateWallDto, AdministrationPermissions.Wall).Returns(isWallAdministrator);
            _wallsDbSet.SetDbSetData(walls.AsQueryable());

            // Act
            // Assert
            var ex = Assert.Throws <ValidationException>(() => _wallService.UpdateWall(updateWallDto));

            Assert.AreEqual(ErrorCodes.ContentDoesNotExist, ex.ErrorCode);
        }