Esempio n. 1
0
 def create(self, validated_data: Dict, *args: Any, **kwargs: Any) -> Plugin:
     validated_data["url"] = self.initial_data.get("url", None)
     validated_data["organization_id"] = self.context["organization_id"]
     if validated_data.get("is_global") and not can_globally_manage_plugins(validated_data["organization_id"]):
         raise PermissionDenied("This organization can't manage global plugins!")
     plugin = Plugin.objects.install(**validated_data)
     return plugin
Esempio n. 2
0
    def test_no_org_check(self):
        result_root = can_globally_manage_plugins(None)
        result_install = can_install_plugins(None)
        result_config = can_configure_plugins(None)
        result_view = can_view_plugins(None)

        self.assertFalse(result_root)
        self.assertFalse(result_install)
        self.assertFalse(result_config)
        self.assertFalse(result_view)
Esempio n. 3
0
    def test_none_check(self):
        self.organization.plugins_access_level = Organization.PluginsAccessLevel.NONE
        self.organization.save()

        result_root = can_globally_manage_plugins(self.organization)
        result_install = can_install_plugins(self.organization)
        result_config = can_configure_plugins(self.organization)
        result_view = can_view_plugins(self.organization)

        self.assertFalse(result_root)
        self.assertFalse(result_install)
        self.assertFalse(result_config)
        self.assertFalse(result_view)
Esempio n. 4
0
    def test_config_check_with_id_str(self):
        self.organization.plugins_access_level = Organization.PluginsAccessLevel.CONFIG
        self.organization.save()
        organization_id = str(self.organization.id)

        result_root = can_globally_manage_plugins(organization_id)
        result_install = can_install_plugins(organization_id)
        result_config = can_configure_plugins(organization_id)
        result_view = can_view_plugins(organization_id)

        self.assertFalse(result_root)
        self.assertFalse(result_install)
        self.assertTrue(result_config)
        self.assertTrue(result_view)
Esempio n. 5
0
 def create(self, validated_data: Dict, *args: Any,
            **kwargs: Any) -> Plugin:
     validated_data["url"] = self.initial_data.get("url", None)
     if validated_data.get("is_global") and not can_globally_manage_plugins(
             self.context["organization_id"]):
         raise PermissionDenied(
             "This organization can't manage global plugins!")
     if validated_data.get("plugin_type", None) != Plugin.PluginType.SOURCE:
         self._update_validated_data_from_url(validated_data,
                                              validated_data["url"])
         self._raise_if_plugin_installed(validated_data["url"],
                                         self.context["organization_id"])
     validated_data["organization_id"] = self.context["organization_id"]
     plugin = super().create(validated_data)
     reload_plugins_on_workers()
     return plugin