Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option DMOJ_PRIVATE_SUBMISSION to hide source code #1582

Merged
merged 6 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dmoj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
DMOJ_SUBMISSIONS_REJUDGE_LIMIT = 10
# Maximum number of submissions a single user can queue without the `spam_submission` permission
DMOJ_SUBMISSION_LIMIT = 2
DMOJ_PRIVATE_SUBMISSION = False
# Whether to allow users to view source code: 'all' | 'all-solved' | 'only-own'
DMOJ_SUBMISSION_SOURCE_VISIBILITY = 'all-solved'
DMOJ_BLOG_NEW_PROBLEM_COUNT = 7
DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT = 7
DMOJ_TOTP_TOLERANCE_HALF_MINUTES = 1
Expand Down
4 changes: 3 additions & 1 deletion judge/jinja2/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def submission_layout(submission, profile_id, user, completed_problem_ids, edita
can_view = True
elif submission.problem_id in completed_problem_ids:
can_view = submission.problem_id in tester_problem_ids
if not settings.DMOJ_PRIVATE_SUBMISSION:
if settings.DMOJ_SUBMISSION_SOURCE_VISIBILITY == 'all-solved':
can_view = can_view or submission.problem.is_public
elif settings.DMOJ_SUBMISSION_SOURCE_VISIBILITY == 'only-own':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this branch, since it's a no-op. On the other hand, it'd be good to have a new settings.DMOJ_SOURCE_VISIBILITY == 'all' branch at the top of this if/else tree return True.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.
I also worried about the line the most.
The purpose was to inform the existence of the branch in case somebody edits it in the future, but I know that it is two lines of unnecessary code.
Now that I wanted to match the branch order in the jinja2 and models source code, I think how about removing the 2 lines.
If you agree, I will only remove 2 unnecessary lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to remove these two lines. Your concern is totally valid but the proper solution is writing some unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.
Thank you for paying attention to the small suggestions and reviewing the code.

can_view = can_view

return can_view, can_edit
7 changes: 6 additions & 1 deletion judge/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ def can_see_detail(self, user):
return True
elif self.user_id == profile.id:
return True
elif (not settings.DMOJ_PRIVATE_SUBMISSION) and \
elif settings.DMOJ_SUBMISSION_SOURCE_VISIBILITY == 'all':
return True
elif settings.DMOJ_SUBMISSION_SOURCE_VISIBILITY == 'all-solved' and \
(self.problem.is_public or self.problem.testers.filter(id=profile.id).exists()) and \
self.problem.submission_set.filter(user_id=profile.id, result='AC',
points=self.problem.points).exists():
return True
elif settings.DMOJ_SUBMISSION_SOURCE_VISIBILITY == 'only-own' and \
self.problem.testers.filter(id=profile.id).exists():
return True
return False

def update_contest(self):
Expand Down