Beispiel #1
0
def password(username, password):
    "Set the password for a user account."
    with anubis.app.app.app_context():
        utils.set_db()
        user = anubis.user.get_user(username)
        if user:
            with anubis.user.UserSaver(user) as saver:
                saver.set_password(password)
        else:
            raise click.ClickException("No such user.")
Beispiel #2
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.")
Beispiel #3
0
def counts():
    "Output counts of entities in the system."
    with anubis.app.app.app_context():
        utils.set_db()
        click.echo(f"{utils.get_count('calls', 'owner'):>5} calls")
        click.echo(f"{utils.get_count('proposals', 'user'):>5} proposals")
        click.echo(f"{utils.get_count('reviews', 'call'):>5} reviews")
        click.echo(
            f"{utils.get_count('reviews', 'proposal_archived'):>5} archived reviews"
        )
        click.echo(f"{utils.get_count('grants', 'call'):>5} grants")
        click.echo(f"{utils.get_count('users', 'username'):>5} users")
Beispiel #4
0
def dump(dumpfile, dumpdir, progressbar):
    "Dump all data in the database to a .tar.gz dump file."
    with anubis.app.app.app_context():
        utils.set_db()
        if not dumpfile:
            dumpfile = "dump_{0}.tar.gz".format(time.strftime("%Y-%m-%d"))
            if dumpdir:
                filepath = os.path.join(dumpdir, dumpfile)
        ndocs, nfiles = flask.g.db.dump(
            dumpfile, exclude_designs=True, progressbar=progressbar
        )
        click.echo(f"Dumped {ndocs} documents and {nfiles} files to {dumpfile}")
Beispiel #5
0
def create_user(username, email, password):
    "Create a new user account."
    with anubis.app.app.app_context():
        utils.set_db()
        try:
            with anubis.user.UserSaver() as saver:
                saver.set_username(username)
                saver.set_email(email)
                saver.set_password(password)
                saver.set_role(constants.USER)
                saver.set_status(constants.ENABLED)
        except ValueError as error:
            raise click.ClickException(str(error))
Beispiel #6
0
def user(username):
    "Show the JSON for the user given by username or email."
    with anubis.app.app.app_context():
        utils.set_db()
        for item in [
            anubis.user.get_user(username=username),
            anubis.user.get_user(email=username),
        ]:
            if item:
                click.echo(json.dumps(item, indent=2))
                break
        else:
            raise click.ClickException("No such user.")
Beispiel #7
0
def show(identifier):
    "Show the JSON for the item given by the identifier."
    with anubis.app.app.app_context():
        utils.set_db()
        for item in [
            anubis.call.get_call(identifier),
            anubis.proposal.get_proposal(identifier),
            anubis.grant.get_grant(identifier),
            anubis.user.get_user(username=identifier),
            anubis.user.get_user(email=identifier),
            flask.g.db.get(identifier),
        ]:
            if item:
                click.echo(json.dumps(item, indent=2))
                break
        else:
            raise click.ClickException("No such item.")
Beispiel #8
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)
Beispiel #9
0
def initialize():
    "Initialization before handling first request."
    utils.set_db()
    anubis.user.create_first_admin()