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

[#1885] Changed document admin to be readonly #887

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

Bartvaderkin
Copy link
Contributor

@Bartvaderkin Bartvaderkin commented Dec 11, 2023

task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1885

In the pentest you could upload here, but this is user content so no need to create/edit it through the admin.

Fields:

@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (ba38b08) 94.68% compared to head (cabff54) 94.79%.
Report is 14 commits behind head on develop.

Files Patch % Lines
src/open_inwoner/accounts/admin.py 77.77% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #887      +/-   ##
===========================================
+ Coverage    94.68%   94.79%   +0.10%     
===========================================
  Files          831      857      +26     
  Lines        29275    30085     +810     
===========================================
+ Hits         27720    28519     +799     
- Misses        1555     1566      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bartvaderkin Bartvaderkin marked this pull request as ready for review December 12, 2023 07:56
@alextreme
Copy link
Member

Note my remark: "This is to be corrected, the default document-file extensions from the Open Zaak configuration can be used as the default whitelist. This validation is to be added on a model-level, and other filefields in Open Inwoner can be checked and if necessary the same validation can be added to those filefields as well."

As Users can upload documents (via a plan) this will need validation of some kind. And the other FileFields will likely also require attention.

pi-sigma
pi-sigma previously approved these changes Dec 14, 2023
@pi-sigma pi-sigma dismissed their stale review December 14, 2023 10:38

Too quick, didn't see the comment

@stevenbal stevenbal self-assigned this Jan 16, 2024
@stevenbal
Copy link
Contributor

@alextreme in the PR description I made a list of the file fields that I could find.

  • The FilerFileField actually already has validation that blocks you from uploading .svg, .html or other files that can allow XSS.
  • document.file, action.file and message.file all use settings.UPLOAD_FILE_TYPES in the frontend and the admins are readonly (added in this PR)
  • siteconfig.theme_stylesheet: admin only and only allows .css
  • CaseUploadForm.files: already checks the extensions based on the configured extensions in OpenZaakConfig

Copy link
Contributor Author

@Bartvaderkin Bartvaderkin left a comment

Choose a reason for hiding this comment

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

@stevenbal See note in the diff.

Comment on lines 167 to 196
fields = [
"uuid",
"name",
"description",
"status",
"type",
"end_date",
"display_file_url",
"is_for",
"created_on",
"updated_on",
"created_by",
"plan",
"is_deleted",
]
readonly_fields = (
"uuid",
"name",
"description",
"status",
"type",
"end_date",
"display_file_url",
"is_for",
"created_on",
"updated_on",
"created_by",
"plan",
"is_deleted",
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not very DRY to repeat the same list? You could assign then same:

readonly_fields = fields

Also even more robust and less manual configuration to use has_change_permission() instead of explicitly listing everything. For example, if a new field gets added we need to remember it has to be added here (twice!) instead of being readonly by default. It is also more correct to make the model as a whole readonly instead of manually marking all fields.

This goes for all the changes that do similar.

Copy link
Member

@alextreme alextreme left a comment

Choose a reason for hiding this comment

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

The updated PR looks fine to me, retriggered the tests

@alextreme alextreme merged commit bdc8f79 into develop Jan 18, 2024
14 checks passed
@alextreme alextreme deleted the fix/1885-admin-document-pen branch January 18, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants