Esempio n. 1
0
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,
    )
Esempio n. 2
0
    def post(self, organisation_id):
        """
        """

        schema = NamespaceSchema()

        namespace_data = request.get_json()

        validated_namespace_data, errors = schema.load(namespace_data)

        if errors:
            return dict(status='fail', message=errors), 400

        organisation = Organisation.get_by_id(organisation_id)

        if not organisation:
            return dict(
                status='fail',
                message=f'Organisation with id {organisation_id} not found'
            ), 404

        name = validated_namespace_data.get('name')

        namespace = Namespace(name, organisation_id)
        saved = namespace.save()

        if not saved:
            return dict(status='fail', message='Internal Server Error'), 500

        new_namespace_data, errors = schema.dumps(namespace)

        return dict(status='success',
                    data=dict(namespace=json.loads(new_namespace_data))), 201
def add_organisation():
    form = NewOrganisationForm()

    if form.validate_on_submit():
        return redirect(
            url_for(
                '.organisation_settings',
                org_id=Organisation.create_from_form(form).id,
            ))

    return render_template('views/organisations/add-organisation.html',
                           form=form)
Esempio n. 4
0
def add_organisation_from_gp_service(service_id):
    if (not current_service.organisation_type
            == Organisation.TYPE_NHS_GP) or current_service.organisation:
        abort(403)

    form = AddGPOrganisationForm(service_name=current_service.name)

    if form.validate_on_submit():
        Organisation.create(
            form.get_organisation_name(),
            crown=False,
            organisation_type='nhs_gp',
            agreement_signed=False,
        ).associate_service(service_id)
        return redirect(url_for(
            '.service_agreement',
            service_id=service_id,
        ))

    return render_template('views/organisations/add-gp-organisation.html',
                           form=form)
Esempio n. 5
0
    def delete(self, organisation_id):
        """
        """
        org_admin_schema = OrgAdminSchema()

        org_admin_data = request.get_json()

        validated_org_admin_data, errors =\
            org_admin_schema.load(org_admin_data)

        if errors:
            return dict(status='fail', message=errors), 400

        # Get User
        user = User.get_by_id(validated_org_admin_data.get('user_id', None))

        if not user:
            return dict(status='fail', message='User not found'), 404

        # Get organisation
        organisation = Organisation.get_by_id(organisation_id)

        if not organisation:
            return dict(status='fail', message='Organisation not found'), 404

        # removing user from organisation admins
        try:

            organisation.admins.remove(user)

        except Exception:
            return dict(status='fail',
                        message='Organisation Admin not found'), 404

        saved_org_admins = organisation.save()

        if not saved_org_admins:
            return dict(status='fail', message='Internal Server Error'), 500

        org_schema = OrganisationSchema()

        new_org_admin_data, errors = org_schema.dumps(organisation)

        return dict(
            status='success',
            data=dict(organisation_admins=json.loads(new_org_admin_data))), 200
Esempio n. 6
0
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 post(self, organisation_id):
        """
        """

        org_member_schema = OrgMemberSchema()

        org_member_data = request.get_json()

        validated_org_member_data, errors = org_member_schema.load(
            org_member_data)

        if errors:
            return dict(status='fail', message=errors), 400

        # Get User
        user = User.get_by_id(validated_org_member_data.get('user_id', None))

        if not user:
            return dict(status='fail', message='User not found'), 404

        # Get organisation
        organisation = Organisation.get_by_id(organisation_id)

        if not organisation:
            return dict(status='fail', message='Organisation not found'), 404

        if user in organisation.members:
            return dict(status='fail', message='Member already exist'), 409

        # adding user to organisation members
        organisation.members.append(user)

        saved_org_member = organisation.save()

        user_schema = UserSchema()

        if not saved_org_member:
            return dict(status='fail', message='Internal Server Error'), 500

        new_org_member_data, errors = user_schema.dumps(user)

        return dict(
            status='success',
            data=dict(
                organisation_member=json.loads(new_org_member_data))), 201
Esempio n. 8
0
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 add_organisation():
    form = NewOrganisationForm()

    if form.validate_on_submit():
        try:
            return redirect(
                url_for(
                    '.organisation_settings',
                    org_id=Organisation.create_from_form(form).id,
                ))
        except HTTPError as e:
            msg = 'Organisation name already exists'
            if e.status_code == 400 and msg in e.message:
                form.name.errors.append(
                    "This organisation name is already in use")
            else:
                raise e

    return render_template('views/organisations/add-organisation.html',
                           form=form)
Esempio n. 10
0
    def get(self, organisation_id):
        """
        """
        org_schema = OrganisationSchema(many=True)

        organisation = Organisation.get_by_id(organisation_id)

        if not organisation:
            return dict(status='fail', message='Organisation not found'), 404

        org_admins = organisation.admins

        org_admin_data, errors = org_schema.dumps(org_admins)

        if errors:
            return dict(status="fail", message="Internal Server Error"), 500

        return dict(
            status="success",
            data=dict(organisation_admins=json.loads(org_admin_data))), 200
Esempio n. 11
0
    def get(self, organisation_id):
        """
        """
        schema = NamespaceSchema(many=True)

        organisation = Organisation.get_by_id(organisation_id)

        if not organisation:
            return dict(
                status='fail',
                message=f'Organisation with id {organisation_id} not found'
            ), 404

        namespaces = Namespace.query.filter_by(organisation_id=organisation.id)

        namespace_data, errors = schema.dumps(namespaces)

        if errors:
            return dict(status='fail', message=errors), 500

        return dict(status='success',
                    data=dict(namespaces=json.loads(namespace_data))), 200
Esempio n. 12
0
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"))
Esempio n. 13
0
 def default_organisation(self):
     return Organisation(None)
Esempio n. 14
0
 def default_organisation(self):
     return Organisation.from_domain(self.email_domain)
Esempio n. 15
0
 def organisations(self):
     return [
         Organisation(organisation)
         for organisation in self.orgs_and_services['organisations']
     ]
Esempio n. 16
0
 def organisation(self):
     return Organisation.from_service(self.id)
def test_organisation_billing_details(purchase_order_number, expected_result):
    organisation = Organisation(
        organisation_json(purchase_order_number=purchase_order_number))
    assert organisation.billing_details == expected_result
Esempio n. 18
0
 def organisation(self):
     return Organisation.from_id(self.organisation_id)
Esempio n. 19
0
 def default_organisation(self):
     return Organisation(
         organisations_client.get_organisation_by_domain(self.email_domain)
     )
Esempio n. 20
0
 def organisation(self):
     return Organisation(
         organisations_client.get_service_organisation(self.id))