public async Task <CommandResult> Handle(ReplyCommentCommand request, CancellationToken cancellationToken) { Post post = await _postRepository.GetByIdAsync(request.PostId); ProfileAccessResult accessResult = await _profileDomainService.CanAccessProfileData(_currentProfileId, post.ProfileId); if (accessResult != ProfileAccessResult.CanAccess) { return(FailureDueToPostNotFound()); } Comment comment = await _commentRepository.GetByIdAsync(request.CommentId); if (comment == null) { return(FailureDueToCommentNotFound()); } comment.Reply( _currentProfileId, request.Body ); await _commentRepository.UpdateAsync(comment); return(await CommitAndPublishDefaultAsync()); }
public async Task ProfileNotFriendsShouldBeNotAllowedToAccess() { Profile profile = GetNewProfile(Guid.NewGuid()); Profile profileTwo = GetNewProfile(Guid.NewGuid()); ProfileDomainService profileDomainService = new ProfileDomainService(GetSimpleProfileRepository(profile, profileTwo)); ProfileAccessResult accessResult = await profileDomainService.CanAccessProfileData(profile.Id, profileTwo.Id); Assert.AreEqual(ProfileAccessResult.Forbidden, accessResult); }
private async Task <bool> CanModifyPost(Post post) { if (post == null) { return(false); } ProfileAccessResult accessResult = await _profileDomainService.CanAccessProfileData(_currentProfileId, post.ProfileId); return(accessResult == ProfileAccessResult.CanAccess); }
public async Task ShouldNotFindProfileInRepository() { Mock <IProfileRepository> mock = new Mock <IProfileRepository>(); mock.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync(() => null); ProfileDomainService profileDomainService = new ProfileDomainService(mock.Object); ProfileAccessResult accessResult = await profileDomainService.CanAccessProfileData(Guid.NewGuid(), Guid.NewGuid()); Assert.AreEqual(ProfileAccessResult.NotFound, accessResult); }
public async Task<IActionResult> GetAllByProfileIdAsync(Guid profileId, string nameFilter = null, int pageNumber = 1, int pageSize = 20) { ProfileAccessResult canAccessDiets = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId); if (canAccessDiets == ProfileAccessResult.CanAccess) { IEnumerable<DietListReadModel> diets = await _readModelRepository.GetDietListAsync(profileId, nameFilter, pageNumber, pageSize); return CreateResponse(diets); } else if (canAccessDiets == ProfileAccessResult.Forbidden) return Forbid(); return NotFound(); }
public async Task ProfileOwnerShouldBeAllowedToAccessData() { Mock <IProfileRepository> mock = new Mock <IProfileRepository>(); Profile profile = GetNewProfile(); mock.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())) .ReturnsAsync(profile); ProfileDomainService profileDomainService = new ProfileDomainService(mock.Object); ProfileAccessResult accessResult = await profileDomainService.CanAccessProfileData(profile.Id, profile.Id); Assert.AreEqual(ProfileAccessResult.CanAccess, accessResult); }
public async Task<IActionResult> GetDietSummaryAsync(Guid id) { DietSummaryReadModel diet = await _readModelRepository.GetDietSummaryAsync(id); if (diet != null) { ProfileAccessResult canAccessDiet = await _profileDomainService.CanAccessProfileData(_currentProfileId, diet.ProfileId); if (canAccessDiet == ProfileAccessResult.CanAccess) return CreateResponse(diet); if (canAccessDiet == ProfileAccessResult.Forbidden) return Forbid(); } return NotFound(); }
public async Task ProfileFriendsShouldBeAllowedToAccess() { Profile profile = GetNewProfile(Guid.NewGuid()); Profile profileTwo = GetNewProfile(Guid.NewGuid()); profileTwo.ChangeSettings(new ProfileSettings(PrivacyType.Protected)); profile.AddFriend(profileTwo); profileTwo.AddFriend(profile); ProfileDomainService profileDomainService = new ProfileDomainService(GetSimpleProfileRepository(profile, profileTwo)); ProfileAccessResult accessResult = await profileDomainService.CanAccessProfileData(profile.Id, profileTwo.Id); Assert.AreEqual(ProfileAccessResult.CanAccess, accessResult); }
public async Task <IActionResult> GetProfileFriendsAsync(Guid profileId, string nameFilter = null) { ProfileAccessResult canAccessGoals = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId); if (canAccessGoals == ProfileAccessResult.CanAccess) { IEnumerable <ProfileFriendReadModel> friends = await _readModelRepository.GetProfileFriendsAsync(profileId, nameFilter); return(CreateResponse(friends)); } else if (canAccessGoals == ProfileAccessResult.Forbidden) { return(Forbid()); } return(NotFound()); }
public async Task <IActionResult> GetAllByProfileIdAsync(Guid profileId, string titleFilter = null, int pageNumber = 1, int pageSize = 20) { ProfileAccessResult canAccessMeasures = await _profileDomainService.CanAccessProfileData(_currentProfileId, profileId); if (canAccessMeasures == ProfileAccessResult.CanAccess) { IEnumerable <MeasureListReadModel> measures = await _measureReadModelRepository.GetMeasureListAsync(profileId, titleFilter, pageNumber, pageSize); return(CreateResponse(measures)); } else if (canAccessMeasures == ProfileAccessResult.Forbidden) { return(Forbid()); } return(NotFound()); }
public async Task <IActionResult> GetMealSummaryAsync(Guid id) { MealSummaryReadModel meal = await _readModelRepository.GetMealSummaryAsync(id); if (meal != null) { ProfileAccessResult canAccessMeal = await _profileDomainService.CanAccessProfileData(_currentProfileId, meal.ProfileId); if (canAccessMeal == ProfileAccessResult.CanAccess) { return(CreateResponse(meal)); } if (canAccessMeal == ProfileAccessResult.Forbidden) { return(Forbid()); } } return(NotFound()); }
public async Task <IActionResult> GetByIdAsync(Guid id) { PostSummaryReadModel post = await _postReadModelRepository.GetPostSummaryAsync(id); if (post != null) { ProfileAccessResult canAccessPost = await _profileDomainService.CanAccessProfileData(_currentProfileId, post.ProfileId); if (canAccessPost == ProfileAccessResult.CanAccess) { return(CreateResponse(post)); } if (canAccessPost == ProfileAccessResult.Forbidden) { return(Forbid()); } } return(NotFound()); }