Exemplo n.º 1
0
def create_proposals(count, category, stage, with_comments=False):
    user = User.query.filter_by().first()
    for i in range(count):
        target = "123.456"
        p = Proposal.create(
            stage=stage,
            status=ProposalStatus.LIVE,
            title=f'Fake Proposal #{i} {category} {stage}',
            content=f'My fake proposal content, numero {i}',
            brief=f'This is proposal {i} generated by e2e testing',
            category=category,
            target=target,
            payout_address="fake123",
            deadline_duration=100)
        p.date_published = datetime.now()
        p.team.append(user)
        db.session.add(p)
        db.session.flush()
        num_ms = randint(1, 9)
        for j in range(num_ms):
            m = Milestone(
                title=f'Fake MS {j}',
                content=
                f'Fake milestone #{j} on fake proposal #{i} {category} {stage}!',
                date_estimated=datetime.now(),
                payout_amount=str(float(target) / num_ms),
                immediate_payout=j == 0,
                proposal_id=p.id,
                index=j)
            db.session.add(m)
        # limit comment creation as it is slow
        if i == 0 and with_comments:
            for j in range(31):
                c = Comment(
                    proposal_id=p.id,
                    user_id=user.id,
                    parent_comment_id=None,
                    content=
                    f'Fake comment #{j} on fake proposal #{i} {category} {stage}!'
                )
                db.session.add(c)
        if stage == ProposalStage.FUNDING_REQUIRED:
            stake = p.create_contribution('1', None, True)
            stake.confirm('fakestaketxid', '1')
            db.session.add(stake)
            db.session.flush()
            fund = p.create_contribution('100', None, False)
            fund.confirm('fakefundtxid0', '100')
            db.session.add(fund)
            db.session.flush()
            p.status = ProposalStatus.LIVE
            db.session.add(p)
            db.session.flush()
Exemplo n.º 2
0
def post_proposal_comments(proposal_id, user_id, content):
    proposal = Proposal.query.filter_by(id=proposal_id).first()
    if proposal:
        comment = Comment(
            proposal_id=proposal_id,
            user_id=g.current_user.id,
            content=content
        )
        db.session.add(comment)
        db.session.commit()
        dumped_comment = comment_schema.dump(comment)
        return dumped_comment, 201
    else:
        return {"message": "No proposal matching id"}, 404
Exemplo n.º 3
0
def create_proposals(count):
    user = User.query.filter_by().first()
    for i in range(count):
        if i < 5:
            stage = ProposalStage.WIP
        else:
            stage = ProposalStage.COMPLETED
        p = Proposal.create(
            stage=stage,
            status=ProposalStatus.LIVE,
            title=f'Fake Proposal #{i}',
            content=f'My fake proposal content, numero {i}',
            brief=f'This is proposal {i} generated by "flask create-proposals"',
            category=Category.ACCESSIBILITY,
            target="123.456",
            payout_address="fake123",
            deadline_duration=100)
        p.date_published = datetime.datetime.now()
        p.team.append(user)
        p.date_approved = datetime.datetime.now()
        p.accepted_with_funding = True
        p.version = '2'
        p.fully_fund_contibution_bounty()
        db.session.add(p)
        db.session.flush()
        num_ms = randint(1, 9)
        for j in range(num_ms):
            m = Milestone(
                title=f'Fake MS {j}',
                content=f'Fake milestone #{j} on fake proposal #{i}!',
                days_estimated='10',
                payout_percent=str(floor(1 / num_ms * 100)),
                immediate_payout=j == 0,
                proposal_id=p.id,
                index=j)
            db.session.add(m)
        for j in range(100):
            c = Comment(proposal_id=p.id,
                        user_id=user.id,
                        parent_comment_id=None,
                        content=f'Fake comment #{j} on fake proposal #{i}!')
            db.session.add(c)

        Milestone.set_v2_date_estimates(p)
        db.session.add(p)

    db.session.commit()
    print(f'Added {count} LIVE fake proposals')
Exemplo n.º 4
0
def create_proposals(count):
    user = User.query.filter_by().first()
    for i in range(count):
        if i < 5:
            stage = ProposalStageEnum.WIP
        else:
            stage = ProposalStageEnum.COMPLETED
        target = str(randint(1, 10))
        p = Proposal.create(
            stage=stage,
            status=ProposalStatus.LIVE,
            title=f'Fake Proposal #{i}',
            content=f'My fake proposal content, numero {i}',
            brief=
            f'This is proposal {i} generated by "flask create-proposals", a useful tool for generating test proposal data.',
            category=Category.random(),
            target=target,
        )
        p.date_published = datetime.datetime.now()
        p.team.append(user)
        db.session.add(p)
        db.session.flush()

        num_ms = randint(1, 9)
        for j in range(num_ms):
            m = Milestone(
                title=f'Fake MS {j}',
                content=f'Fake milestone #{j} on fake proposal #{i}!',
                date_estimated=datetime.datetime.now(),
                payout_amount=str(float(target) / num_ms),
                immediate_payout=j == 0,
                proposal_id=p.id,
                index=j)
            db.session.add(m)
        for j in range(100):
            c = Comment(proposal_id=p.id,
                        user_id=user.id,
                        parent_comment_id=None,
                        content=f'Fake comment #{j} on fake proposal #{i}!')
            db.session.add(c)

    db.session.commit()
    print(f'Added {count} LIVE fake proposals')
Exemplo n.º 5
0
def post_proposal_comments(proposal_id, comment, parent_comment_id):
    # Make sure proposal exists
    proposal = Proposal.query.filter_by(id=proposal_id).first()
    if not proposal:
        return {"message": "No proposal matching id"}, 404

    if proposal.status != ProposalStatus.LIVE and proposal.status != ProposalStatus.DISCUSSION:
        return {
            "message":
            "Proposal must be live or open for public review to comment"
        }, 400

    # Make sure the parent comment exists
    parent = None
    if parent_comment_id:
        parent = Comment.query.filter_by(id=parent_comment_id).first()
        if not parent:
            return {"message": "Parent comment doesn’t exist"}, 400

    # Make sure user has verified their email
    if not g.current_user.email_verification.has_verified:
        return {"message": "Please confirm your email before commenting"}, 401

    # Make sure user is not silenced
    if g.current_user.silenced:
        return {
            "message":
            "Your account has been silenced, commenting is disabled."
        }, 403

    # Make the comment
    comment = Comment(proposal_id=proposal_id,
                      user_id=g.current_user.id,
                      parent_comment_id=parent_comment_id,
                      content=comment)
    db.session.add(comment)
    db.session.commit()
    dumped_comment = comment_schema.dump(comment)

    # Email proposal team if top-level comment
    if not parent:
        for member in proposal.team:
            send_email(
                member.email_address, 'proposal_comment', {
                    'author':
                    g.current_user,
                    'proposal':
                    proposal,
                    'comment_url':
                    make_url(
                        f'/proposals/{proposal.id}?tab=discussions&comment={comment.id}'
                    ),
                    'author_url':
                    make_url(f'/profile/{comment.author.id}'),
                })
    # Email parent comment creator, if it's not themselves
    if parent and parent.author.id != comment.author.id:
        send_email(
            parent.author.email_address, 'comment_reply', {
                'author':
                g.current_user,
                'proposal':
                proposal,
                'comment_url':
                make_url(
                    f'/proposals/{proposal.id}?tab=discussions&comment={comment.id}'
                ),
                'author_url':
                make_url(f'/profile/{comment.author.id}'),
            })

    return dumped_comment, 201