Example #1
0
    def as_dict(self):
        """Return the internal Org model as a dictionary.

        None fields are not included.
        """
        org_schema = OrgSchema()
        obj = org_schema.dump(self._model, many=False)
        return obj
Example #2
0
    def get():
        """Get a list of orgs that the current user is associated with."""
        token = g.jwt_oidc_token_info

        try:
            user = UserService.find_by_jwt_token(token)
            if not user:
                response, status = {'message': 'User not found.'}, http_status.HTTP_404_NOT_FOUND
            else:
                all_orgs = OrgService.get_orgs(user.identifier)
                orgs = OrgSchema().dump(
                    all_orgs, many=True)
                response, status = jsonify({'orgs': orgs}), http_status.HTTP_200_OK

        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
        return response, status
Example #3
0
    def get():
        """Get a list of orgs that the current user is associated with."""
        token = g.jwt_oidc_token_info

        try:
            user = UserService.find_by_jwt_token(token)
            if not user:
                response, status = {'message': 'User not found.'}, http_status.HTTP_404_NOT_FOUND
            else:
                # response, status = jsonify(user.get_orgs()), http_status.HTTP_200_OK
                all_orgs = OrgService.get_orgs(user.identifier)
                exclude_fields = []
                # only approved users should see entities..
                # TODO when endpoints are separated into afilliations endpoint, this logic can be removed
                if all_orgs:
                    if all_orgs[0].members and all_orgs[0].members[0].status != Status.ACTIVE.value:
                        exclude_fields.append('affiliated_entities')
                orgs = OrgSchema(exclude=exclude_fields).dump(
                    all_orgs, many=True)
                response, status = jsonify({'orgs': orgs}), http_status.HTTP_200_OK

        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
        return response, status