def get_user(user_id, with_proposals, with_comments, with_pending, with_work): user = User.get_by_id(user_id) if user: result = user_schema.dump(user) authed_user = auth.get_authed_user() is_self = authed_user and authed_user.id == user.id if with_proposals: proposals = Proposal.get_by_user(user) proposals_dump = user_proposals_schema.dump(proposals) result["proposals"] = proposals_dump if with_comments: comments = Comment.get_by_user(user) comments_dump = user_comments_schema.dump(comments) result["comments"] = comments_dump if with_pending and is_self: pending = Proposal.get_by_user(user, [ ProposalStatus.PENDING, ProposalStatus.APPROVED, ProposalStatus.REJECTED, ]) pending_dump = user_proposals_schema.dump(pending) result["pendingProposals"] = pending_dump if with_work: result["work"] = rfw_models.RFWWorker.get_work(user.id, is_self) return result else: message = "User with id matching {} not found".format(user_id) return {"message": message}, 404
def get_user(user_id, with_proposals, with_comments, with_funded, with_pending, with_arbitrated, with_requests, with_rejected_permanently): user = User.get_by_id(user_id) if user: result = user_schema.dump(user) authed_user = auth.get_authed_user() is_self = authed_user and authed_user.id == user.id if with_requests: requests = CCR.get_by_user(user) requests_dump = ccrs_schema.dump(requests) result["requests"] = requests_dump if with_proposals: proposals = Proposal.get_by_user(user) proposals_dump = user_proposals_schema.dump(proposals) result["proposals"] = proposals_dump if with_funded: contributions = ProposalContribution.get_by_userid(user_id) if not authed_user or user.id != authed_user.id: contributions = [ c for c in contributions if c.status == ContributionStatus.CONFIRMED ] contributions = [c for c in contributions if not c.private] contributions = [ c for c in contributions if c.proposal.status == ProposalStatus.LIVE ] contributions_dump = user_proposal_contributions_schema.dump( contributions) result["contributions"] = contributions_dump if with_comments: comments = Comment.get_by_user(user) comments_dump = user_comments_schema.dump(comments) result["comments"] = comments_dump if with_pending and is_self: pending_proposals = Proposal.get_by_user(user, [ ProposalStatus.STAKING, ProposalStatus.PENDING, ProposalStatus.APPROVED, ProposalStatus.REJECTED, ]) pending_proposals_dump = user_proposals_schema.dump( pending_proposals) result["pendingProposals"] = pending_proposals_dump pending_ccrs = CCR.get_by_user(user, [ CCRStatus.PENDING, CCRStatus.APPROVED, CCRStatus.REJECTED, ]) pending_ccrs_dump = ccrs_schema.dump(pending_ccrs) result["pendingRequests"] = pending_ccrs_dump if with_arbitrated and is_self: result["arbitrated"] = user_proposal_arbiters_schema.dump( user.arbiter_proposals) if with_rejected_permanently and is_self: rejected_proposals = Proposal.get_by_user( user, [ProposalStatus.REJECTED_PERMANENTLY]) result[ "rejectedPermanentlyProposals"] = user_proposals_schema.dump( rejected_proposals) rejected_ccrs = CCR.get_by_user(user, [ CCRStatus.REJECTED_PERMANENTLY, ]) result["rejectedPermanentlyRequests"] = ccrs_schema.dump( rejected_ccrs) return result else: message = "User with id matching {} not found".format(user_id) return {"message": message}, 404