Skip to content

Commit

Permalink
Rename SafeApp visible field to listed (#1123)
Browse files Browse the repository at this point in the history
Renames SafeApp.visible to SafeApp.listed
  • Loading branch information
hectorgomezv authored May 13, 2024
1 parent 18cc685 commit 62d29dc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/safe_apps/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SocialProfileInline(admin.TabularInline[Model, Model]):

@admin.register(SafeApp)
class SafeAppAdmin(admin.ModelAdmin[SafeApp]):
list_display = ("name", "url", "chain_ids", "visible")
list_display = ("name", "url", "chain_ids", "listed")
list_filter = (ChainIdFilter,)
search_fields = ("name", "url")
ordering = ("name",)
Expand Down
18 changes: 18 additions & 0 deletions src/safe_apps/migrations/0012_rename_visible_safeapp_listed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.2 on 2024-05-08 05:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("safe_apps", "0011_alter_safeapp_icon_url"),
]

operations = [
migrations.RenameField(
model_name="safeapp",
old_name="visible",
new_name="listed",
),
]
5 changes: 2 additions & 3 deletions src/safe_apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ class AccessControlPolicy(str, Enum):
DOMAIN_ALLOWLIST = "DOMAIN_ALLOWLIST"

app_id = models.BigAutoField(primary_key=True)
# TODO: rename "visible" to "listed" across the service
visible = models.BooleanField(
listed = models.BooleanField(
default=True
) # True if this safe-app should be visible from the view. False otherwise
) # True if this safe-app should be listed in the view. False otherwise
url = models.URLField()
name = models.CharField(max_length=200)
icon_url = models.ImageField(
Expand Down
2 changes: 1 addition & 1 deletion src/safe_apps/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Meta:
model = SafeApp

app_id = factory.Sequence(lambda id: id)
visible = True
listed = True
url = factory.Faker("url")
name = factory.Faker("company")
icon_url = factory.django.ImageField(width=50, height=50)
Expand Down
56 changes: 28 additions & 28 deletions src/safe_apps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,23 +629,23 @@ def test_should_cache_response(self) -> None:


class SafeAppsVisibilityTests(APITestCase):
def test_visible_safe_app_is_shown(self) -> None:
visible_safe_app = SafeAppFactory.create(visible=True)
def test_listed_safe_app_is_shown(self) -> None:
listed_safe_app = SafeAppFactory.create(listed=True)
json_response = [
{
"id": visible_safe_app.app_id,
"url": visible_safe_app.url,
"name": visible_safe_app.name,
"iconUrl": f"http://testserver{visible_safe_app.icon_url.url}",
"description": visible_safe_app.description,
"chainIds": visible_safe_app.chain_ids,
"id": listed_safe_app.app_id,
"url": listed_safe_app.url,
"name": listed_safe_app.name,
"iconUrl": f"http://testserver{listed_safe_app.icon_url.url}",
"description": listed_safe_app.description,
"chainIds": listed_safe_app.chain_ids,
"provider": None,
"accessControl": {
"type": "NO_RESTRICTIONS",
},
"tags": [],
"features": [],
"developerWebsite": visible_safe_app.developer_website,
"developerWebsite": listed_safe_app.developer_website,
"socialProfiles": [],
}
]
Expand All @@ -656,40 +656,40 @@ def test_visible_safe_app_is_shown(self) -> None:
self.assertEqual(response.status_code, 200)
self.assertCountEqual(response.json(), json_response)

def test_not_visible_safe_app_is_shown_if_only_listed_is_not_set(self) -> None:
not_visible_safe_app = SafeAppFactory.create(visible=False)
visible_safe_app = SafeAppFactory.create(visible=True)
def test_unlisted_safe_app_is_shown_if_only_listed_is_not_set(self) -> None:
unlisted_safe_app = SafeAppFactory.create(listed=False)
listed_safe_app = SafeAppFactory.create(listed=True)
json_response = [
{
"id": not_visible_safe_app.app_id,
"url": not_visible_safe_app.url,
"name": not_visible_safe_app.name,
"iconUrl": f"http://testserver{not_visible_safe_app.icon_url.url}",
"description": not_visible_safe_app.description,
"chainIds": not_visible_safe_app.chain_ids,
"id": unlisted_safe_app.app_id,
"url": unlisted_safe_app.url,
"name": unlisted_safe_app.name,
"iconUrl": f"http://testserver{unlisted_safe_app.icon_url.url}",
"description": unlisted_safe_app.description,
"chainIds": unlisted_safe_app.chain_ids,
"provider": None,
"accessControl": {
"type": "NO_RESTRICTIONS",
},
"tags": [],
"features": [],
"developerWebsite": not_visible_safe_app.developer_website,
"developerWebsite": unlisted_safe_app.developer_website,
"socialProfiles": [],
},
{
"id": visible_safe_app.app_id,
"url": visible_safe_app.url,
"name": visible_safe_app.name,
"iconUrl": f"http://testserver{visible_safe_app.icon_url.url}",
"description": visible_safe_app.description,
"chainIds": visible_safe_app.chain_ids,
"id": listed_safe_app.app_id,
"url": listed_safe_app.url,
"name": listed_safe_app.name,
"iconUrl": f"http://testserver{listed_safe_app.icon_url.url}",
"description": listed_safe_app.description,
"chainIds": listed_safe_app.chain_ids,
"provider": None,
"accessControl": {
"type": "NO_RESTRICTIONS",
},
"tags": [],
"features": [],
"developerWebsite": visible_safe_app.developer_website,
"developerWebsite": listed_safe_app.developer_website,
"socialProfiles": [],
},
]
Expand All @@ -700,8 +700,8 @@ def test_not_visible_safe_app_is_shown_if_only_listed_is_not_set(self) -> None:
self.assertEqual(response.status_code, 200)
self.assertCountEqual(response.json(), json_response)

def test_not_visible_safe_app_is_not_shown_if_only_listed_is_set(self) -> None:
SafeAppFactory.create(visible=False)
def test_unlisted_safe_app_is_not_shown_if_only_listed_is_set(self) -> None:
SafeAppFactory.create(listed=False)
json_response: List[Dict[str, Any]] = []
url = reverse("v1:safe-apps:list") + f'{"?onlyListed=true"}'

Expand Down
4 changes: 2 additions & 2 deletions src/safe_apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SafeAppsListView(ListAPIView): # type: ignore[type-arg]
_swagger_only_listed_param = openapi.Parameter(
"onlyListed",
openapi.IN_QUERY,
description="If true, only listed/visible Safe Apps will be included. Else, all Safe Apps will be included",
description="If true, only listed Safe Apps will be included. Else, all Safe Apps will be included",
type=openapi.TYPE_BOOLEAN,
default=False,
)
Expand All @@ -69,7 +69,7 @@ def get_queryset(self) -> QuerySet[SafeApp]:
self.request.query_params.get("onlyListed", False)
)
if only_listed:
queryset = SafeApp.objects.filter(visible=True)
queryset = SafeApp.objects.filter(listed=True)
else:
queryset = SafeApp.objects.all()

Expand Down

0 comments on commit 62d29dc

Please sign in to comment.