コード例 #1
0
        public IActionResult ActivateOrganisation(string 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 employe id {id}"));
            }

            // Check the user has permission for this organisation
            UserOrganisation userOrg = currentUser.UserOrganisations.FirstOrDefault(uo => uo.OrganisationId == organisationId);

            if (userOrg == null)
            {
                return(new HttpForbiddenResult($"User {currentUser?.EmailAddress} is not registered for employer id {organisationId}"));
            }

            // TODO - Delete this once PITP is enabled
            if (userOrg.HasExpiredPin())
            {
                userOrg.Organisation.UserOrganisations.Remove(userOrg);
                DataRepository.Delete(userOrg);
                DataRepository.SaveChanges();

                throw new PinExpiredException();
            }

            // Ensure this organisation needs activation on the users account
            if (userOrg.HasBeenActivated())
            {
                throw new Exception(
                          $"Attempt to activate employer {userOrg.OrganisationId}:'{userOrg.Organisation.OrganisationName}' for {currentUser.EmailAddress} by '{(OriginalUser == null ? currentUser.EmailAddress : OriginalUser.EmailAddress)}' which has already been activated");
            }

            // begin ActivateService journey
            ReportingOrganisationId = organisationId;
            return(RedirectToAction("ActivateService", "Register"));
        }
コード例 #2
0
        private ActionResult UnwrapRegistrationRequest(OrganisationViewModel model, out UserOrganisation userOrg)
        {
            userOrg = null;

            long userId = 0;
            long orgId  = 0;

            try
            {
                string code = Encryption.DecryptQuerystring(model.ReviewCode);
                code = HttpUtility.UrlDecode(code);
                string[] args = code.SplitI(":");
                if (args.Length != 3)
                {
                    throw new ArgumentException("Too few parameters in registration review code");
                }

                userId = args[0].ToLong();
                if (userId == 0)
                {
                    throw new ArgumentException("Invalid user id in registration review code");
                }

                orgId = args[1].ToLong();
                if (orgId == 0)
                {
                    throw new ArgumentException("Invalid organisation id in registration review code");
                }
            }
            catch
            {
                return(View("CustomError", new ErrorViewModel(1114)));
            }

            //Get the user oganisation
            userOrg = DataRepository.GetAll <UserOrganisation>()
                      .Where(uo => uo.UserId == userId)
                      .Where(uo => uo.OrganisationId == orgId)
                      .FirstOrDefault();

            if (userOrg == null)
            {
                return(View("CustomError", new ErrorViewModel(1115)));
            }

            //Check this registrations hasnt already completed
            if (userOrg.HasBeenActivated())
            {
                return(View("CustomError", new ErrorViewModel(1145)));
            }

            switch (userOrg.Organisation.Status)
            {
            case OrganisationStatuses.Active:
            case OrganisationStatuses.Pending:
                break;

            default:
                throw new ArgumentException(
                          $"Invalid organisation status {userOrg.Organisation.Status} user {userId} and organisation {orgId} for reviewing registration request");
            }

            if (userOrg.Address == null)
            {
                throw new Exception($"Cannot find address for user {userId} and organisation {orgId} for reviewing registration request");
            }

            //Load view model
            model.ContactFirstName = userOrg.User.ContactFirstName;
            model.ContactLastName  = userOrg.User.ContactLastName;
            if (string.IsNullOrWhiteSpace(model.ContactFirstName) && string.IsNullOrWhiteSpace(model.ContactFirstName))
            {
                model.ContactFirstName = userOrg.User.Firstname;
                model.ContactLastName  = userOrg.User.Lastname;
            }

            model.ContactJobTitle     = userOrg.User.ContactJobTitle.Coalesce(userOrg.User.JobTitle);
            model.ContactEmailAddress = userOrg.User.ContactEmailAddress.Coalesce(userOrg.User.EmailAddress);
            model.EmailAddress        = userOrg.User.EmailAddress;
            model.ContactPhoneNumber  = userOrg.User.ContactPhoneNumber;

            model.OrganisationName = userOrg.Organisation.OrganisationName;
            model.CompanyNumber    = userOrg.Organisation.CompanyNumber;
            model.SectorType       = userOrg.Organisation.SectorType;

            var sicCodeIds = userOrg.Organisation.GetSicCodes().Select(o => o.SicCode.SicCodeId).ToList();

            model.SicCodes = DataRepository.GetAll <SicCode>().Where(s => sicCodeIds.Contains(s.SicCodeId)).ToList();

            model.Address1 = userOrg.Address.Address1;
            model.Address2 = userOrg.Address.Address2;
            model.Address3 = userOrg.Address.Address3;
            model.Country  = userOrg.Address.Country;
            model.Postcode = userOrg.Address.PostCode;
            model.PoBox    = userOrg.Address.PoBox;

            model.RegisteredAddress = userOrg.Address.Status == AddressStatuses.Pending
                ? userOrg.Organisation.GetLatestAddress().GetAddressLines()
                : null;

            model.CharityNumber = userOrg.Organisation.OrganisationReferences
                                  .Where(o => o.ReferenceName.ToLower() == nameof(OrganisationViewModel.CharityNumber).ToLower())
                                  .Select(or => or.ReferenceValue)
                                  .FirstOrDefault();

            model.MutualNumber = userOrg.Organisation.OrganisationReferences
                                 .Where(o => o.ReferenceName.ToLower() == nameof(OrganisationViewModel.MutualNumber).ToLower())
                                 .Select(or => or.ReferenceValue)
                                 .FirstOrDefault();

            model.OtherName = userOrg.Organisation.OrganisationReferences.ToList()
                              .Where(
                o => o.ReferenceName.ToLower() != nameof(OrganisationViewModel.CharityNumber).ToLower() &&
                o.ReferenceName.ToLower() != nameof(OrganisationViewModel.MutualNumber).ToLower())
                              .Select(or => or.ReferenceName)
                              .FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(model.OtherName))
            {
                model.OtherValue = userOrg.Organisation.OrganisationReferences
                                   .Where(o => o.ReferenceName == model.OtherName)
                                   .Select(or => or.ReferenceValue)
                                   .FirstOrDefault();
            }

            return(null);
        }
コード例 #3
0
        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));
        }