Skip to content

Commit 62cc145

Browse files
committed
ADD delete repo button to admin panel
1 parent 1ba4fd4 commit 62cc145

File tree

3 files changed

+263
-121
lines changed

3 files changed

+263
-121
lines changed

api/anubis/views/admin/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def register_admin_views(app):
1515
from anubis.views.admin.visuals import visuals_
1616
from anubis.views.admin.reserve import reserve_
1717
from anubis.views.admin.submissions import submissions_
18+
from anubis.views.admin.repo import repos_
1819

1920
views = [
2021
ide,
@@ -33,6 +34,7 @@ def register_admin_views(app):
3334
lectures_,
3435
reserve_,
3536
submissions_,
37+
repos_,
3638
]
3739

3840
for view in views:

api/anubis/views/admin/repo.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from flask import Blueprint
2+
3+
from flask import Blueprint
4+
5+
from anubis.github.repos import delete_assignment_repo
6+
from anubis.lms.assignments import get_assignment_data
7+
from anubis.lms.courses import assert_course_context
8+
from anubis.lms.repos import get_repos
9+
from anubis.models import Assignment, AssignmentRepo, User
10+
from anubis.utils.auth.http import require_user
11+
from anubis.utils.cache import cache
12+
from anubis.utils.http import req_assert, success_response
13+
from anubis.utils.http.decorators import json_response
14+
15+
repos_ = Blueprint("admin-repos", __name__, url_prefix="/admin/repos")
16+
17+
18+
@repos_.delete("/delete/<string:repo_id>")
19+
@require_user()
20+
@json_response
21+
def admin_repos_delete(repo_id: str):
22+
"""
23+
Get all unique repos for a user
24+
25+
:return:
26+
"""
27+
28+
# Get the repo from db
29+
repo: AssignmentRepo = AssignmentRepo.query.filter(
30+
AssignmentRepo.id == repo_id,
31+
).first()
32+
33+
# Make sure the repo exists
34+
req_assert(repo is not None, message="Repo does not exist")
35+
36+
# Verify this admin is allowed to touch this repo
37+
assert_course_context(repo)
38+
39+
# Get student and assignment
40+
student: User = User.query.filter(User.id == repo.owner_id).first()
41+
assignment: Assignment = Assignment.query.filter(Assignment.id == repo.assignment_id).first()
42+
43+
# Verify they exist
44+
req_assert(student is not None, message="User does not exist")
45+
req_assert(assignment is not None, message="Assignment does not exist")
46+
47+
# Verify that the current course context, and the assignment course match
48+
assert_course_context(assignment)
49+
assert_course_context(student)
50+
51+
52+
# If the repo is shared, then student can not delete
53+
req_assert(not repo.shared, message="Repo is shared. Please reach out to Anubis support to delete/reset this repo.")
54+
55+
# Delete the repo
56+
delete_assignment_repo(student, assignment)
57+
58+
# Delete cache entry
59+
cache.delete_memoized(get_repos, student.id)
60+
61+
# Clear cache entry
62+
cache.delete_memoized(get_assignment_data, student.id, repo.assignment_id)
63+
64+
# Pass them back
65+
return success_response({"status": "Github Repo & Submissions deleted"})

0 commit comments

Comments
 (0)