diff --git a/src/safe_apps/admin.py b/src/safe_apps/admin.py index fb07de5b..118ec2a5 100644 --- a/src/safe_apps/admin.py +++ b/src/safe_apps/admin.py @@ -22,7 +22,7 @@ def queryset(self, request, queryset): @admin.register(SafeApp) class SafeAppAdmin(admin.ModelAdmin): - list_display = ("name", "url", "chain_ids") + list_display = ("name", "url", "chain_ids", "visible") list_filter = (ChainIdFilter,) search_fields = ("name", "url") ordering = ("name",) diff --git a/src/safe_apps/migrations/0005_safeapp_visible.py b/src/safe_apps/migrations/0005_safeapp_visible.py new file mode 100644 index 00000000..f358f3a6 --- /dev/null +++ b/src/safe_apps/migrations/0005_safeapp_visible.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.4 on 2021-06-29 14:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("safe_apps", "0004_add_auto_pk"), + ] + + operations = [ + migrations.AddField( + model_name="safeapp", + name="visible", + field=models.BooleanField(default=True), + ), + ] diff --git a/src/safe_apps/models.py b/src/safe_apps/models.py index 0f357e3d..ebf04e3c 100644 --- a/src/safe_apps/models.py +++ b/src/safe_apps/models.py @@ -12,6 +12,9 @@ def __str__(self): class SafeApp(models.Model): app_id = models.BigAutoField(primary_key=True) + visible = models.BooleanField( + default=True + ) # True if this safe-app should be visible from the view. False otherwise url = models.URLField() name = models.CharField(max_length=200) icon_url = models.URLField() diff --git a/src/safe_apps/tests/factories.py b/src/safe_apps/tests/factories.py index f3dac1d5..87639c0c 100644 --- a/src/safe_apps/tests/factories.py +++ b/src/safe_apps/tests/factories.py @@ -17,6 +17,7 @@ class Meta: model = SafeApp app_id = factory.Faker("pyint") + visible = True url = factory.Faker("url") name = factory.Faker("company") icon_url = factory.Faker("image_url") diff --git a/src/safe_apps/tests/test_views.py b/src/safe_apps/tests/test_views.py index e182e3a2..26d8dba2 100644 --- a/src/safe_apps/tests/test_views.py +++ b/src/safe_apps/tests/test_views.py @@ -247,3 +247,35 @@ def test_should_cache_response(self): # Cache-Control should be 10 minutes (60 * 10) self.assertEqual(cache_control, "max-age=600") self.assertEqual(response.data, json_response) + + +class SafeAppsVisibilityTests(APITestCase): + def test_visible_safe_app_is_shown(self): + visible_safe_app = SafeAppFactory.create(visible=True) + json_response = [ + { + "id": visible_safe_app.app_id, + "url": visible_safe_app.url, + "name": visible_safe_app.name, + "icon_url": visible_safe_app.icon_url, + "description": visible_safe_app.description, + "chain_ids": visible_safe_app.chain_ids, + "provider": None, + } + ] + url = reverse("v1:safe-apps:list") + + response = self.client.get(path=url, data=None, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, json_response) + + def test_not_visible_safe_app_is_not_shown(self): + SafeAppFactory.create(visible=False) + json_response = [] + url = reverse("v1:safe-apps:list") + + response = self.client.get(path=url, data=None, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, json_response) diff --git a/src/safe_apps/views.py b/src/safe_apps/views.py index 5bba0340..2804cf8a 100644 --- a/src/safe_apps/views.py +++ b/src/safe_apps/views.py @@ -29,7 +29,7 @@ def get(self, request, *args, **kwargs): return super().get(self, request, *args, **kwargs) def get_queryset(self): - queryset = SafeApp.objects.all() + queryset = SafeApp.objects.filter(visible=True) network_id = self.request.query_params.get("chainId") if network_id is not None and network_id.isdigit():