Example #1
0
def display(username):
    "Display the given user."
    user = get_user(username=username)
    if user is None:
        return utils.error("No such user.", flask.url_for("home"))
    if not allow_view(user):
        return utils.error("Access to user display not allowed.")
    reviewer_calls = [
        anubis.call.get_call(r.value) for r in flask.g.db.view(
            "calls", "reviewer", key=user["username"], reduce=False)
    ]
    user_proposals_count = utils.get_count(
        "proposals", "user", user["username"]) + utils.get_count(
            "proposals", "access", user["username"])
    return flask.render_template(
        "user/display.html",
        user=user,
        reviewer_calls=reviewer_calls,
        allow_create_call=anubis.call.allow_create(user),
        user_calls_count=utils.get_count("calls", "owner", user["username"]),
        user_proposals_count=user_proposals_count,
        user_reviews_count=utils.get_count("reviews", "reviewer",
                                           user["username"]),
        user_grants_count=utils.get_user_grants_count(user["username"]),
        allow_enable_disable=allow_enable_disable(user),
        allow_edit=allow_edit(user),
        allow_delete=allow_delete(user),
        gdpr=utils.get_site_text("gdpr.md"),
    )
Example #2
0
def allow_delete(user):
    """Can the the given user account be deleted?
    Only when user is not admin, and has no proposals and no reviews,
    and is not reviewer in any call.
    Note that the user herself may be able to delete the account.
    """
    if user["role"] == constants.ADMIN:
        return False
    if utils.get_count("proposals", "user", user["username"]):
        return False
    if utils.get_count("reviews", "reviewer", user["username"]):
        return False
    if utils.get_count("calls", "reviewer", user["username"]):
        return False
    return True
Example #3
0
def grant(cid):
    "Display grant field definitions for delete, and add field."
    call = get_call(cid)
    if not call:
        return utils.error("No such call.", flask.url_for("home"))
    if not allow_edit(call):
        return utils.error("You are not allowed to edit the call.")

    if utils.http_GET():
        repeat_fields = [
            f for f in call.get("grant", []) if f["type"] == constants.REPEAT
        ]
        return flask.render_template(
            "call/grant.html",
            call=call,
            repeat_fields=repeat_fields,
            reviews_count=utils.get_count("reviews", "call", call["identifier"]),
        )

    elif utils.http_POST():
        try:
            with CallSaver(call) as saver:
                saver.add_grant_field(flask.request.form)
        except ValueError as error:
            utils.flash_error(error)
        return flask.redirect(flask.url_for(".grant", cid=call["identifier"]))
Example #4
0
def display(gid):
    "Display the grant dossier."
    grant = get_grant(gid)
    if grant is None:
        return utils.error("No such grant dossier.")
    if not allow_view(grant):
        return utils.error("You are not allowed to view this grant dossier.")
    receiver_email = anubis.user.get_user(username=grant["user"])["email"]
    access_emails = []
    for username in grant.get("access_view", []):
        user = anubis.user.get_user(username=username)
        if user:
            access_emails.append(user["email"])
    # There may be accounts that have no email!
    access_emails = [e for e in access_emails if e]
    all_emails = [receiver_email] + access_emails
    email_lists = {
        "Grant receiver (= proposal submitter)": receiver_email,
        "Persons with access to this grant": ", ".join(access_emails),
        "All involved persons": ", ".join(all_emails),
    }
    return flask.render_template(
        "grant/display.html",
        grant=grant,
        proposal=anubis.proposal.get_proposal(grant["proposal"]),
        call=anubis.call.get_call(grant["call"]),
        call_grants_count=utils.get_count("grants", "call", gid),
        email_lists=email_lists,
        allow_view=allow_view(grant),
        allow_edit=allow_edit(grant),
        allow_change_access=allow_change_access(grant),
        allow_lock=allow_lock(grant),
        allow_delete=allow_delete(grant),
    )
Example #5
0
def allow_identifier_edit(call):
    """Is the identifier of the call editable?
    Only if no dependent objects have been created, and it has not been opened.
    """
    if not call.get("identifier"):
        return True
    if utils.get_count("proposals", "call", call["identifier"]):
        return False
    if utils.get_count("reviews", "call", call["identifier"]):
        return False
    if utils.get_count("decisions", "call", call["identifier"]):
        return False
    if utils.get_count("grants", "call", call["identifier"]):
        return False
    if call["tmp"]["is_open"]:
        return False
    return True
Example #6
0
def prepare():
    "Set the database connection, get the current user."
    utils.set_db()
    flask.g.current_user = anubis.user.get_current_user()
    flask.g.am_admin = anubis.user.am_admin()
    flask.g.am_staff = anubis.user.am_staff()
    if flask.g.current_user:
        username = flask.g.current_user["username"]
        flask.g.allow_create_call = anubis.call.allow_create()
        flask.g.my_proposals_count = utils.get_count("proposals", "user",
                                                     username)
        flask.g.my_unsubmitted_proposals_count = utils.get_count(
            "proposals", "unsubmitted", username)
        flask.g.my_reviews_count = utils.get_count("reviews", "reviewer",
                                                   username)
        flask.g.my_unfinalized_reviews_count = utils.get_count(
            "reviews", "unfinalized", username)
        flask.g.my_grants_count = utils.get_user_grants_count(username)
        flask.g.my_incomplete_grants_count = utils.get_count(
            "grants", "incomplete", username)
Example #7
0
def undump(dumpfile, progressbar):
    "Load an Anubis database dump file. The database must be empty."
    with anubis.app.app.app_context():
        utils.set_db()
        if utils.get_count("users", "username") != 0:
            raise click.ClickException(
                f"The database '{anubis.app.app.config['COUCHDB_DBNAME']}'"
                " is not empty."
            )
        ndocs, nfiles = flask.g.db.undump(dumpfile, progressbar=progressbar)
        click.echo(f"Loaded {ndocs} documents and {nfiles} files.")