Skip to content

Commit de743fd

Browse files
authored
Revert "feat: Enable reuplading old versions (#229)" (#238)
This reverts commit a3f2cf9.
1 parent 5658c70 commit de743fd

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

lms/lmsdb/models.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,13 @@ def create_hash(content: Union[str, bytes], *args, **kwargs) -> str:
340340

341341
@classmethod
342342
def is_duplicate(
343-
cls, content: Union[str, bytes], user: User, exercise: Exercise,
344-
*, already_hashed: bool = False,
343+
cls, content: Union[str, bytes], user: User, *,
344+
already_hashed: bool = False,
345345
) -> bool:
346346
hash_ = cls.create_hash(content) if not already_hashed else content
347-
348-
return (
349-
cls
350-
.select()
351-
.group_by(cls.solver, cls.exercise)
352-
.having(
353-
cls.submission_timestamp == fn.MAX(cls.submission_timestamp),
354-
cls.solver == user,
355-
cls.exercise == exercise,
356-
cls.hashed == hash_,
357-
)
347+
return cls.select().where(
348+
cls.hashed == hash_,
349+
cls.solver == user,
358350
).exists()
359351

360352
def start_checking(self) -> bool:
@@ -435,10 +427,7 @@ def create_solution(
435427
if len(files) == 1:
436428
hash_ = cls.create_hash(files[0].code)
437429

438-
if (
439-
hash_
440-
and cls.is_duplicate(hash_, solver, exercise, already_hashed=True)
441-
):
430+
if hash_ and cls.is_duplicate(hash_, solver, already_hashed=True):
442431
raise AlreadyExists('This solution already exists.')
443432

444433
instance = cls.create(**{

lms/models/upload.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
from lms.utils.log import log
1313

1414

15-
def _is_uploaded_before(
16-
user: User, exercise: Exercise, file_hash: str,
17-
) -> bool:
18-
return Solution.is_duplicate(
19-
file_hash, user, exercise, already_hashed=True,
20-
)
15+
def _is_uploaded_before(user: User, file_hash: str) -> bool:
16+
return Solution.is_duplicate(file_hash, user, already_hashed=True)
2117

2218

2319
def _upload_to_db(
@@ -33,7 +29,7 @@ def _upload_to_db(
3329
raise UploadError(
3430
f'Exercise {exercise_id} is closed for new solutions.')
3531

36-
if solution_hash and _is_uploaded_before(user, exercise, solution_hash):
32+
if solution_hash and _is_uploaded_before(user, solution_hash):
3733
raise AlreadyExists('You try to reupload an old solution.')
3834
elif not files:
3935
raise UploadError(f'There are no files to upload for {exercise_id}.')
@@ -58,7 +54,6 @@ def new(user: User, file: FileStorage) -> Tuple[List[int], List[int]]:
5854
matches: List[int] = []
5955
misses: List[int] = []
6056
errors: List[Union[UploadError, AlreadyExists]] = []
61-
6257
for exercise_id, files, solution_hash in Extractor(file):
6358
try:
6459
solution = _upload_to_db(exercise_id, user, files, solution_hash)

lms/tests/test_solutions.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@ def test_new_solution_override_old_solutions(
5050
assert next_unchecked.id == second_solution.id
5151
assert next_unchecked_by_id.id == second_solution.id
5252

53-
third_solution = conftest.create_solution(
54-
exercise, student_user, code='123',
55-
)
56-
fourth_solution = conftest.create_solution(
57-
exercise, student_user, code='1234',
58-
)
59-
assert not Solution.is_duplicate(
60-
third_solution.hashed, student_user, exercise, already_hashed=True,
61-
)
62-
assert Solution.is_duplicate(
63-
fourth_solution.hashed, student_user, exercise,
64-
already_hashed=True,
65-
)
66-
6753
def test_next_exercise_with_cleanest_code(
6854
self,
6955
comment: Comment,

0 commit comments

Comments
 (0)