public async Task DeleteAsync(Guid termsOfServiceId)
        {
            var termsOfService = await termsOfServiceRepository.GetByIdAsync(termsOfServiceId, includeRelations : true, includeFileContents : false);

            if (termsOfService == null)
            {
                throw new ItemNotFoundException($"Terms of Service entry with GUID '{termsOfServiceId}' not found.");
            }

            if (termsOfService.TermsOfServiceAcceptances.Count > 0)
            {
                throw new ItemNotProcessableException("This terms of service agreement has already been agreed to by at least one user. It cannot be deleted.");
            }

            await termsOfServiceRepository.DeleteAsync(termsOfService);
        }
Ejemplo n.º 2
0
        private async Task ValidateTermsOfServiceEntry(Guid?termsOfServiceId)
        {
            if (termsOfServiceId == null)
            {
                return;
            }

            TermsOfServiceModel existingTermsOfService = await termsOfServiceRepository.GetByIdAsync((Guid)termsOfServiceId, includeRelations : false, includeFileContents : false);

            if (existingTermsOfService == null)
            {
                throw new ItemNotFoundException($"TermsOfService entry with Id '{termsOfServiceId} not found.");
            }
        }
        public async Task Index_ExecutedWithOutstandingAgreements_ViewResultReturned()
        {
            //Arrange
            var id = Guid.NewGuid().ToString();

            using var termsOfServiceController = new TermsOfServiceController(fakeUserManager, termsOfServiceRepository, mockConfiguration, mockIdentityServerInteractionService,
                                                                              mockEventService, mockClientStore, fakeSignInManager)
                  {
                      ControllerContext = new ControllerContext()
                      {
                          HttpContext = new DefaultHttpContext()
                          {
                              User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                        {
                            new Claim(ClaimTypes.Name, "example name"),
                            new Claim(ClaimTypes.NameIdentifier, id),
                            new Claim("sub", id),
                            new Claim("custom-claim", "example claim value"),
                        }, "mock")),
                          }
                      }
                  };

            fakeUserManager.SetUserModel(userModel);
            termsOfServiceRepository.GetAllOutstandingAgreementsByUserAsync(Arg.Any <Guid>())
            .Returns(new List <Guid>()
            {
                Guid.NewGuid(),
                Guid.NewGuid()
            });

            termsOfServiceRepository.GetByIdAsync(Arg.Any <Guid>(), Arg.Any <bool>(), Arg.Any <bool>()).Returns(termsOfServiceModel);

            // Act
            var actionResult = await termsOfServiceController.Index(RETURN_URL, 0);

            // Assert
            var viewResult = actionResult as ViewResult;

            Assert.NotNull(viewResult);

            var model = viewResult.Model as TermsOfServiceViewModel;

            Assert.True(model.AgreementName == termsOfServiceModel.AgreementName, $"Model field AgreementName '{model.AgreementName}' should be '{termsOfServiceModel.AgreementName}'.");
            Assert.True(model.AgreementCount == 2, $"Model field AgreementCount '{model.AgreementCount}' should be '2'.");
        }
Ejemplo n.º 4
0
        /************************************************/
        /* helper APIs for the TermsOfServiceController */
        /************************************************/
        private async Task <TermsOfServiceViewModel> BuildTermsOfServiceViewModel(string returnUrl, List <Guid> outstandingTerms, int initialAgreementCount)
        {
            var termsOfService = await termsOfServiceRepository.GetByIdAsync(outstandingTerms[0], includeRelations : false, includeFileContents : true);

            if (termsOfService == null)
            {
                throw new ItemNotFoundException($"Terms of service entry '{outstandingTerms[0]}' not found.");
            }

            return(new TermsOfServiceViewModel()
            {
                AgreementCount = outstandingTerms.Count,
                AgreementName = termsOfService.AgreementName,
                TermsOfServiceId = termsOfService.Id,
                CssContents = LocalizeStyleSheetItems(termsOfService.CssContents),
                HtmlContents = termsOfService.HtmlContents,
                ReturnUrl = returnUrl,
                InitialAgreementCount = (initialAgreementCount > 0 ? initialAgreementCount : outstandingTerms.Count)
            });
        }