Ejemplo n.º 1
0
class IndividualUserEnrolmentView(BaseEnrolmentWizardView):
    google_analytics_page_id = 'IndividualEnrolment'
    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_BUSINESS_TYPE,
        constants.PROGRESS_STEP_LABEL_INDIVIDUAL_USER_ACCOUNT,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_PERSONAL_INFO
    ]

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={constants.PERSONAL_INFO: 3},
        step_counter_anon={
            constants.USER_ACCOUNT: 2,
            constants.VERIFICATION: 3,
            constants.PERSONAL_INFO: 4
        },
    )

    form_list = (
        (constants.USER_ACCOUNT, forms.UserAccount),
        (constants.VERIFICATION, forms.UserAccountVerification),
        (constants.PERSONAL_INFO, forms.IndividualPersonalDetails),
    )

    templates = {
        constants.USER_ACCOUNT: 'enrolment/individual-user-account.html',
        constants.VERIFICATION: 'enrolment/user-account-verification.html',
        constants.PERSONAL_INFO: 'enrolment/individual-personal-details.html',
        constants.FINISHED: 'enrolment/individual-success.html',
    }

    @property
    def verification_link_url(self):
        url = reverse('enrolment-individual',
                      kwargs={'step': constants.VERIFICATION})
        return self.request.build_absolute_uri(url)

    def get(self, *args, **kwargs):
        # at this point all the steps will be hidden as the user is logged
        # in and has a user profile, so the normal `get` method fails with
        # IndexError, meaning `done` will not be hit. Working around this:
        if self.kwargs['step'] == constants.FINISHED:
            return self.done()
        return super().get(*args, **kwargs)

    def get_template_names(self):
        return [self.templates[self.steps.current]]

    def done(self, *args, **kwargs):
        return TemplateResponse(self.request,
                                self.templates[constants.FINISHED],
                                self.get_finished_context_data())
Ejemplo n.º 2
0
class NonCompaniesHouseEnrolmentView(mixins.CreateBusinessProfileMixin,
                                     BaseEnrolmentWizardView):
    google_analytics_page_id = 'NonCompaniesHouseEnrolment'
    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_BUSINESS_TYPE,
        constants.PROGRESS_STEP_LABEL_USER_ACCOUNT,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
        constants.PROGRESS_STEP_LABEL_PERSONAL_INFO,
    ]

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            constants.ADDRESS_SEARCH: 2,
            constants.PERSONAL_INFO: 3,
        },
        step_counter_anon={
            constants.USER_ACCOUNT: 2,
            constants.VERIFICATION: 3,
            constants.ADDRESS_SEARCH: 4,
            constants.PERSONAL_INFO: 5,
        },
    )

    form_list = (
        (constants.USER_ACCOUNT, forms.UserAccount),
        (constants.VERIFICATION, forms.UserAccountVerification),
        (constants.ADDRESS_SEARCH, forms.NonCompaniesHouseSearch),
        (constants.PERSONAL_INFO, core.forms.PersonalDetails),
    )

    templates = {
        constants.USER_ACCOUNT: 'enrolment/user-account.html',
        constants.VERIFICATION: 'enrolment/user-account-verification.html',
        constants.ADDRESS_SEARCH: 'enrolment/address-search.html',
        constants.PERSONAL_INFO:
        'enrolment/non-companies-house-personal-details.html',
        constants.FINISHED: 'enrolment/non-companies-house-success.html',
    }

    @property
    def verification_link_url(self):
        url = reverse('enrolment-sole-trader',
                      kwargs={'step': constants.VERIFICATION})
        return self.request.build_absolute_uri(url)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if self.steps.current == constants.PERSONAL_INFO:
            context['company'] = self.get_cleaned_data_for_step(
                constants.ADDRESS_SEARCH)
        return context
Ejemplo n.º 3
0
    class TestView(views.ProgressIndicatorMixin, NamedUrlSessionWizardView):
        def get_template_names(self):
            return ['enrolment/user-account-resend-verification.html']

        form_list = (
            (views.USER_ACCOUNT, forms.UserAccount),
            (views.COMPANY_SEARCH, forms.UserAccount),
        )

        progress_conf = helpers.ProgressIndicatorConf(
            step_counter_user={views.USER_ACCOUNT: 2},
            step_counter_anon={views.USER_ACCOUNT: 2},
            first_step=views.USER_ACCOUNT,
        )
Ejemplo n.º 4
0
class ResendVerificationCodeView(mixins.RedirectLoggedInMixin,
                                 mixins.RestartOnStepSkipped,
                                 mixins.ProgressIndicatorMixin,
                                 mixins.StepsListMixin,
                                 mixins.CreateUserAccountMixin,
                                 mixins.GA360Mixin, NamedUrlSessionWizardView):

    google_analytics_page_id = 'ResendVerificationCode'
    form_list = (
        (constants.RESEND_VERIFICATION, forms.ResendVerificationCode),
        (constants.VERIFICATION, forms.UserAccountVerification),
    )

    templates = {
        constants.RESEND_VERIFICATION:
        'enrolment/user-account-resend-verification.html',
        constants.VERIFICATION: 'enrolment/user-account-verification.html',
        constants.FINISHED: 'enrolment/start.html',
    }

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_anon={
            constants.RESEND_VERIFICATION: 1,
            constants.VERIFICATION: 2
        },
        # logged in users should not get here
        step_counter_user={},
    )
    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_RESEND_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
    ]

    @property
    def verification_link_url(self):
        url = reverse('resend-verification',
                      kwargs={'step': constants.VERIFICATION})
        return self.request.build_absolute_uri(url)

    def get_template_names(self):
        return [self.templates[self.steps.current]]

    def render_done(self, form, **kwargs):
        choice = self.request.session.get(constants.SESSION_KEY_COMPANY_CHOICE)
        if choice == constants.COMPANIES_HOUSE_COMPANY:
            url = URL_COMPANIES_HOUSE_ENROLMENT
        elif choice == constants.NON_COMPANIES_HOUSE_COMPANY:
            url = URL_NON_COMPANIES_HOUSE_ENROLMENT
        elif choice == constants.NOT_COMPANY:
            url = URL_INDIVIDUAL_ENROLMENT
        else:
            url = reverse('enrolment-business-type')
        response = self.validate_code(form=form, response=redirect(url))
        return response

    def process_step(self, form):
        if form.prefix == constants.RESEND_VERIFICATION:
            email = form.cleaned_data['email']
            verification_code = helpers.regenerate_verification_code(email)
            if verification_code:
                helpers.send_verification_code_email(
                    email=email,
                    verification_code=verification_code,
                    form_url=self.request.path,
                    verification_link=self.verification_link_url,
                )
        return super().process_step(form)

    def get_context_data(self, *args, **kwargs):
        return super().get_context_data(
            verification_missing_url=urls.domestic.CONTACT_US /
            'triage/great-account/verification-missing/',
            contact_url=urls.domestic.CONTACT_US / 'domestic/',
            *args,
            **kwargs)

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == constants.VERIFICATION:
            data = self.get_cleaned_data_for_step(
                constants.RESEND_VERIFICATION)
            if data:
                form_initial['email'] = data['email']
        return form_initial
Ejemplo n.º 5
0
class PreVerifiedEnrolmentView(BaseEnrolmentWizardView):
    google_analytics_page_id = 'PreVerifiedEnrolment'

    # Needed by CreateUserAccountMixin, not applicable here
    verification_link_url = ''

    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_USER_ACCOUNT,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_PERSONAL_INFO,
    ]

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={constants.PERSONAL_INFO: 1},
        step_counter_anon={
            constants.USER_ACCOUNT: 1,
            constants.VERIFICATION: 2,
            constants.PERSONAL_INFO: 3,
        },
    )

    form_list = (
        (constants.USER_ACCOUNT, forms.UserAccount),
        (constants.VERIFICATION, forms.UserAccountVerification),
        (constants.PERSONAL_INFO, core.forms.PersonalDetails),
    )

    templates = {
        constants.USER_ACCOUNT: 'enrolment/user-account.html',
        constants.VERIFICATION: 'enrolment/user-account-verification.html',
        constants.PERSONAL_INFO: 'enrolment/preverified-personal-details.html',
        constants.FAILURE: 'enrolment/failure-pre-verified.html',
    }

    def get(self, *args, **kwargs):
        key = self.request.GET.get('key')
        if key:
            data = helpers.retrieve_preverified_company(key)
            if data:
                self.request.session[constants.SESSION_KEY_COMPANY_DATA] = data
                self.request.session[constants.SESSION_KEY_ENROL_KEY] = key
                self.request.session.save()
            else:
                return redirect(reverse('enrolment-start'))
        if self.steps.current == constants.PERSONAL_INFO:
            if not self.request.session.get(
                    constants.SESSION_KEY_COMPANY_DATA):
                return redirect(reverse('enrolment-start'))
        return super().get(*args, **kwargs)

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == constants.PERSONAL_INFO:
            context['company'] = self.request.session[
                constants.SESSION_KEY_COMPANY_DATA]
        return context

    def done(self, form_list, **kwargs):
        try:
            self.claim_company(self.serialize_form_list(form_list))
        except HTTPError:
            return TemplateResponse(self.request,
                                    self.templates[constants.FAILURE])
        else:
            messages.success(self.request, 'Business profile created')
            return redirect('business-profile')

    def claim_company(self, data):
        helpers.claim_company(
            enrolment_key=self.request.session[
                constants.SESSION_KEY_ENROL_KEY],
            personal_name=f'{data["given_name"]} {data["family_name"]}',
            sso_session_id=self.request.user.session_id,
        )

    def serialize_form_list(self, form_list):
        data = {}
        for form in form_list:
            data.update(form.cleaned_data)
        return data
Ejemplo n.º 6
0
class CollaboratorEnrolmentView(BaseEnrolmentWizardView):
    google_analytics_page_id = 'CollaboratorEnrolment'
    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_INDIVIDUAL_USER_ACCOUNT,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_PERSONAL_INFO
    ]

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={constants.PERSONAL_INFO: 2},
        step_counter_anon={
            constants.USER_ACCOUNT: 1,
            constants.VERIFICATION: 2,
            constants.PERSONAL_INFO: 3
        },
    )

    form_list = (
        (constants.USER_ACCOUNT, forms.UserAccountCollaboration),
        (constants.VERIFICATION, forms.UserAccountVerification),
        (constants.PERSONAL_INFO, forms.IndividualPersonalDetails),
    )

    templates = {
        constants.USER_ACCOUNT:
        'enrolment/individual-user-account.html',
        constants.VERIFICATION:
        'enrolment/user-account-verification.html',
        constants.PERSONAL_INFO:
        'enrolment/collaborator-personal-details.html',
        constants.FINISHED:
        'enrolment/individual-success.html',
        constants.INVITE_EXPIRED:
        'enrolment/individual-collaborator-invite-expired.html'
    }

    @property
    def verification_link_url(self):
        url = reverse('enrolment-collaboration',
                      kwargs={'step': constants.VERIFICATION})
        return self.request.build_absolute_uri(url)

    def get(self, *args, **kwargs):
        if 'invite_key' in self.request.GET:
            self.request.session[
                constants.
                SESSION_KEY_INVITE_KEY] = self.request.GET['invite_key']
            if not self.collaborator_invition:
                contact_url = urls.domestic.CONTACT_US / 'domestic/enquiries/'
                context = {
                    'contact_url':
                    contact_url,
                    'description':
                    ('This invitation has expired, please contact your business profile administrator to request a '
                     f'new invitation or <a href="{contact_url}"">contact us.</a>'
                     )
                }
                return TemplateResponse(
                    request=self.request,
                    template=self.templates[constants.INVITE_EXPIRED],
                    context=context,
                )
        # at this point all the steps will be hidden as the user is logged
        # in and has a user profile, so the normal `get` method fails with
        # IndexError, meaning `done` will not be hit. Working around this:
        if self.steps.count == 0:
            return self.render_done(form=None, step=constants.FINISHED)
        return super().get(*args, **kwargs)

    def get_template_names(self):
        return [self.templates[self.steps.current]]

    def create_company_profile(self):
        helpers.collaborator_invite_accept(
            sso_session_id=self.request.user.session_id,
            invite_key=self.request.session[constants.SESSION_KEY_INVITE_KEY],
        )

    @cached_property
    def collaborator_invition(self):
        return helpers.collaborator_invite_retrieve(
            self.request.session[constants.SESSION_KEY_INVITE_KEY])

    def get_context_data(self, **kwargs):
        return super().get_context_data(
            collaborator_invition=self.collaborator_invition,
            **kwargs,
        )

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == constants.USER_ACCOUNT:
            form_initial['email'] = self.collaborator_invition[
                'collaborator_email']
        return form_initial

    def done(self, *args, **kwargs):
        self.create_company_profile()
        messages.success(self.request, 'Account created')
        return redirect('business-profile')
Ejemplo n.º 7
0
class CompaniesHouseEnrolmentView(mixins.CreateBusinessProfileMixin,
                                  BaseEnrolmentWizardView):
    google_analytics_page_id = 'CompaniesHouseEnrolment'
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            constants.COMPANY_SEARCH: 2,
            constants.ADDRESS_SEARCH: 2,
            constants.BUSINESS_INFO: 2,
            constants.PERSONAL_INFO: 3,
        },
        step_counter_anon={
            constants.USER_ACCOUNT: 2,
            constants.VERIFICATION: 3,
            constants.COMPANY_SEARCH: 4,
            constants.ADDRESS_SEARCH: 4,
            constants.BUSINESS_INFO: 4,
            constants.PERSONAL_INFO: 5,
        },
    )
    steps_list_labels = [
        constants.PROGRESS_STEP_LABEL_BUSINESS_TYPE,
        constants.PROGRESS_STEP_LABEL_USER_ACCOUNT,
        constants.PROGRESS_STEP_LABEL_VERIFICATION,
        constants.PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
        constants.PROGRESS_STEP_LABEL_PERSONAL_INFO,
    ]

    form_list = (
        (constants.USER_ACCOUNT, forms.UserAccount),
        (constants.VERIFICATION, forms.UserAccountVerification),
        (constants.COMPANY_SEARCH, forms.CompaniesHouseCompanySearch),
        (constants.ADDRESS_SEARCH, forms.CompaniesHouseAddressSearch),
        (constants.BUSINESS_INFO, forms.CompaniesHouseBusinessDetails),
        (constants.PERSONAL_INFO, core.forms.PersonalDetails),
    )

    templates = {
        constants.USER_ACCOUNT: 'enrolment/user-account.html',
        constants.VERIFICATION: 'enrolment/user-account-verification.html',
        constants.COMPANY_SEARCH:
        'enrolment/companies-house-company-search.html',
        constants.ADDRESS_SEARCH: 'enrolment/address-search.html',
        constants.BUSINESS_INFO:
        'enrolment/companies-house-business-details.html',
        constants.PERSONAL_INFO:
        'enrolment/companies-house-personal-details.html',
        constants.FINISHED: 'enrolment/companies-house-success.html',
    }

    @property
    def verification_link_url(self):
        url = reverse('enrolment-companies-house',
                      kwargs={'step': constants.VERIFICATION})
        return self.request.build_absolute_uri(url)

    def address_search_condition(self):
        company = self.get_cleaned_data_for_step(constants.COMPANY_SEARCH)
        if not company:
            return True
        return helpers.is_companies_house_details_incomplete(
            company['company_number'])

    condition_dict = {
        constants.ADDRESS_SEARCH: address_search_condition,
        **mixins.CreateUserAccountMixin.condition_dict
    }

    def get_form_kwargs(self, step=None):
        form_kwargs = super().get_form_kwargs(step=step)
        if step == constants.BUSINESS_INFO:
            previous_data = self.get_cleaned_data_for_step(
                constants.COMPANY_SEARCH)
            if previous_data:
                form_kwargs['is_enrolled'] = helpers.get_is_enrolled(
                    previous_data['company_number'])
        return form_kwargs

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == constants.ADDRESS_SEARCH:
            company = self.get_cleaned_data_for_step(
                constants.COMPANY_SEARCH) or {}
            form_initial['company_name'] = company.get('company_name')
        elif step == constants.BUSINESS_INFO:
            company_search_step_data = self.get_cleaned_data_for_step(
                constants.COMPANY_SEARCH)
            company_data = helpers.get_companies_house_profile(
                company_search_step_data['company_number'])
            company = helpers.CompanyParser(company_data)
            form_initial['company_name'] = company.name
            form_initial['company_number'] = company.number
            form_initial['sic'] = company.nature_of_business
            form_initial['date_of_creation'] = company.date_of_creation
            if self.address_search_condition():
                address_step_data = self.get_cleaned_data_for_step(
                    constants.ADDRESS_SEARCH) or {}
                form_initial['address'] = address_step_data.get('address')
                form_initial['postal_code'] = address_step_data.get(
                    'postal_code')
            else:
                form_initial['address'] = company.address
                form_initial['postal_code'] = company.postcode
        return form_initial

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == constants.ADDRESS_SEARCH:
            context['is_in_companies_house'] = True
        return context

    def serialize_form_list(self, form_list):
        return {
            **super().serialize_form_list(form_list),
            'company_type':
            'COMPANIES_HOUSE',
        }

    def done(self, form_list, form_dict, **kwargs):
        data = self.serialize_form_list(form_list)
        is_enrolled = helpers.get_is_enrolled(data['company_number'])
        if is_enrolled:
            helpers.create_company_member(
                sso_session_id=self.request.user.session_id,
                data={
                    'company': data['company_number'],
                    'sso_id': self.request.user.id,
                    'company_email': self.request.user.email,
                    'name': self.request.user.full_name,
                    'mobile_number': data.get('phone_number', ''),
                })

            helpers.notify_company_admins_member_joined(
                sso_session_id=self.request.user.session_id,
                email_data={
                    'company_name':
                    data['company_name'],
                    'name':
                    self.request.user.full_name,
                    'email':
                    self.request.user.email,
                    'profile_remove_member_url':
                    self.request.build_absolute_uri(
                        reverse('business-profile-admin-tools')),
                    'report_abuse_url':
                    urls.domestic.FEEDBACK
                },
                form_url=self.request.path)

            if self.request.user.role == user_roles.MEMBER:
                messages.add_message(self.request, messages.SUCCESS,
                                     'You are now linked to the profile.')

            return redirect(
                reverse('business-profile') + '?member_user_linked=true')

        else:
            return super().done(form_list, form_dict=form_dict, **kwargs)
Ejemplo n.º 8
0
class ResendVerificationCodeView(NotFoundOnDisabledFeature,
                                 RedirectLoggedInMixin, RestartOnStepSkipped,
                                 ProgressIndicatorMixin, StepsListMixin,
                                 NamedUrlSessionWizardView):

    form_list = (
        (RESEND_VERIFICATION, forms.ResendVerificationCode),
        (VERIFICATION, forms.UserAccountVerification),
    )

    templates = {
        RESEND_VERIFICATION: 'enrolment/user-account-resend-verification.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        FINISHED: 'enrolment/start.html',
    }

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_anon={
            RESEND_VERIFICATION: 1,
            VERIFICATION: 2
        },
        first_step=RESEND_VERIFICATION,
        # logged in users should not get here
        step_counter_user={},
    )
    steps_list_conf = helpers.StepsListConf(
        form_labels_anon=[
            'Resend verification',
            PROGRESS_STEP_LABEL_VERIFICATION,
        ],
        # logged in users should not get here
        form_labels_user=[],
    )

    def get_template_names(self):
        return [self.templates[self.steps.current]]

    def done(self, form_list, **kwargs):
        cookies = self.get_cleaned_data_for_step(VERIFICATION)['cookies']
        choice = self.request.session.get('company_choice')
        if choice == constants.COMPANIES_HOUSE_COMPANY:
            url = URL_COMPANIES_HOUSE_ENROLMENT
        elif choice == constants.SOLE_TRADER:
            url = URL_SOLE_TRADER_ENROLMENT
        else:
            url = reverse('enrolment-business-type')
        response = redirect(url)
        response.cookies.update(cookies)
        return response

    def render_next_step(self, form, **kwargs):
        response = super().render_next_step(form, **kwargs)
        if form.prefix == RESEND_VERIFICATION:
            email = form.cleaned_data['email']
            verification_code = helpers.regenerate_verification_code(email)
            if verification_code:
                helpers.send_verification_code_email(
                    email=email,
                    verification_code=verification_code,
                    form_url=self.request.path,
                )
        return response

    def get_context_data(self, *args, **kwargs):
        return super().get_context_data(
            verification_missing_url=urls.build_great_url(
                'contact/triage/great-account/verification-missing/'),
            contact_url=urls.build_great_url('contact/domestic/'),
            *args,
            **kwargs)

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == VERIFICATION:
            data = self.get_cleaned_data_for_step(RESEND_VERIFICATION)
            if data:
                form_initial['email'] = data['email']
        return form_initial
Ejemplo n.º 9
0
class PreVerifiedEnrolmentView(BaseEnrolmentWizardView):
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[PROGRESS_STEP_LABEL_PERSONAL_INFO],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={PERSONAL_INFO: 1},
        step_counter_anon={
            USER_ACCOUNT: 1,
            VERIFICATION: 2,
            PERSONAL_INFO: 3,
        },
        first_step=USER_ACCOUNT,
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        PERSONAL_INFO: 'enrolment/preverified-personal-details.html',
        FINISHED: 'enrolment/success-pre-verified.html',
        FAILURE: 'enrolment/failure-pre-verified.html',
    }

    def get(self, *args, **kwargs):
        key = self.request.GET.get('key')
        if key:
            data = helpers.retrieve_preverified_company(key)
            if data:
                self.request.session[SESSION_KEY_COMPANY_DATA] = data
                self.request.session[SESSION_KEY_ENROL_KEY] = key
                self.request.session.save()
            else:
                return redirect(reverse('enrolment-start'))
        if self.steps.current == PERSONAL_INFO:
            if not self.request.session.get(SESSION_KEY_COMPANY_DATA):
                return redirect(reverse('enrolment-start'))
        return super().get(*args, **kwargs)

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == PERSONAL_INFO:
            context['company'] = (
                self.request.session[SESSION_KEY_COMPANY_DATA])
        return context

    def done(self, form_list, **kwargs):
        try:
            self.claim_company(self.serialize_form_list(form_list))
        except HTTPError:
            template_name = self.templates[FAILURE]
        else:
            template_name = self.templates[FINISHED]
        return TemplateResponse(self.request, template_name)

    def claim_company(self, data):
        helpers.claim_company(
            enrolment_key=self.request.session[SESSION_KEY_ENROL_KEY],
            personal_name=f'{data["given_name"]} {data["family_name"]}',
            sso_session_id=self.request.sso_user.session_id,
        )

    def serialize_form_list(self, form_list):
        data = {}
        for form in form_list:
            data.update(form.cleaned_data)
        return data
Ejemplo n.º 10
0
class SoleTraderEnrolmentView(CreateCompanyProfileMixin,
                              BaseEnrolmentWizardView):
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            COMPANY_SEARCH: 2,
            BUSINESS_INFO: 3,
            PERSONAL_INFO: 4,
        },
        step_counter_anon={
            USER_ACCOUNT: 2,
            VERIFICATION: 3,
            COMPANY_SEARCH: 4,
            BUSINESS_INFO: 4,
            PERSONAL_INFO: 5,
        },
        first_step=USER_ACCOUNT,
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (COMPANY_SEARCH, forms.SoleTraderSearch),
        (BUSINESS_INFO, forms.SoleTraderBusinessDetails),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        COMPANY_SEARCH: 'enrolment/sole-trader-search.html',
        BUSINESS_INFO: 'enrolment/sole-trader-business-details.html',
        PERSONAL_INFO: 'enrolment/sole-trader-personal-details.html',
        FINISHED: 'enrolment/success-sole-trader.html',
    }

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == BUSINESS_INFO:
            data = self.get_cleaned_data_for_step(COMPANY_SEARCH)
            if data:
                form_initial['address'] = data['address'].replace(', ', '\n')
                form_initial['postal_code'] = data['postal_code']
                form_initial['company_name'] = data['company_name']
        return form_initial

    def done(self, form_list, **kwargs):
        data = self.serialize_form_list(form_list)
        self.create_company_profile(data)
        return TemplateResponse(self.request, self.templates[FINISHED])

    def serialize_form_list(self, form_list):
        return {
            'company_type': 'SOLE_TRADER',
            **super().serialize_form_list(form_list)
        }
Ejemplo n.º 11
0
class CompaniesHouseEnrolmentView(CreateCompanyProfileMixin,
                                  BaseEnrolmentWizardView):
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            COMPANY_SEARCH: 2,
            BUSINESS_INFO: 2,
            PERSONAL_INFO: 3,
        },
        step_counter_anon={
            USER_ACCOUNT: 2,
            VERIFICATION: 3,
            COMPANY_SEARCH: 4,
            BUSINESS_INFO: 4,
            PERSONAL_INFO: 5,
        },
        first_step=USER_ACCOUNT,
    )
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (COMPANY_SEARCH, forms.CompaniesHouseSearch),
        (BUSINESS_INFO, forms.CompaniesHouseBusinessDetails),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        COMPANY_SEARCH: 'enrolment/companies-house-search.html',
        BUSINESS_INFO: 'enrolment/companies-house-business-details.html',
        PERSONAL_INFO: 'enrolment/companies-house-personal-details.html',
        FINISHED: 'enrolment/success-companies-house.html',
    }

    def get_form_kwargs(self, step=None):
        form_kwargs = super().get_form_kwargs(step=step)
        if step == BUSINESS_INFO:
            previous_data = self.get_cleaned_data_for_step(COMPANY_SEARCH)
            if previous_data:
                form_kwargs['company_data'] = helpers.get_company_profile(
                    number=previous_data['company_number'],
                    session=self.request.session,
                )
                form_kwargs['is_enrolled'] = helpers.get_is_enrolled(
                    company_number=previous_data['company_number'],
                    session=self.request.session,
                )
        elif step == COMPANY_SEARCH:
            form_kwargs['session'] = self.request.session
        return form_kwargs

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == COMPANY_SEARCH:
            context['company_not_found_url'] = urls.build_great_url(
                'contact/triage/great-account/company-not-found/')
        return context

    def serialize_form_list(self, form_list):
        return {
            'company_type': 'COMPANIES_HOUSE',
            **super().serialize_form_list(form_list)
        }

    def done(self, form_list, **kwargs):
        data = self.serialize_form_list(form_list)
        is_enrolled = helpers.get_is_enrolled(
            company_number=data['company_number'],
            session=self.request.session,
        )
        if is_enrolled:
            helpers.request_collaboration(
                company_number=data['company_number'],
                email=self.request.sso_user.email,
                name=f"{data['given_name']} {data['family_name']}",
                form_url=self.request.path,
            )
        else:
            self.create_company_profile(data)
        return TemplateResponse(self.request, self.templates[FINISHED])