def add_organisation_from_nhs_local_service(service_id): if (not current_service.organisation_type == Organisation.TYPE_NHS_LOCAL) or current_service.organisation: abort(403) form = AddNHSLocalOrganisationForm( organisation_choices=[(organisation.id, organisation.name) for organisation in Organisations() if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL]) search_form = SearchByNameForm() if form.validate_on_submit(): Organisation.from_id( form.organisations.data).associate_service(service_id) return redirect(url_for( '.service_agreement', service_id=service_id, )) return render_template( 'views/organisations/add-nhs-local-organisation.html', form=form, search_form=search_form, )
def accept_org_invite(token): invited_org_user = InvitedOrgUser.from_token(token) if not current_user.is_anonymous and current_user.email_address.lower( ) != invited_org_user.email_address.lower(): message = Markup(""" You’re signed in as {}. This invite is for another email address. <a class="govuk-link govuk-link--no-visited-state" href={}>Sign out</a> and click the link again to accept this invite. """.format(current_user.email_address, url_for("main.sign_out", _external=True))) flash(message=message) abort(403) if invited_org_user.status == 'cancelled': organisation = Organisation.from_id(invited_org_user.organisation) return render_template('views/cancelled-invitation.html', from_user=invited_org_user.invited_by.name, organisation_name=organisation.name) if invited_org_user.status == 'accepted': session.pop('invited_org_user', None) return redirect( url_for('main.organisation_dashboard', org_id=invited_org_user.organisation)) session['invited_org_user'] = invited_org_user.serialize() existing_user = User.from_email_address_or_none( invited_org_user.email_address) organisation_users = OrganisationUsers(invited_org_user.organisation) if existing_user: invited_org_user.accept_invite() if existing_user not in organisation_users: existing_user.add_to_organisation( organisation_id=invited_org_user.organisation) return redirect( url_for('main.organisation_dashboard', org_id=invited_org_user.organisation)) else: return redirect(url_for('main.register_from_org_invite'))
def load_organisation_before_request(): if '/static/' in request.url: _request_ctx_stack.top.organisation = None return if _request_ctx_stack.top is not None: _request_ctx_stack.top.organisation = None if request.view_args: org_id = request.view_args.get('org_id') if org_id: try: _request_ctx_stack.top.organisation = Organisation.from_id(org_id) except HTTPError as exc: # if org id isn't real, then 404 rather than 500ing later because we expect org to be set if exc.status_code == 404: abort(404) else: raise
def accept_org_invite(token): invited_org_user = InvitedOrgUser.from_token(token) if not current_user.is_anonymous and current_user.email_address.lower() != invited_org_user.email_address.lower(): message = Markup( _( "You’re signed in as %(email)s. This invite is for another email address. " + "<a href=%(href)s>Sign out</a> and click the link again to accept this invite.", email=current_user.email_address, href=url_for("main.sign_out", _external=True), ) ) flash(message=message) abort(403) if invited_org_user.status == "cancelled": organisation = Organisation.from_id(invited_org_user.organisation) return render_template( "views/cancelled-invitation.html", from_user=invited_org_user.invited_by.name, organisation_name=organisation.name, ) if invited_org_user.status == "accepted": session.pop("invited_org_user", None) return redirect(url_for("main.organisation_dashboard", org_id=invited_org_user.organisation)) session["invited_org_user"] = invited_org_user.serialize() existing_user = User.from_email_address_or_none(invited_org_user.email_address) organisation_users = OrganisationUsers(invited_org_user.organisation) if existing_user: invited_org_user.accept_invite() if existing_user not in organisation_users: existing_user.add_to_organisation(organisation_id=invited_org_user.organisation) return redirect(url_for("main.organisation_dashboard", org_id=invited_org_user.organisation)) else: return redirect(url_for("main.register_from_org_invite"))
def organisation(self): return Organisation.from_id(self.organisation_id)