Skip to content

Commit

Permalink
Adding new API features for better exercise management (archiving, ex…
Browse files Browse the repository at this point in the history
…ercise admins, ref. solutions visibility).
  • Loading branch information
krulis-martin committed Aug 19, 2023
1 parent 0f6a758 commit 93a1db5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
14 changes: 14 additions & 0 deletions recodex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,23 @@ def set_exercise_score_config(self, exercise_id, score_config: str):
def update_exercise(self, exercise_id, details):
self.post('/exercises/{}'.format(exercise_id), data=details)

def set_exercise_archived(self, exercise_id, archived):
self.post('/exercises/{}/archived'.format(exercise_id), data={"archived": archived})

def set_exercise_author(self, exercise_id, author):
self.post('/exercises/{}/author'.format(exercise_id), data={"author": author})

def set_exercise_admins(self, exercise_id, admins_ids):
self.post('/exercises/{}/admins'.format(exercise_id), data={"admins": admins_ids})

def delete_exercise(self, exercise_id):
self.delete('/exercises/{}'.format(exercise_id))

def update_reference_solution_visibility(self, solution_id, visibility):
self.post('/reference-solutions/{}/visibility'.format(solution_id), data={
"visibility": visibility
})

def delete_reference_solution_evaluation(self, evaluation_id):
self.delete('/reference-solutions/evaluation/{}'.format(evaluation_id))

Expand Down
44 changes: 44 additions & 0 deletions recodex/plugins/exercises/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,39 @@ def set_config(api: ApiClient, exercise_id, file_name, useJson):
api.update_exercise_config(exercise_id, config)


@cli.command()
@click.argument("exercise_id")
@click.option("--excavate/--archive", "excavate", default=False)
@pass_api_client
def set_archived(api: ApiClient, exercise_id, excavate):
"""
Set the archived flag of an exercise (put it into archived mode or excavate from archive).
"""
api.set_exercise_archived(exercise_id, not excavate)


@cli.command()
@click.argument("exercise_id")
@click.argument("author")
@pass_api_client
def set_author(api: ApiClient, exercise_id, author):
"""
Change the author of the exercise.
"""
api.set_exercise_author(exercise_id, author)


@cli.command()
@click.argument("exercise_id")
@click.option('--admin', '-a', multiple=True)
@pass_api_client
def set_admins(api: ApiClient, exercise_id, admin):
"""
Set exercise admins (replaces current list of admins).
"""
api.set_exercise_admins(exercise_id, admin)


@cli.command()
@click.option('--stats', is_flag=True)
@pass_api_client
Expand Down Expand Up @@ -321,3 +354,14 @@ def tags_remove_global(api: ApiClient, tag):
"""
res = api.exercise_tags_remove_global(tag)
click.echo("{} exercise(s) affected".format(res["count"]))


@cli.command()
@click.argument("ref_solution_id")
@click.argument("visibility")
@pass_api_client
def set_ref_solution_visibility(api: ApiClient, ref_solution_id, visibility):
"""
Change visibility of a reference solution.
"""
api.update_reference_solution_visibility(ref_solution_id, int(visibility))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='recodex-cli',
version='0.0.19',
version='0.0.20',
description='ReCodEx CLI',
long_description='A command line frontend to the ReCodEx programmer evaluation system',
classifiers=[
Expand Down

0 comments on commit 93a1db5

Please sign in to comment.