def as_dict(self): """Return the Membership as a python dict. None fields are not included in the dict. """ membership_schema = MembershipSchema() obj = membership_schema.dump(self._model, many=False) return obj
def get(org_id): """Retrieve the set of members for the given org.""" try: status = request.args.get('status').upper() if request.args.get( 'status') else None roles = request.args.get('roles').upper() if request.args.get( 'roles') else None members = MembershipService.get_members_for_org( org_id, status=status, membership_roles=roles, token_info=g.jwt_oidc_token_info) if members: response, status = {'members': MembershipSchema(exclude=['org']).dump(members, many=True)}, \ http_status.HTTP_200_OK else: response, status = {}, \ http_status.HTTP_200_OK except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status
def get(org_id): """Get the membership for the given org and user.""" 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: membership = MembershipService \ .get_membership_for_org_and_user_all_status(org_id=org_id, user_id=user.identifier) response, status = MembershipSchema(exclude=['org']).dump(membership), http_status.HTTP_200_OK except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code return response, status