diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5bd4f..986c0ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## [Unreleased](https://github.com/Onemind-Services-LLC/netbox-secrets/tree/HEAD) + +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-secrets/compare/v2.0.3...HEAD) + +**Closed issues:** + +- \[Bug\]: ImproperlyConfigured: Application labels aren't unique, duplicates [\#160](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/160) +- \[maintenance\]: NetBox Community v4.1.0 [\#159](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/159) +- \[Bug\]: error deleting users [\#151](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/151) +- \[Bug\]: Cannot post on '/api/plugins/secrets/user-keys/' endpoint [\#89](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/89) + +**Merged pull requests:** + +- Bump micromatch from 4.0.5 to 4.0.8 in /netbox\_secrets/project-static in the npm\_and\_yarn group across 1 directory [\#155](https://github.com/Onemind-Services-LLC/netbox-secrets/pull/155) ([dependabot[bot]](https://github.com/apps/dependabot)) + +## [v2.0.3](https://github.com/Onemind-Services-LLC/netbox-secrets/tree/v2.0.3) (2024-07-26) + +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-secrets/compare/v2.0.2...v2.0.3) + +**Closed issues:** + +- \[Bug\]: Unable to access netbox api schema with plugin enabled [\#148](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/148) + +**Merged pull requests:** + +- Release v2.0.3 [\#150](https://github.com/Onemind-Services-LLC/netbox-secrets/pull/150) ([abhi1693](https://github.com/abhi1693)) +- Fixed failing schema [\#149](https://github.com/Onemind-Services-LLC/netbox-secrets/pull/149) ([abhi1693](https://github.com/abhi1693)) + ## [v2.0.2](https://github.com/Onemind-Services-LLC/netbox-secrets/tree/v2.0.2) (2024-07-20) [Full Changelog](https://github.com/Onemind-Services-LLC/netbox-secrets/compare/v2.0.1...v2.0.2) @@ -69,7 +97,6 @@ **Closed issues:** - \[Docs\]: top\_level\_menu is not documented [\#122](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/122) -- \[Bug\]: ENHANCE YOUR SECRET MANAGEMENT... description is too long and unusable [\#121](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/121) - \[Bug\]: Unable to import plugin netbox-secrets: Module not found. [\#120](https://github.com/Onemind-Services-LLC/netbox-secrets/issues/120) **Merged pull requests:** diff --git a/Dockerfile b/Dockerfile index 06feaa9..9bbd8ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG NETBOX_VARIANT=v4.0 +ARG NETBOX_VARIANT=v4.1 FROM netboxcommunity/netbox:${NETBOX_VARIANT} @@ -6,4 +6,4 @@ RUN mkdir -pv /plugins/netbox-secrets COPY . /plugins/netbox-secrets RUN /opt/netbox/venv/bin/python3 /plugins/netbox-secrets/setup.py develop -RUN cp -rf /plugins/netbox-secrets/netbox_secrets/ /opt/netbox/venv/lib/python3.11/site-packages/netbox_secrets +RUN cp -rf /plugins/netbox-secrets/netbox_secrets/ /opt/netbox/venv/lib/python3.12/site-packages/netbox_secrets diff --git a/README.md b/README.md index 5641460..08ddca5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ and stability. | 3.6.x | 1.9.x | | 3.7.x | 1.10.x | | 4.0.x | 2.0.x | +| 4.1.x | 2.1.x | # Installation diff --git a/netbox_secrets/__init__.py b/netbox_secrets/__init__.py index b59c600..1f35e55 100644 --- a/netbox_secrets/__init__.py +++ b/netbox_secrets/__init__.py @@ -15,8 +15,8 @@ class NetBoxSecrets(PluginConfig): author = metadata.get('Author') author_email = metadata.get('Author-email') base_url = 'secrets' - min_version = '4.0.0' - max_version = '4.0.99' + min_version = '4.1.0' + max_version = '4.1.99' required_settings = [] default_settings = { 'apps': ['dcim.device', 'virtualization.virtualmachine'], diff --git a/netbox_secrets/api/serializers.py b/netbox_secrets/api/serializers.py index d8a42b8..0873ccd 100644 --- a/netbox_secrets/api/serializers.py +++ b/netbox_secrets/api/serializers.py @@ -13,7 +13,6 @@ from ..constants import SECRET_ASSIGNABLE_MODELS from ..models import * - __all__ = [ 'SecretRoleSerializer', 'SecretSerializer', diff --git a/netbox_secrets/api/views.py b/netbox_secrets/api/views.py index 9663772..3a5340f 100644 --- a/netbox_secrets/api/views.py +++ b/netbox_secrets/api/views.py @@ -4,16 +4,16 @@ from django.conf import settings from django.http import HttpResponseBadRequest from drf_spectacular import utils as drf_utils +from netbox.api.viewsets import BaseViewSet, NetBoxModelViewSet, mixins from rest_framework import mixins as drf_mixins, status -from rest_framework.exceptions import ValidationError +from rest_framework.exceptions import PermissionDenied, ValidationError from rest_framework.parsers import FormParser, JSONParser, MultiPartParser from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.routers import APIRootView from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet - -from netbox.api.viewsets import BaseViewSet, NetBoxModelViewSet, mixins from utilities.query import count_related + from . import serializers from .. import constants, exceptions, filtersets, models @@ -347,9 +347,9 @@ def create(self, request): class ActivateUserKeyViewSet(ViewSet): """ - This endpoint expects a private key and a list of user keys to be activated. - The private key is used to derive a master key, which is then used to activate - each user key provided. + This endpoint expects a private key and a list of user keys to be activated. + The private key is used to derive a master key, which is then used to activate + each user key provided. """ permission_classes = [IsAuthenticated] @@ -380,6 +380,10 @@ class ActivateUserKeyViewSet(ViewSet): }, ) def create(self, request): + # Check if the user has the permission to change UserKey + if not request.user.has_perm('netbox_secrets.change_userkey'): + raise PermissionDenied("You do not have permission to active User Keys.") + serializer = self.serializer_class(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) diff --git a/netbox_secrets/graphql/filters.py b/netbox_secrets/graphql/filters.py index 117c54d..4d2ff3e 100644 --- a/netbox_secrets/graphql/filters.py +++ b/netbox_secrets/graphql/filters.py @@ -1,8 +1,8 @@ import strawberry_django -from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin -from ..models import * +from netbox.graphql.filter_mixins import BaseFilterMixin, autotype_decorator from ..filtersets import * +from ..models import * __all__ = [ 'SecretFilter', diff --git a/netbox_secrets/graphql/schema.py b/netbox_secrets/graphql/schema.py index 952f53e..25a6055 100644 --- a/netbox_secrets/graphql/schema.py +++ b/netbox_secrets/graphql/schema.py @@ -3,20 +3,13 @@ import strawberry import strawberry_django -from ..models import * from .types import * -@strawberry.type +@strawberry.type(name='Query') class NetboxSecretsQuery: - @strawberry.field - def secret_roles(self, id: int) -> List[SecretRoleType]: - return SecretRole.objects.get(pk=id) - + secret_roles: List[SecretRoleType] = strawberry_django.field() secret_roles_list: List[SecretRoleType] = strawberry_django.field() - @strawberry.field - def secrets(self, id: int) -> List[SecretType]: - return Secret.objects.get(pk=id) - + secrets: List[SecretType] = strawberry_django.field() secrets_list: List[SecretType] = strawberry_django.field() diff --git a/netbox_secrets/migrations/0004_populate_secrets.py b/netbox_secrets/migrations/0004_populate_secrets.py index cf3dacf..52da41e 100644 --- a/netbox_secrets/migrations/0004_populate_secrets.py +++ b/netbox_secrets/migrations/0004_populate_secrets.py @@ -50,7 +50,7 @@ def update_objectchanges(apps, schema_editor): """ Update the ObjectChange records to reflect the new model name. """ - ObjectChange = apps.get_model('extras', 'ObjectChange') + ObjectChange = apps.get_model('core', 'ObjectChange') ContentType = apps.get_model('contenttypes', 'ContentType') try: diff --git a/netbox_secrets/templates/netbox_secrets/userkey_list.html b/netbox_secrets/templates/netbox_secrets/userkey_list.html index 91cc514..e0cec49 100644 --- a/netbox_secrets/templates/netbox_secrets/userkey_list.html +++ b/netbox_secrets/templates/netbox_secrets/userkey_list.html @@ -15,8 +15,10 @@ {% endif %} {% endif %} - - Activate User Key - + {% if perms.netbox_secrets.change_userkey %} + + Activate User Key + + {% endif %} {% endblock controls %} diff --git a/netbox_secrets/views.py b/netbox_secrets/views.py index 2399271..a6165c9 100644 --- a/netbox_secrets/views.py +++ b/netbox_secrets/views.py @@ -4,16 +4,17 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import PermissionDenied from django.db import transaction from django.shortcuts import get_object_or_404, redirect, render from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.translation import gettext as _ from django.views.generic.base import View +from netbox_secrets.models import UserKey -from extras.signals import clear_events +from core.signals import clear_events from netbox.views import generic -from netbox_secrets.models import UserKey from tenancy.views import ObjectContactsView from utilities.exceptions import AbortRequest, PermissionsViolation from utilities.forms import restrict_form_fields @@ -385,6 +386,9 @@ def get(self, request): ) def post(self, request): + if not request.user.has_perm('netbox_secrets.change_userkey'): + raise PermissionDenied("You do not have permission to activate User Keys.") + if not self.userkey or not self.userkey.is_active(): messages.error(request, "You do not have an active User Key.") return redirect('plugins:netbox_secrets:userkey_activate') diff --git a/setup.py b/setup.py index 72a1524..cc8ab25 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='netbox-secrets', - version='2.0.3', + version='2.1.0', description=description, long_description=long_description, long_description_content_type="text/markdown",