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

Fix error on clone settings without organization selected #997

Merged
merged 8 commits into from
May 22, 2023

Conversation

Donnype
Copy link
Contributor

@Donnype Donnype commented May 17, 2023

Changes

Remove unused endpoint and set object list field when bypassing the ListView.get() because the form was invalid. Formviews on a POST call the form_invalid() which calls self.render_to_response(self.get_context(form=form)) immediately. But at this time the (Base)ListView has not set self.object_list = self.get_queryset() since it only does this on a GET request. But get_context_data()' _is_ being called on a generic (list?) view that tries to set context["object_list"] = self.object_list`, which fails because it does not have that property.

Issue link

Fixes #996

Proof

image


Code Checklist

  • All the commits in this PR are properly PGP-signed and verified;
  • This PR only contains functionality relevant to the issue; tickets have been created for newly discovered issues.
  • I have written unit tests for the changes or fixes I made.
  • For any non-trivial functionality, I have added integration and/or end-to-end tests.
  • I have performed a self-review of my code and refactored it to the best of my abilities.

Communication

  • I have informed others of any required .env changes files if required and changed the .env-dist accordingly.
  • I have made corresponding changes to the documentation, if necessary.

Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

@Donnype Donnype requested a review from a team as a code owner May 17, 2023 15:04
ammar92
ammar92 previously approved these changes May 18, 2023
Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

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

I think it's something else that caused this not to work as a ListView object with a custom query set. But the code seems valid and ListViews without Django ORM models are always a bit tricky.

@Donnype
Copy link
Contributor Author

Donnype commented May 18, 2023

@ammar92 I added a more detailed description of the flow going wrong, perhaps that clears things up?

@Darwinkel
Copy link
Contributor

Checklist for QA:

  • I have checked out this branch, and successfully ran a fresh make reset.
  • I confirmed that there are no unintended functional regressions in this branch:
    • I have managed to pass the onboarding flow
    • Objects and Findings are created properly
    • Tasks are created and completed properly
  • I confirmed that the PR's advertised feature or hotfix works as intended.

What works:

  • An organization must always be specified now
  • Cloning and editing Katalogus / boefje settings still work

What doesn't work:

  • Curiously (possibly an existing bug), the clone page is incomplete in which settings it displays. I tested a bit, and it looks like the settings page only displays the most recently added setting for each boefje. In the below screenshots, I removed and re-added the PROTOCOL setting for nmap, and it replaces TOP_PORTS. Cloning does seem to apply all settings correctly - this is presumably a visual bug.
    image
    image
    image

@Donnype
Copy link
Contributor Author

Donnype commented May 19, 2023

@Darwinkel Good spot, fixed!

@Darwinkel
Copy link
Contributor

@Darwinkel Good spot, fixed!

Fix confirmed, ready to merge :)

@@ -9,7 +9,7 @@ <h2>{% translate "Clone settings" %}</h2>
This includes both the KAT-alogus settings as well as enabled and disabled plugins.
{% endblocktranslate %}
</p>
<form action="{% url "katalogus_clone_settings" organization.code %}"
<form action="{% url "katalogus_settings" organization.code %}"
method="post"
class="horizontal-view help"
novalidate>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is novalidate hier nuttig op? Die skipped namelijk ook de required fields daarmee.

Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

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

Somehow I still think we're misusing the ListView. It is supposed to always render a list of objects regardless of the form's validity. If our use case or flow is different in some way, then indeed we shouldn't use it as such.

@dekkers dekkers merged commit 4254e00 into main May 22, 2023
@dekkers dekkers deleted the fix/clone-settings-no-org-error branch May 22, 2023 14:58
jpbruinsslot added a commit that referenced this pull request May 25, 2023
* main: (21 commits)
  feature(octopoes): fields to finding type model (#921)
  Add new permissions (#950)
  Fix RDO workflow (#1023)
  Various fixes to Fierce boefje (#1001)
  Feature/add signing provider for raw file (#994)
  Only sleep when all queues are empty (#952)
  Upgrade (default) container Dockerfiles from Python 3.8 to 3.11 (#1021)
  Upgrade FastAPI and dependencies (#467)
  Make two-factor authentication (2fa) optional (#1002)
  Upgrade to Django 4.2 (#1004)
  Upgrade to requests v2.31.0 (#1020)
  Removed LXD legacy (#1016)
  Pin typing-extensions to 4.5.0 (#1019)
  Fix error on clone settings without organization selected (#997)
  Scheduler tests clean up (#978)
  Remove job model and generate migrations (#995)
  update/nuclei path fix, backwards compat (#962)
  Update debianinstall.rst (#822)
  Delete `plugin_repository` package (#992)
  Create boefjes.md (#828)
  ...
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.

Cloning the katalogus settings without specifiyng an organization causes a 500 error
5 participants