def lookup_org_name():
        """
        Lookup organisation in Brreg by name.

        :param name: Organisation name
        :statuscode 401: Unauthorized
        """
        if not verify_auth_token(request.cookies.get('auth_token')):
            abort(401)
        if not brreg_client:
            abort(404)
        name = request.args['name']
        response = brreg_client.get_brreg_enhet_name_search(name)
        search_result = response.get('result', [])
        for org in search_result:
            org_number = org.get('Orgnr', None)
            try:
                flod_org = current_app.db_session.query(Organisation).filter(
                    Organisation.org_number == org_number
                ).one()
                org['id'] = flod_org.id

                org['is_registered'] = not flod_org.is_deleted
            except NoResultFound:
                org['is_registered'] = False

        marshalled = marshal(search_result, brreg_name_search_fields)
        return Response(json.dumps(marshalled), mimetype='application/json')
 def validate(self, f, *args, **kwargs):
     auth_token = request.cookies.get('auth_token', None)
     valid = auth_token is not None \
         and verify_auth_token(auth_token)
     if not valid:
         self.fail("User not authenticated with cookie.",
                   f, 401, None, *args, **kwargs)
    def lookup_brreg_contact():
        """
        Lookup contact information in Brreg.

        :param orgnr: Organisation number
        :statuscode 401: Unauthorized
        """
        if not verify_auth_token(request.cookies.get('auth_token')):
            abort(401)
        if not brreg_client:
            abort(404)
        org_number = request.args['orgnr']
        response = brreg_client.get_brreg_enhet_contact_data(org_number)
        return Response(json.dumps(response), mimetype='application/json')
    def lookup_basic_brreg_data():
        """
        Lookup unit information in Brreg.

        :param orgnr: Organisation number
        :statuscode 401: Unauthorized
        """
        if not verify_auth_token(request.cookies.get('auth_token')):
            abort(401)
        if not brreg_client:
            abort(404)
        org_number = request.args['orgnr']
        try:
            response = brreg_client.get_brreg_enhet_basis_data_full(org_number)
        except OrgNrNotFoundException, e:
            return Response(
                json.dumps({"__error__": [e.message]}),
                mimetype='application/json',
                status=404
            )
 def validate(self, f, *args, **kwargs):
     auth_token = request.cookies.get("auth_token", None)
     valid = auth_token is not None and verify_auth_token(auth_token) and verify_superuser_auth_token(auth_token)
     if not valid:
         self.fail("User is not authorized to request the resource.", f, 403, None, *args, **kwargs)