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

Added option DMOJ_PRIVATE_SUBMISSION to hide source code #1582

merged 6 commits into from
Feb 22, 2021

Conversation

munhyunsu
Copy link
Contributor

I am using DMOJ as a university teaching tutor.
I want to prevent the students I teach from simply copy-pasting more efficient source code while looking at the answers other students have solved.

This Pull Request provides a private submission function as mentioned in #836.

Use the DMOJ_PRIVATE_SUBMISSION flag in settings.py or local_setting.py.
If DMOJ_PRIVATE_SUBMISSION = True, only the source code submitted by the user can be checked in /submissions.

@codecov-io
Copy link

codecov-io commented Jan 11, 2021

Codecov Report

Merging #1582 (ccd9601) into master (707c015) will decrease coverage by 0.00%.
The diff coverage is 20.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1582      +/-   ##
==========================================
- Coverage   46.05%   46.04%   -0.01%     
==========================================
  Files         213      213              
  Lines       12145    12149       +4     
==========================================
+ Hits         5593     5594       +1     
- Misses       6552     6555       +3     
Impacted Files Coverage Δ
judge/jinja2/submission.py 11.76% <0.00%> (-1.57%) ⬇️
judge/views/submission.py 32.58% <0.00%> (-0.09%) ⬇️
dmoj/settings.py 97.64% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 707c015...ccd9601. Read the comment docs.

Copy link
Contributor

@fluix-dev fluix-dev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Considering this was rejected prior, I'm not sure it will be accepted this time, but the code around permissions has certainly cleaned up a bit so I think it's alright. See comment.

What you've done only affects template rendering, not actual access to the submission page. For example, going to the submission URL or through the API, the submission can still be accessed. You should modify the can_see_detail function of the Submission model and write some unit tests to verify it works here.

@@ -15,6 +16,8 @@ def submission_layout(submission, profile_id, user, completed_problem_ids, edita
elif profile_id == submission.user_id:
can_view = True
elif submission.problem_id in completed_problem_ids:
can_view = submission.problem.is_public or submission.problem_id in tester_problem_ids
can_view = submission.problem_id in tester_problem_ids
if not private_submission:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing the settings.DMOJ_PRIVATE_SUBMISSION into the context and then re-checking, you should check it here directly instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the reply.
I did it directly.

@fluix-dev
Copy link
Contributor

@Xyene says he's okay with merging, assuming this work.

@fluix-dev
Copy link
Contributor

Totally forgot to mention this, can you change the name of this new setting and make it a string to allow for future changes. From Slack, a while back:

xyene: actually
xyene: I'd like to see this be a string
xyene: DMOJ_SUBMISSION_SOURCE_VISIBILITY = 'all' | 'all-solved' | 'only-own'
xyene: I don't expect them to implement the others
xyene: but keep it a string because I'm sure someone will want it
xyene: and having two bool fields is dumb

Pretty much, set the current one in settings.py to DMOJ_SUBMISSION_SOURCE_VISIBILITY = 'all' and then check it's value for the new changes. Don't worry about 'all-solved' for now and let me know if you need any help.

…type: str) which can be "all" | "all-solved" | "only-own"
@munhyunsu
Copy link
Contributor Author

I Understand that it would be useful to more users to provide three options.
Revisions were made according to #1582 (comment)
Thank you for not forgetting to reply.

Copy link
Member

@Xyene Xyene left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to implement the other options :)

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.

Copy link
Contributor

@fluix-dev fluix-dev left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for working on this!

Copy link
Member

@Xyene Xyene left a comment

Choose a reason for hiding this comment

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

Thanks!

@Xyene Xyene merged commit 7d01160 into DMOJ:master Feb 22, 2021
leduythuccs added a commit to VNOI-Admin/OJ that referenced this pull request May 11, 2021
* Add option DMOJ_PRIVATE_SUBMISSION to hide source code; closes DMOJ/online-judge#836 (DMOJ/online-judge#1582)

* Fix impossible to translate strings

* Import latest Can I use... data

* Add minor improvements to user data downloads

* Use a subquery for problem filter and force a STRAIGHT_JOIN for subs

* Reduce time complexity for chain of * in problem filter

* Update English source .po files in updatemessages

* Add problem visibility to APIProblemList

* Make caniuse PR use reviewers instead of assignees

* Pretty format caniuse.json

This is so that diffs actually make sense.

* Make translations PR use reviewers instead of assignees

* Add comment for non-trivial submission saving logic

* Ignore Vim's backups

* Fix permissions on `0110_default_output_prefix_override` migration

* Add contest curator and tester fields

* Add migration for contest curator and tester

* Add contest curator and tester to admin site

* Add contest curator and tester to views

* Add contest curator and tester to frontend

* Add tests for contest curators and testers

* Add `is_locked` to `submission_related`

* Compute user_tester_ids without an inner join

* Allow contest curators and authors to see submissions made in contest (DMOJ/online-judge#1672)

To whomever implements DMOJ/online-judge#1509, I pity your soul.

* Fix missing `distinct()`

* Set submission contest object to None on contest submission delete

* Remove unneeded `profile.update_contest()` call in `ProblemSubmit`

* Fix `SubmissionMixin` `access_check()` method

There's no testing quite like testing in prod.

* Remove unused PrivateMessage model

* Create initial revision on contest/problem clone

* Convert contest and submission `is_locked` to `DateTimeField`s

* Convert submission `was_rejudged` to a `DateTimeField`

* Add migration to convert to datetimes

* Refactor atomic revisions

Use `revision.create_revision(atomic=True)` instead of explicity
wrapping with ``transaction.atomic`

* Consistently cache global submission stats

Instead of using the problems visible to whatever user populating
the cache, we simply cache stats all submissions on the site.

* Fix attempt to fetch all submissions

* Allow unlisted users to see contest rank; fixes DMOJ/online-judge#1607

* Fixing some error when update from dmoj (#66)

* Fix lint

* Add merged migartion

* Make sure user can see their submissions in contest

Co-authored-by: Hyun-Su, Mun <munhyunsu@gmail.com>
Co-authored-by: Quantum <quantum2048@gmail.com>
Co-authored-by: dmoj-build <build@dmoj.ca>
Co-authored-by: Evan <evanzhang1028@hotmail.com>
Co-authored-by: JoshuaTianYangLiu <josh.liu@student.tdsb.on.ca>
Co-authored-by: Roger Fu <kiritofeng@users.noreply.github.com>
Co-authored-by: kiritofeng <rogerjfu@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants