Skip to content

Commit

Permalink
Add visibility modifier to safe-apps (#130)
Browse files Browse the repository at this point in the history
- The visibility modifier can be set to True or False
- Existing Safe Apps will have it set to True (this is also the default value when adding a new safe-app)
- If set to False the safe-app won't be returned on GET /api/v1/safe-apps/
  • Loading branch information
fmrsabino authored Jun 30, 2021
1 parent 2ccf0e1 commit a686862
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/safe_apps/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)
Expand Down
18 changes: 18 additions & 0 deletions src/safe_apps/migrations/0005_safeapp_visible.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
3 changes: 3 additions & 0 deletions src/safe_apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/safe_apps/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 32 additions & 0 deletions src/safe_apps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/safe_apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit a686862

Please sign in to comment.