public static void Throw404IfFeatureDisabled(FeatureFlag featureFlag) { if (!FeatureFlagHelper.IsFeatureEnabled(featureFlag)) { throw new PageNotFoundException(); } }
private static void DecideRegistrationMethod(UserOrganisation userOrganisation) { if (userOrganisation.Organisation.Status == OrganisationStatuses.Pending) { // Organisations will have the "Pending" status if they have been added via manual data entry (and thus should be manually reviewed) // (Organisations will be "Active" if they already exist in our database, or if they are imported from CoHo) userOrganisation.Method = RegistrationMethods.Manual; } else if (userOrganisation.Organisation.SectorType == SectorTypes.Public) { userOrganisation.Method = RegistrationMethods.Manual; } else if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.PrivateManualRegistration)) { userOrganisation.Method = RegistrationMethods.Manual; } else if (userOrganisation.Organisation.GetLatestAddress()?.IsUkAddress != true) { userOrganisation.Method = RegistrationMethods.Manual; } else { userOrganisation.Method = RegistrationMethods.PinInPost; } }
public IActionResult ManageOrganisationGet(string encryptedOrganisationId) { // Check for feature flag and redirect if not enabled if (!FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney)) { return(RedirectToAction("ManageOrganisationGet", "ManageOrganisations", new { encryptedOrganisationId = encryptedOrganisationId })); } long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); User user = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(user); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); var organisation = dataRepository.Get <Organisation>(organisationId); if (OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(organisation)) { return(RedirectToAction("DeclareScope", "Organisation", new { id = encryptedOrganisationId })); } // build the view model List <int> yearsWithDraftReturns = dataRepository.GetAll <DraftReturn>() .Where(d => d.OrganisationId == organisationId) .Select(d => d.SnapshotYear) .ToList(); var viewModel = new ManageOrganisationViewModel(organisation, user, yearsWithDraftReturns); return(View("ManageOrganisation", viewModel)); }
public IActionResult ManageOrganisationsGet() { // Check for feature flag and redirect if not enabled if (!FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney)) { return(RedirectToAction("ManageOrganisationsGet", "ManageOrganisations")); } if (User.IsInRole(LoginRoles.GpgAdmin)) { return(RedirectToAction("AdminHomePage", "AdminHomepage")); } User user = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(user); ControllerHelper.RedirectIfUserNeedsToReadPrivacyPolicy(User, user, Url); var viewModel = new ManageOrganisationsViewModel { UserOrganisations = user.UserOrganisations.OrderBy(uo => uo.Organisation.OrganisationName) }; return(View("ManageOrganisations", viewModel)); }
public IActionResult Step6Task1() { if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.ReportingStepByStep)) { return(View("../ReportingStepByStep/Step6Task1")); } else { return(new HttpNotFoundResult()); } }
public IActionResult Index() { //Clear the default back url of the employer hub pages EmployerBackUrl = null; ReportBackUrl = null; if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.ReportingStepByStep)) { return(View("Launchpad/PrototypeIndex")); } else { return(View("Launchpad/Index")); } }
public UserOrganisation CreateRegistration(Organisation organisation, User user, IUrlHelper urlHelper) { var userOrganisation = new UserOrganisation { User = user, Organisation = organisation, // The address isn't important for registering organisation that are already in our database, or are from Companies House // But, for manual registrations, we use this to validate the address and mark the address as Active once it is approved Address = organisation.GetLatestAddress() }; DecideRegistrationMethod(userOrganisation); if (userOrganisation.Method == RegistrationMethods.PinInPost) { bool pitpSuccess = pinInThePostService.GenerateAndSendPinInThePostAndUpdateUserOrganisationWithLetterId(userOrganisation, urlHelper); if (!pitpSuccess) { // Sending a Pin In The Post failed // Switch to Manual registration userOrganisation.Method = RegistrationMethods.Manual; } } // Note: this is an IF, not an ELSE-IF, because we might change registration methods if PITP fails if (userOrganisation.Method == RegistrationMethods.Manual) { if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.SendRegistrationReviewEmails)) { SendReviewRegistrationEmailToGeo(userOrganisation, urlHelper); } } dataRepository.Insert(userOrganisation); dataRepository.SaveChanges(); return(userOrganisation); }
public IActionResult ManageOrganisations() { // Check for feature flag and redirect if not enabled if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney)) { return(RedirectToAction("ManageOrganisationsGet", "ManageOrganisations")); } //Clear all the stashes this.ClearAllStashes(); //Reset the current reporting organisation ReportingOrganisation = null; //Ensure user has completed the registration process IActionResult checkResult = CheckUserRegisteredOk(out User currentUser); if (checkResult != null && IsImpersonatingUser == false) { return(checkResult); } // check if the user has accepted the privacy statement (unless admin or impersonating) if (!IsImpersonatingUser && !base.CurrentUser.IsAdministrator()) { DateTime?hasReadPrivacy = currentUser.AcceptedPrivacyStatement; if (hasReadPrivacy == null || hasReadPrivacy.Value < Global.PrivacyChangedDate) { return(RedirectToAction(nameof(PrivacyPolicyController.PrivacyPolicyGet), "PrivacyPolicy")); } } //create the new view model IOrderedEnumerable <UserOrganisation> model = currentUser.UserOrganisations.OrderBy(uo => uo.Organisation.OrganisationName); return(View("ManageOrganisations", model)); }
public async Task <IActionResult> Step1Task2([FromQuery] SearchResultsQuery searchQuery, string orderBy = "relevance") { if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.ReportingStepByStep)) { //When never searched in this session if (string.IsNullOrWhiteSpace(SearchViewService.LastSearchParameters)) { //If no compare employers in session then load employers from the cookie if (CompareViewService.BasketItemCount == 0) { CompareViewService.LoadComparedEmployersFromCookie(); } } // ensure parameters are valid if (!searchQuery.TryValidateSearchParams(out HttpStatusViewResult result)) { return(result); } // generate result view model var searchParams = SearchResultsQueryToEmployerSearchParameters(searchQuery); SearchViewModel model = await ViewingService.SearchAsync(searchParams, orderBy); ViewBag.ReturnUrl = SearchViewService.GetLastSearchUrl(); ViewBag.BasketViewModel = new CompareBasketViewModel { CanAddEmployers = false, CanViewCompare = CompareViewService.BasketItemCount > 1, CanClearCompare = true }; return(View("../ReportingStepByStep/Step1Task2", model)); } else { return(new HttpNotFoundResult()); } }
public IActionResult ManageOrganisation(string id) { // Check for feature flag and redirect if enabled if (FeatureFlagHelper.IsFeatureEnabled(FeatureFlag.NewManageOrganisationsJourney)) { return(RedirectToAction("ManageOrganisationGet", "ManageOrganisations", new { encryptedOrganisationId = id })); } //Ensure user has completed the registration process IActionResult checkResult = CheckUserRegisteredOk(out User currentUser); if (checkResult != null) { return(checkResult); } // Decrypt org id if (!id.DecryptToId(out long organisationId)) { return(new HttpBadRequestResult($"Cannot decrypt organisation id {id}")); } // Check the user has permission for this organisation UserOrganisation userOrg = currentUser.UserOrganisations.FirstOrDefault(uo => uo.OrganisationId == organisationId); if (userOrg == null || userOrg.PINConfirmedDate == null) { return(new HttpForbiddenResult($"User {currentUser?.EmailAddress} is not registered for organisation id {organisationId}")); } // clear the stash this.ClearStash(); //Get the current snapshot date DateTime currentSnapshotDate = userOrg.Organisation.SectorType.GetAccountingStartDate(); //Make sure we have an explicit scope for last and year for organisations new to this year if (userOrg.HasBeenActivated() && userOrg.Organisation.Created >= currentSnapshotDate) { ScopeStatuses scopeStatus = ScopeBusinessLogic.GetLatestScopeStatusForSnapshotYear(organisationId, currentSnapshotDate.Year - 1); if (!scopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope)) { return(RedirectToAction(nameof(DeclareScope), "Organisation", new { id })); } } // get any associated users for the current org List <UserOrganisation> associatedUserOrgs = userOrg.GetAssociatedUsers().ToList(); // build the view model List <int> yearsWithDraftReturns = DataRepository.GetAll <DraftReturn>() .Where(d => d.OrganisationId == organisationId) .Select(d => d.SnapshotYear) .ToList(); var model = new ManageOrganisationModel { CurrentUserOrg = userOrg, AssociatedUserOrgs = associatedUserOrgs, EncCurrentOrgId = Encryption.EncryptQuerystring(organisationId.ToString()), ReportingYearsWithDraftReturns = yearsWithDraftReturns }; return(View(model)); }