diff --git a/rocky/katalogus/views/plugin_enable_disable.py b/rocky/katalogus/views/plugin_enable_disable.py index 81a0cb89d6a..b44096ec910 100644 --- a/rocky/katalogus/views/plugin_enable_disable.py +++ b/rocky/katalogus/views/plugin_enable_disable.py @@ -79,16 +79,21 @@ def post(self, request, *args, **kwargs): _("Boefje '{boefje_name}' enabled.").format(boefje_name=self.plugin.name), ) else: + member_clearance_level_text = ( + "Your clearance level is L{}. Contact your administrator to get a higher clearance level." + ).format(self.organization_member.trusted_clearance_level) + + if self.organization_member.trusted_clearance_level < 0: + member_clearance_level_text = _( + "Your clearance level has not yet been set. Contact your administrator." + ) + messages.add_message( self.request, messages.ERROR, - _( - "To enable {} you need at least a clearance level of L{}. " - "Your clearance level is L{}. Contact your administrator to get a higher clearance level." - ).format( + _("To enable {} you need at least a clearance level of L{}. " + member_clearance_level_text).format( self.plugin.name.title(), self.plugin.scan_level.value, - self.organization_member.trusted_clearance_level, ), ) diff --git a/rocky/tests/katalogus/test_katalogus.py b/rocky/tests/katalogus/test_katalogus.py index 7950cc0ca5a..3ae583ede72 100644 --- a/rocky/tests/katalogus/test_katalogus.py +++ b/rocky/tests/katalogus/test_katalogus.py @@ -186,7 +186,7 @@ def test_katalogus_client(mocker): def test_enable_disable_plugin_no_clearance(rf, redteam_member, mocker): - redteam_member.trusted_clearance_level = -1 + redteam_member.trusted_clearance_level = 1 redteam_member.save() plugin = get_boefjes_data()[0] @@ -226,6 +226,44 @@ def test_enable_disable_plugin_no_clearance(rf, redteam_member, mocker): ) +def test_enable_disable_plugin_no_clearance_other_text(rf, redteam_member, mocker): + redteam_member.trusted_clearance_level = -1 + redteam_member.save() + + plugin = get_boefjes_data()[0] + mock_requests = mocker.patch("katalogus.client.requests") + mock_response = mocker.MagicMock() + mock_requests.Session().get.return_value = mock_response + mock_response.json.return_value = plugin + + request = setup_request( + rf.post( + "plugin_enable_disable", + ), + redteam_member.user, + ) + + response = PluginEnableDisableView.as_view()( + setup_request(request, redteam_member.user), + organization_code=redteam_member.organization.code, + plugin_type=plugin["type"], + plugin_id=plugin["id"], + plugin_state=False, + ) + + # redirects back to KAT-alogus + assert response.status_code == 302 + + assert ( + list(request._messages).pop().message + == "To enable " + + plugin["name"].title() + + " you need at least a clearance level of L" + + str(plugin["scan_level"]) + + ". Your clearance level has not yet been set. Contact your administrator." + ) + + def test_enable_disable_plugin_has_clearance(rf, redteam_member, mocker): plugin = get_boefjes_data()[0] mock_requests = mocker.patch("katalogus.client.requests")