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

REST API to recalculate bits and clone katalogus settings #3572

Merged
merged 7 commits into from
Oct 1, 2024

Conversation

dekkers
Copy link
Contributor

@dekkers dekkers commented Sep 23, 2024

Changes

This adds the REST API for recalculating bits and cloning settings. The endpoints are under the organization endpoint. For example if organization has rocky primary key 1, using httpie you can recalculate bits using:

$ http POST http://127.0.0.1:8000/api/v1/organization/1/recalculate_bits/ "Authorization:Token <token>"

To clone the katalogus settings to organization with rocky primary key 2:

$ http POST http://127.0.0.1:8000/api/v1/organization/1/clone_katalogus_settings/ to_organization=2 "Authorization:Token <token>"

This includes PR #3571 because else the tests with the right permissions don't work, so PR #3571 needs to be merged first.

Issue link

Closes #3525

QA notes

See Changes how to test the API.


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.

@dekkers dekkers requested a review from a team as a code owner September 23, 2024 15:14
@dekkers dekkers self-assigned this Sep 24, 2024
ammar92
ammar92 previously approved these changes Sep 26, 2024
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.

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.
  • I checked the logs for errors and/or warnings and made issues where necessary

What works:

  • API endpoints exist and work as expected
  • Was able to recalculate bits
  • Was able to clone KATalogus settings to a new organization

underdarknl
underdarknl previously approved these changes Sep 30, 2024
@stephanie0x00
Copy link
Contributor

stephanie0x00 commented Sep 30, 2024

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.
  • I checked the logs for errors and/or warnings and made issues where necessary

What works:

Couldn't test due to the error message below.

What doesn't work:

  • When going to the API interface the following error is triggered when using the form to recalculate the bits and to clone.

image

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/api/v1/organization/1/clone_katalogus_settings/

Django Version: 5.0.8
Python Version: 3.11.10
Installed Applications:
['whitenoise.runserver_nostatic',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.humanize',
 'django.forms',
 'django_components',
 'django_components.safer_staticfiles',
 'django_otp',
 'django_otp.plugins.otp_static',
 'django_otp.plugins.otp_totp',
 'two_factor',
 'account',
 'tools',
 'fmea',
 'rocky',
 'crisis_room',
 'onboarding',
 'katalogus',
 'django_password_validators',
 'django_password_validators.password_history',
 'rest_framework',
 'tagulous',
 'compressor',
 'reports',
 'knox',
 'csp']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'rocky.middleware.auth_token.AuthTokenMiddleware',
 'django_structlog.middlewares.RequestMiddleware',
 'django_otp.middleware.OTPMiddleware',
 'rocky.middleware.auth_required.AuthRequiredMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'rocky.middleware.onboarding.OnboardingMiddleware',
 'csp.middleware.CSPMiddleware']



Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/viewsets.py", line 124, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
    ^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/rocky/tools/viewsets.py", line 80, in clone_katalogus_settings
    organization_code=self.organization.code,
                      ^^^^^^^^^^^^^^^^^

Exception Type: AttributeError at /api/v1/organization/1/clone_katalogus_settings/
Exception Value: 'OrganizationViewSet' object has no attribute 'organization'

Bug or feature?:

n/a

@stephanie0x00 stephanie0x00 added the 😸 Review/QA feedback Review/QA feedback provided label Sep 30, 2024
@underdarknl underdarknl merged commit 62455d4 into main Oct 1, 2024
10 checks passed
@underdarknl underdarknl deleted the api-bits-recalculate-clone-settings branch October 1, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😸 Review/QA feedback Review/QA feedback provided
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Create REST API to rerun bits and duplicate katalogus settings
4 participants