public async Task <IActionResult> Index(ChangePasswordFormData formData, DlsSubApplication dlsSubApplication)
        {
            var adminId    = User.GetAdminId();
            var delegateId = User.GetCandidateId();

            var verifiedLinkedUsersAccounts = string.IsNullOrEmpty(formData.CurrentPassword)
                ? new UserAccountSet()
                : userService.GetVerifiedLinkedUsersAccounts(adminId, delegateId, formData.CurrentPassword !);

            if (!verifiedLinkedUsersAccounts.Any())
            {
                ModelState.AddModelError(
                    nameof(ChangePasswordFormData.CurrentPassword),
                    CommonValidationErrorMessages.IncorrectPassword
                    );
            }

            if (!ModelState.IsValid)
            {
                var model = new ChangePasswordViewModel(formData, dlsSubApplication);
                return(View(model));
            }

            var newPassword = formData.Password !;

            await passwordService.ChangePasswordAsync(verifiedLinkedUsersAccounts.GetUserRefs(), newPassword);

            return(View("Success", dlsSubApplication));
        }
Example #2
0
        public void DlsSubApplication_enums_return_expected_values(
            DlsSubApplication dlsSubApplication,
            int id,
            string name,
            string headerExtension,
            string?headerPath,
            string?headerPathName,
            string?urlSegment,
            int?faqTargetGroupId,
            bool displayHelpMenuItem,
            bool hasNullHeaderData
            )
        {
            using (new AssertionScope())
            {
                dlsSubApplication.Id.Should().Be(id);
                dlsSubApplication.Name.Should().Be(name);
                dlsSubApplication.HeaderExtension.Should().Be(headerExtension);
                dlsSubApplication.UrlSegment.Should().Be(urlSegment);
                dlsSubApplication.FaqTargetGroupId.Should().Be(faqTargetGroupId);
                dlsSubApplication.DisplayHelpMenuItem.Should().Be(displayHelpMenuItem);

                if (hasNullHeaderData)
                {
                    dlsSubApplication.HeaderPath.Should().BeNull();
                    dlsSubApplication.HeaderPathName.Should().BeNull();
                }
                else
                {
                    dlsSubApplication.HeaderPath.Should().EndWith(headerPath);
                    dlsSubApplication.HeaderPathName.Should().EndWith(headerPathName);
                }
            }
        }
Example #3
0
 public SupportViewModel(
     DlsSubApplication dlsSubApplication,
     SupportPage currentPage,
     string currentSystemBaseUrl
     ) : base(dlsSubApplication, currentPage, currentSystemBaseUrl)
 {
 }
Example #4
0
        public async Task <IActionResult> Index(DlsSubApplication dlsSubApplication)
        {
            if (!DlsSubApplication.TrackingSystem.Equals(dlsSubApplication) &&
                !DlsSubApplication.Frameworks.Equals(dlsSubApplication))
            {
                return(NotFound());
            }

            // TODO HEEDLS-608 If the user is centre admin but tracking system is off we need to show a 404
            // TODO HEEDLS-608 name these something appropriate
            var trackingSystemSupportEnabled =
                DlsSubApplication.TrackingSystem.Equals(dlsSubApplication) &&
                User.HasCentreAdminPermissions() &&
                await featureManager.IsEnabledAsync(FeatureFlags.RefactoredTrackingSystem);

            var frameworksSupportEnabled = DlsSubApplication.Frameworks.Equals(dlsSubApplication) &&
                                           User.HasFrameworksAdminPermissions();

            if (trackingSystemSupportEnabled || frameworksSupportEnabled)
            {
                var model = new SupportTicketsViewModel(
                    dlsSubApplication,
                    SupportPage.SupportTickets,
                    configuration.GetCurrentSystemBaseUrl()
                    );
                return(View("Index", model));
            }

            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult SaveNotificationPreferences(
            UserType?userType,
            IEnumerable <int> notificationIds,
            DlsSubApplication dlsSubApplication
            )
        {
            var userReference = GetUserReference(userType);

            if (userReference == null)
            {
                return(RedirectToAction("AccessDenied", "LearningSolutions"));
            }

            notificationPreferencesService.SetNotificationPreferencesForUser(
                userReference.UserType,
                userReference.Id,
                notificationIds
                );

            return(RedirectToAction(
                       "Index",
                       "NotificationPreferences",
                       new { dlsSubApplication = dlsSubApplication.UrlSegment }
                       ));
        }
Example #6
0
        public IActionResult AllFaqItems(DlsSubApplication dlsSubApplication)
        {
            var faqs = faqsService.GetPublishedFaqsForTargetGroup(dlsSubApplication.FaqTargetGroupId !.Value)
                       .Select(f => new SearchableFaq(f));

            var model = new FaqItemsViewModel(dlsSubApplication, faqs);

            return(View(model));
        }
 public ResourcesViewModel(
     DlsSubApplication dlsSubApplication,
     SupportPage currentPage,
     string currentSystemBaseUrl,
     IEnumerable <ResourceGroup> resourceGroups
     ) : base(dlsSubApplication, currentPage, currentSystemBaseUrl)
 {
     Categories = resourceGroups.Select(rc => new ResourceGroupViewModel(rc, currentSystemBaseUrl));
 }
 protected BaseSupportViewModel(
     DlsSubApplication dlsSubApplication,
     SupportPage currentPage,
     string currentSystemBaseUrl
     )
 {
     CurrentPage          = currentPage;
     DlsSubApplication    = dlsSubApplication;
     CurrentSystemBaseUrl = currentSystemBaseUrl;
 }
Example #9
0
        public IActionResult Index(DlsSubApplication dlsSubApplication)
        {
            var model = new SupportViewModel(
                dlsSubApplication,
                SupportPage.Support,
                configuration.GetCurrentSystemBaseUrl()
                );

            return(View("Support", model));
        }
Example #10
0
 public UpdateNotificationPreferencesViewModel(
     IEnumerable <NotificationPreference> notifications,
     string userType,
     DlsSubApplication dlsSubApplication
     )
 {
     Notifications     = notifications;
     UserType          = userType;
     DlsSubApplication = dlsSubApplication;
 }
        public IActionResult Index(DlsSubApplication dlsSubApplication)
        {
            var model = new ResourcesViewModel(
                dlsSubApplication,
                SupportPage.Resources,
                configuration.GetCurrentSystemBaseUrl(),
                resourcesService.GetAllResources()
                );

            return(View("Index", model));
        }
 public NotificationPreferenceListViewModel(
     IEnumerable <NotificationPreference> notifications,
     UserType userType,
     bool showAsExpandable,
     DlsSubApplication dlsSubApplication
     )
 {
     Notifications     = notifications;
     UserType          = userType;
     ShowAsExpandable  = showAsExpandable;
     DlsSubApplication = dlsSubApplication;
 }
Example #13
0
        public IActionResult ViewFaq(DlsSubApplication dlsSubApplication, int faqId)
        {
            var faq = faqsService.GetPublishedFaqByIdForTargetGroup(faqId, dlsSubApplication.FaqTargetGroupId !.Value);

            if (faq == null)
            {
                return(NotFound());
            }

            var model = new SearchableFaqViewModel(dlsSubApplication, new SearchableFaq(faq));

            return(View(model));
        }
Example #14
0
        public FaqsPageViewModel(
            DlsSubApplication dlsSubApplication,
            SupportPage currentPage,
            string currentSystemBaseUrl,
            SearchSortFilterPaginationResult <SearchableFaq> result
            ) : base(result, false, searchLabel: "Search faqs")
        {
            CurrentPage          = currentPage;
            DlsSubApplication    = dlsSubApplication;
            CurrentSystemBaseUrl = currentSystemBaseUrl;

            Faqs = result.ItemsToDisplay.Select(f => new SearchableFaqViewModel(DlsSubApplication, f));
        }
Example #15
0
 public IActionResult EditDetails(
     MyAccountEditDetailsFormData formData,
     string action,
     DlsSubApplication dlsSubApplication
     )
 {
     return(action switch
     {
         "save" => EditDetailsPostSave(formData, dlsSubApplication),
         "previewImage" => EditDetailsPostPreviewImage(formData, dlsSubApplication),
         "removeImage" => EditDetailsPostRemoveImage(formData, dlsSubApplication),
         _ => new StatusCodeResult(500),
     });
        private async Task <bool> ApplicationIsInaccessibleByPage(
            DlsSubApplication application
            )
        {
            if (DlsSubApplication.TrackingSystem.Equals(application) &&
                !await featureManager.IsEnabledAsync(FeatureFlags.RefactoredTrackingSystem) ||
                DlsSubApplication.SuperAdmin.Equals(application) &&
                !await featureManager.IsEnabledAsync(FeatureFlags.RefactoredSuperAdminInterface))
            {
                return(true);
            }

            return(!validApplications.Contains(application));
        }
Example #17
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            var enumerationName = bindingContext.ValueProvider.GetValue(bindingContext.FieldName);

            if (string.IsNullOrEmpty(enumerationName.FirstValue))
            {
                bindingContext.Result = ModelBindingResult.Success(DlsSubApplication.Default);
            }
            else if (DlsSubApplication.TryGetFromUrlSegment(enumerationName.FirstValue, out var result, true))
            {
                bindingContext.Result = ModelBindingResult.Success(result !);
            }
Example #18
0
        public IActionResult Index(DlsSubApplication dlsSubApplication)
        {
            var userAdminId    = User.GetAdminId();
            var userDelegateId = User.GetCandidateId();

            var(adminUser, delegateUser) = userService.GetUsersById(userAdminId, userDelegateId);

            var customPrompts =
                centreRegistrationPromptsService.GetCentreRegistrationPromptsWithAnswersByCentreIdAndDelegateUser(
                    User.GetCentreId(),
                    delegateUser
                    );

            var model = new MyAccountViewModel(adminUser, delegateUser, customPrompts, dlsSubApplication);

            return(View(model));
        }
        public IActionResult Index(DlsSubApplication dlsSubApplication)
        {
            var adminId            = User.GetCustomClaimAsInt(CustomClaimTypes.UserAdminId);
            var adminNotifications =
                notificationPreferencesService.GetNotificationPreferencesForUser(UserType.AdminUser, adminId);

            var delegateId            = User.GetCandidateId();
            var delegateNotifications =
                notificationPreferencesService.GetNotificationPreferencesForUser(UserType.DelegateUser, delegateId);

            var model = new NotificationPreferencesViewModel(
                adminNotifications,
                delegateNotifications,
                dlsSubApplication
                );

            return(View(model));
        }
Example #20
0
        public FaqsPageViewModel(
            DlsSubApplication dlsSubApplication,
            SupportPage currentPage,
            string currentSystemBaseUrl,
            IEnumerable <SearchableFaq> faqs,
            int page,
            string?searchString
            ) : base(searchString, page, false, FaqSortBy, Descending, searchLabel: "Search faqs")
        {
            CurrentPage          = currentPage;
            DlsSubApplication    = dlsSubApplication;
            CurrentSystemBaseUrl = currentSystemBaseUrl;

            var searchedItems = GenericSearchHelper.SearchItemsUsingTokeniseScorer(faqs, SearchString, MatchCutOffScore).ToList();
            var faqsToShow    = SortFilterAndPaginate(searchedItems);

            Faqs = faqsToShow.Select(f => new SearchableFaqViewModel(DlsSubApplication, f));
        }
        public IActionResult UpdateNotificationPreferences(UserType?userType, DlsSubApplication dlsSubApplication)
        {
            var userReference = GetUserReference(userType);

            if (userReference == null)
            {
                return(RedirectToAction("AccessDenied", "LearningSolutions"));
            }

            var notifications =
                notificationPreferencesService.GetNotificationPreferencesForUser(
                    userReference.UserType,
                    userReference.Id
                    );

            var model = new UpdateNotificationPreferencesViewModel(notifications, userType !, dlsSubApplication);

            return(View(model));
        }
Example #22
0
        public IActionResult Index(
            DlsSubApplication dlsSubApplication,
            int page            = 1,
            string?searchString = null
            )
        {
            var faqs = faqsService.GetPublishedFaqsForTargetGroup(dlsSubApplication.FaqTargetGroupId !.Value)
                       .Select(f => new SearchableFaq(f));

            var model = new FaqsPageViewModel(
                dlsSubApplication,
                SupportPage.Faqs,
                configuration.GetCurrentSystemBaseUrl(),
                faqs,
                page,
                searchString
                );

            return(View("Faqs", model));
        }
Example #23
0
        public IActionResult EditDetails(DlsSubApplication dlsSubApplication)
        {
            var userAdminId    = User.GetAdminId();
            var userDelegateId = User.GetCandidateId();

            var(adminUser, delegateUser) = userService.GetUsersById(userAdminId, userDelegateId);

            var jobGroups     = jobGroupsDataService.GetJobGroupsAlphabetical().ToList();
            var customPrompts =
                promptsService.GetEditDelegateRegistrationPromptViewModelsForCentre(delegateUser, User.GetCentreId());

            var model = new MyAccountEditDetailsViewModel(
                adminUser,
                delegateUser,
                jobGroups,
                customPrompts,
                dlsSubApplication
                );

            return(View(model));
        }
        public NotificationPreferencesViewModel(
            IEnumerable <NotificationPreference> adminNotifications,
            IEnumerable <NotificationPreference> delegateNotifications,
            DlsSubApplication dlsSubApplication
            )
        {
            AdminNotifications = new NotificationPreferenceListViewModel(
                adminNotifications,
                UserType.AdminUser,
                delegateNotifications.Any(),
                dlsSubApplication
                );
            DelegateNotifications = new NotificationPreferenceListViewModel(
                delegateNotifications,
                UserType.DelegateUser,
                adminNotifications.Any(),
                dlsSubApplication
                );

            DlsSubApplication = dlsSubApplication;
        }
        public MyAccountViewModel(
            AdminUser?adminUser,
            DelegateUser?delegateUser,
            CentreRegistrationPromptsWithAnswers?customPrompts,
            DlsSubApplication dlsSubApplication
            )
        {
            FirstName      = adminUser?.FirstName ?? delegateUser?.FirstName;
            Surname        = adminUser?.LastName ?? delegateUser?.LastName;
            User           = adminUser?.EmailAddress ?? delegateUser?.EmailAddress;
            ProfilePicture = adminUser?.ProfileImage ?? delegateUser?.ProfileImage;
            Centre         = adminUser?.CentreName ?? delegateUser?.CentreName;
            DelegateNumber = delegateUser?.CandidateNumber;
            AliasId        = delegateUser?.AliasId;
            JobGroup       = delegateUser?.JobGroupName;
            ProfessionalRegistrationNumber = delegateUser == null
                ? null
                : PrnStringHelper.GetPrnDisplayString(
                delegateUser.HasBeenPromptedForPrn,
                delegateUser.ProfessionalRegistrationNumber
                );

            DelegateRegistrationPrompts = new List <DelegateRegistrationPrompt>();
            if (customPrompts != null)
            {
                DelegateRegistrationPrompts = customPrompts.CustomPrompts.Select(
                    cp =>
                    new DelegateRegistrationPrompt(
                        cp.RegistrationField.Id,
                        cp.PromptText,
                        cp.Mandatory,
                        cp.Answer
                        )
                    )
                                              .ToList();
            }

            DlsSubApplication = dlsSubApplication;
        }
        private void ValidateUserHasPermissionForApplicationAndSetAppropriateResult(
            ActionExecutingContext context,
            ClaimsPrincipal user,
            DlsSubApplication application,
            string dlsSubApplicationParameterName
            )
        {
            if (user.IsDelegateOnlyAccount() && DlsSubApplication.Main.Equals(application))
            {
                SetLearningPortalVersionRedirectResult(context, dlsSubApplicationParameterName !);
                return;
            }

            if (!user.HasLearningPortalPermissions() && DlsSubApplication.LearningPortal.Equals(application) ||
                !user.HasFrameworksAdminPermissions() && DlsSubApplication.Frameworks.Equals(application) ||
                !user.HasSupervisorAdminPermissions() && DlsSubApplication.Supervisor.Equals(application) ||
                !user.HasCentreAdminPermissions() && DlsSubApplication.TrackingSystem.Equals(application) ||
                !user.HasSuperAdminPermissions() && DlsSubApplication.SuperAdmin.Equals(application))
            {
                SetAccessDeniedRedirectResult(context);
            }
        }
Example #27
0
        public IActionResult Index(
            DlsSubApplication dlsSubApplication,
            int page            = 1,
            string?searchString = null
            )
        {
            // A MatchCutOffScore of 65 is being used here rather than the default 80.
            // The default Fuzzy Search configuration does not reliably bring back expected FAQs.
            // Through trial and error a combination of the PartialTokenSetScorer ratio scorer
            // and this cut off score bring back reliable results comparable to the JS search.
            const int    matchCutOffScore = 65;
            const string faqSortBy        = "Weighting,FaqId";

            var faqs = faqsService.GetPublishedFaqsForTargetGroup(dlsSubApplication.FaqTargetGroupId !.Value)
                       .Select(f => new SearchableFaq(f));

            var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
                new SearchOptions(searchString, matchCutOffScore, true),
                new SortOptions(faqSortBy, GenericSortingHelper.Descending),
                null,
                new PaginationOptions(page)
                );

            var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                faqs,
                searchSortPaginationOptions
                );

            var model = new FaqsPageViewModel(
                dlsSubApplication,
                SupportPage.Faqs,
                configuration.GetCurrentSystemBaseUrl(),
                result
                );

            return(View("Faqs", model));
        }
Example #28
0
        public MyAccountViewModel(
            AdminUser?adminUser,
            DelegateUser?delegateUser,
            CentreCustomPromptsWithAnswers?customPrompts,
            DlsSubApplication dlsSubApplication
            )
        {
            FirstName      = adminUser?.FirstName ?? delegateUser?.FirstName;
            Surname        = adminUser?.LastName ?? delegateUser?.LastName;
            User           = adminUser?.EmailAddress ?? delegateUser?.EmailAddress;
            ProfilePicture = adminUser?.ProfileImage ?? delegateUser?.ProfileImage;
            Centre         = adminUser?.CentreName ?? delegateUser?.CentreName;
            DelegateNumber = delegateUser?.CandidateNumber;
            AliasId        = delegateUser?.AliasId;
            JobGroup       = delegateUser?.JobGroupName;
            ProfessionalRegistrationNumber = delegateUser?.HasBeenPromptedForPrn == true
                ? delegateUser.ProfessionalRegistrationNumber ?? "Not professionally registered"
                : "Not yet provided";

            CustomFields = new List <CustomFieldViewModel>();
            if (customPrompts != null)
            {
                CustomFields = customPrompts.CustomPrompts.Select(
                    cp =>
                    new CustomFieldViewModel(
                        cp.CustomPromptNumber,
                        cp.CustomPromptText,
                        cp.Mandatory,
                        cp.Answer
                        )
                    )
                               .ToList();
            }

            DlsSubApplication = dlsSubApplication;
        }
 public ChangePasswordViewModel(DlsSubApplication dlsSubApplication) : this(
         new ChangePasswordFormData(),
         dlsSubApplication
         )
 {
 }
 public ChangePasswordViewModel(ChangePasswordFormData formData, DlsSubApplication dlsSubApplication) : base(formData)
 {
     DlsSubApplication = dlsSubApplication;
 }