示例#1
0
def delete_account():
    delete_account_form = DeleteAccountForm()
    if delete_account_form.validate_on_submit():
        github_status = get_github_token_status(current_app, current_user)
        if github_status == "valid":
            github_client = get_github_client(current_app, current_user)

            for github_repo in GithubRepo.query.filter(GithubRepo.integration == current_user.github_integration).all():
                try:
                    github_client.delete_webhook(github_repo.id, github_repo.hook_id)
                except GithubResourceMissing:
                    pass

            github_client.revoke_integration()

        trello_status = get_trello_token_status(current_app, current_user)
        if trello_status == "valid":
            trello_client = get_trello_client(current_app, current_user)
            trello_client.revoke_integration()

        db.session.delete(current_user)
        db.session.commit()
        session.clear()

        flash("Your account and all authorisations have been deleted.", "warning")
        return redirect(url_for(".start_page"))

    elif delete_account_form.errors:
        for error in delete_account_form.errors.items():
            flash(error, "warning")

    return render_template("user/delete-account.html", delete_account_form=delete_account_form)
示例#2
0
def dashboard():
    github_status = get_github_token_status(current_app, current_user)
    trello_status = get_trello_token_status(current_app, current_user)

    github_repos = (
        GithubRepo.query.filter(GithubRepo.integration == current_user.github_integration).all()
        if github_status == "valid"
        else []
    )

    product_signoffs = []
    if trello_status == "valid":
        trello_client = get_trello_client(current_app, current_user)
        trello_board_ids = [board.id for board in trello_client.get_boards()]

        product_signoffs = ProductSignoff.query.filter(
            ProductSignoff.trello_board.has(TrelloBoard.id.in_(trello_board_ids))
        ).all()

    return render_template(
        "dashboard.html",
        github_status=github_status,
        trello_status=trello_status,
        github_repos=github_repos,
        product_signoffs=product_signoffs,
    )
示例#3
0
def trello_manage_product_signoff(signoff_id):
    trello_client = get_trello_client(current_app, current_user)
    product_signoff = ProductSignoff.query.filter(ProductSignoff.id == signoff_id).one_or_none()
    if not product_signoff:
        flash("No such board")
        return redirect(url_for(".trello_product_signoff")), 404

    elif product_signoff.user != current_user:
        flash("That product signoff check is owned by another person")
        return redirect(url_for(".trello_product_signoff")), 403

    product_signoff.hydrate(trello_client)

    return render_template("features/signoff/manage-product-signoff.html", product_signoff=product_signoff)
示例#4
0
def revoke_trello():
    trello_client = get_trello_client(current_app, current_user)
    if trello_client.revoke_integration() is False:
        flash(
            "Something went wrong revoking your Trello authorisation. Please do it directly from your Trello account.",
            "error",
        )

    db.session.delete(current_user.trello_integration)
    db.session.commit()

    flash("Trello authorisation token revoked successfully.")

    return redirect(url_for(".dashboard"))
示例#5
0
def trello_product_signoff():
    trello_client = get_trello_client(current_app, current_user)
    all_trello_boards_json = trello_client.get_boards(with_lists=True, as_json=True)
    all_trello_boards_by_id = {board_json["id"]: board_json for board_json in all_trello_boards_json}

    existing_product_signoff_checks = ProductSignoff.query.filter(
        ProductSignoff.trello_board.has(TrelloBoard.id.in_(all_trello_boards_by_id.keys()))
    ).all()

    for product_signoff in existing_product_signoff_checks:
        product_signoff.hydrate_from_board_json(all_trello_boards_by_id[product_signoff.trello_board.id])

    return render_template(
        "features/signoff/product-signoff.html",
        existing_product_signoff_checks=existing_product_signoff_checks,
        can_connect_more_boards=len(all_trello_boards_json) > len(existing_product_signoff_checks),
    )
示例#6
0
def authorize_trello_complete():
    authorize_form = AuthorizeTrelloForm()

    if authorize_form.validate_on_submit():
        current_user.trello_integration = TrelloIntegration(oauth_token=authorize_form.trello_integration.data)

        trello_client = get_trello_client(current_app, current_user)
        if trello_client.is_token_valid():
            db.session.add(current_user)
            db.session.commit()

            flash("Trello authorisation successful.", "info")
            return redirect(url_for(".dashboard"))

        flash("The Trello authorisation token you have submitted is invalid. Please try again.", "warning")
        return render_template("integrate-trello.html", authorize_form=authorize_form)

    flash("Form submit failed", "error")
    return redirect(url_for(".start_page"))
示例#7
0
def trello_delete_signoff_check(signoff_id):
    delete_product_signoff_form = DeleteProductSignoffForm()

    trello_client = get_trello_client(current_app, current_user)

    product_signoff = ProductSignoff.query.filter(ProductSignoff.id == signoff_id).one_or_none()
    if not product_signoff:
        flash("No such product signoff")
        return redirect(url_for(".trello_product_signoff")), 404

    elif product_signoff.user != current_user:
        flash("That product signoff check is owned by another person")
        return redirect(url_for(".trello_product_signoff")), 403

    product_signoff.hydrate(trello_client)

    if delete_product_signoff_form.validate_on_submit():
        try:
            trello_client.delete_webhook(product_signoff.trello_list.hook_id)

        except TrelloResourceMissing:
            pass

        flash(
            f"You have deleted the product sign-off check on the ‘{product_signoff.trello_board.name}’ board.",
            "warning",
        )
        db.session.delete(product_signoff)
        db.session.commit()

        return redirect(url_for(".trello_product_signoff"))

    elif delete_product_signoff_form.errors:
        for error in delete_product_signoff_form.errors.items():
            flash(error, "warning")

    return render_template(
        "features/signoff/delete-product-signoff.html",
        delete_product_signoff_form=delete_product_signoff_form,
        product_signoff=product_signoff,
    )
示例#8
0
def trello_choose_list():
    board_id = request.args.get("board_id", None)
    if not board_id:
        flash("Please select a Trello board.")
        return redirect(".trello_choose_board")

    if ProductSignoff.query.filter(ProductSignoff.trello_board.has(TrelloBoard.id == board_id)).count():
        flash("Product sign-off checks are already enabled for that board.", "warning")
        return redirect(url_for(".trello_product_signoff"))

    trello_client = get_trello_client(current_app, current_user)
    trello_lists = trello_client.get_lists(board_id=request.args["board_id"])

    list_form = ChooseTrelloListForm(trello_lists)

    if list_form.validate_on_submit():
        list_id = list_form.list_choice.data
        try:
            trello_hook = trello_client.create_webhook(
                object_id=list_id, callback_url=url_for(".trello_callback", _external=True)
            )

        except HookAlreadyExists:
            trello_hook = trello_client.get_webhook(object_id=list_id)

        trello_board = TrelloBoard.from_json(trello_client.get_board(board_id, as_json=True))
        trello_list = TrelloList.from_json(trello_client.get_list(list_id, as_json=True))
        trello_list.hook_id = trello_hook["id"]
        product_signoff = ProductSignoff(user=current_user, trello_board=trello_board, trello_list=trello_list)
        db.session.add(product_signoff)
        db.session.commit()

        flash((f"Product sign-off checks added to the “{trello_board.name}” board."), "info")
        return redirect(url_for(".dashboard"))

    elif list_form.errors:
        for error in list_form.errors.items():
            flash(error, "warning")

    return render_template("features/signoff/select-list.html", list_form=list_form)
示例#9
0
def trello_choose_board():
    trello_client = get_trello_client(current_app, current_user)
    all_trello_boards = trello_client.get_boards(with_lists=True)
    all_trello_boards_by_id = {board.id: board for board in all_trello_boards}

    existing_product_signoff_checks = ProductSignoff.query.filter(
        ProductSignoff.trello_board.has(TrelloBoard.id.in_(all_trello_boards_by_id.keys()))
    ).all()
    existing_trello_board_ids = {product_signoff.trello_board.id for product_signoff in existing_product_signoff_checks}

    available_trello_boards = [board for board in all_trello_boards if board.id not in existing_trello_board_ids]

    board_form = ChooseTrelloBoardForm(available_trello_boards)

    if board_form.validate_on_submit():
        return redirect(url_for(".trello_choose_list", board_id=board_form.board_choice.data))

    elif board_form.errors:
        for error in board_form.errors.items():
            flash(error, "warning")

    return render_template("features/signoff/select-board.html", board_form=board_form)
示例#10
0
 def __init__(self, app, db, user):
     self.app = app
     self.db = db
     self.user = user
     self.github_client = get_github_client(app, user)
     self.trello_client = get_trello_client(app, user)
示例#11
0
def get_board_name(*args, **kwargs):
    signoff_id = request.view_args["signoff_id"]
    product_signoff = ProductSignoff.query.filter(ProductSignoff.id == signoff_id).one()
    trello_client = get_trello_client(current_app, current_user)
    board = trello_client.get_board(product_signoff.trello_board_id)
    return [{"text": board.name, "url": url_for(".trello_manage_product_signoff", signoff_id=signoff_id)}]