Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spicy version of the Map UI optimisaiton #106

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a126b41
mild
Arbyhisenaj Jun 14, 2024
8250ef7
medium
Arbyhisenaj Jun 14, 2024
506c455
spicy (pre-navigator)
Arbyhisenaj Jun 17, 2024
e60e93d
spicy (pre-navigator) fix for dropdown map interaction
Arbyhisenaj Jun 17, 2024
5d4db84
extra-hot (in progress)
Arbyhisenaj Jun 17, 2024
21b2ceb
Allow querying of data source's generic data by private reports
janbaykara Jun 17, 2024
edde679
big-commit
Arbyhisenaj Jun 18, 2024
3a6e0e1
fix: move selectedConstituencyAtom to parent page to fix hot reload c…
joaquimds Jun 18, 2024
9a58dda
Commit to trigger rebuild
janbaykara Jun 19, 2024
0220c65
Merge branch 'main' into design/facelift-spicy-push
janbaykara Jun 19, 2024
dd76172
Fix build issue due to nextjs export vars
janbaykara Jun 19, 2024
aeda0c1
Fix another type error in the markup
janbaykara Jun 19, 2024
baca6bf
Fix missing import
janbaykara Jun 19, 2024
6916b8c
Fix build
janbaykara Jun 19, 2024
cbd6009
Merge branch 'main' into design/facelift-spicy-push
janbaykara Jun 20, 2024
c43158b
Merge branch 'main' into design/facelift-spicy-push
janbaykara Jun 20, 2024
44a16d7
Fix env
janbaykara Jun 20, 2024
decf36b
Add seed data to preview environments
janbaykara Jun 20, 2024
503a434
Fix permissions for points
janbaykara Jun 20, 2024
f978b5f
Trigger rebuild
janbaykara Jun 20, 2024
6bc4b7d
fix: map sidebar crashed if data type is not members
joaquimds Jun 20, 2024
a8be148
fix: fail gracefully when loading members with no postcode data
joaquimds Jun 20, 2024
38b9e7e
Naviagator heirachy tweak
Arbyhisenaj Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hub/graphql/types/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ class GenericData(CommonData):

@strawberry_django.field
def postcode_data(self) -> Optional[PostcodesIOResult]:
if not self.postcode_data:
return None
return benedict(self.postcode_data)

@strawberry_django.field
Expand Down
49 changes: 49 additions & 0 deletions hub/management/commands/seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from asgiref.sync import async_to_sync

from hub.models import HubHomepage, User, Organisation, AirtableSource, MapReport

class Command(BaseCommand):
def handle(self, *args, **kwargs):
# Create an org for the first user
user = User.objects.create_user(
settings.DJANGO_SUPERUSER_USERNAME,
settings.DJANGO_SUPERUSER_EMAIL,
settings.DJANGO_SUPERUSER_PASSWORD
)
org = Organisation.get_or_create_for_user(user)

# Create a data source
source: AirtableSource = AirtableSource.objects.create(
name="CK's test airtable",
data_type=AirtableSource.DataSourceType.EVENT,
organisation=org,
api_key=settings.SEED_AIRTABLE_MEMBERLIST_API_KEY,
base_id=settings.SEED_AIRTABLE_MEMBERLIST_BASE_ID,
table_id=settings.SEED_AIRTABLE_MEMBERLIST_TABLE_NAME,
geography_column_type=AirtableSource.GeographyTypes.POSTCODE,
geography_column="Postcode",
postcode_field="Postcode",
start_time_field="Start",
title_field="Name",
auto_update_enabled=False,
auto_import_enabled=False,
can_display_points_publicly=True,
can_display_details_publicly=True,
update_mapping=[],
)

async_to_sync(AirtableSource.deferred_import_all)(external_data_source_id=source.id)

# Create a hub for the org
hub = HubHomepage.create_for_user(user=1, hostname="testdomain.org", org=org)
hub.layers = [
MapReport.MapLayer(
id=str(source.id),
name="Test data",
source=str(source.id)
),
# TODO: add some event source
]
hub.save()
23 changes: 23 additions & 0 deletions hub/migrations/0133_alter_hubhomepage_organisation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-06-20 09:57

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("hub", "0132_alter_membership_role"),
]

operations = [
migrations.AlterField(
model_name="hubhomepage",
name="organisation",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="hubs",
to="hub.organisation",
),
),
]
48 changes: 28 additions & 20 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2323,11 +2323,11 @@ def user_permissions(
)

source = ExternalDataSource.objects.get(pk=external_data_source_id)
default_source_permissions = source.default_data_permissions()
permissions: cls.DataPermissions = source.default_data_permissions()

if user is None or not user.is_authenticated:
logger.debug("No user provided, returning default permissions")
return default_source_permissions
return permissions

# Check for cached permissions on this source
user_id = user if not hasattr(user, "id") else str(user.id)
Expand All @@ -2350,29 +2350,28 @@ def user_permissions(
can_display_details=False,
)
if user_id is None or external_data_source.organisation is None:
return default_source_permissions
return permissions
else:
# If the user's org owns the source, they can see everything
can_display_points = external_data_source.organisation.members.filter(
is_owner = external_data_source.organisation.members.filter(
user=user_id
).exists()
can_display_details = can_display_points
if is_owner:
permissions['can_display_points'] = True
permissions['can_display_details'] = True
# Otherwise, check if their org has sharing permissions at any granularity
if not can_display_points:
if not is_owner:
permission = SharingPermission.objects.filter(
external_data_source=external_data_source,
organisation__members__user=user_id,
).first()
if permission is not None:
if permission.visibility_record_coordinates:
can_display_points = True
permissions['can_display_points'] = True
if permission.visibility_record_details:
can_display_details = True
permissions['can_display_details'] = True

permissions_dict[user_id] = cls.DataPermissions(
can_display_points=can_display_points,
can_display_details=can_display_details,
)
permissions_dict[user_id] = permissions

cache.set(
permission_cache_key,
Expand All @@ -2382,7 +2381,12 @@ def user_permissions(
timeout=60 * 60,
)

return permissions_dict[user_id]
perms = permissions_dict[user_id]

logger.debug(
f"Calculated new user permissions for user {user}: {perms}"
)
return perms

def filter(self, filter: dict) -> dict:
"""
Expand Down Expand Up @@ -3535,7 +3539,7 @@ class HubHomepage(Page):
subpage_types = ["hub.HubContentPage"]

organisation = models.ForeignKey(
Organisation, on_delete=models.PROTECT, related_name="hubs"
Organisation, on_delete=models.CASCADE, related_name="hubs"
)

layers = models.JSONField(blank=True, null=True, default=list)
Expand Down Expand Up @@ -3593,25 +3597,29 @@ def create_for_user(
user,
hostname,
port=80,
org_id=None,
org=None,
):
"""
Create a new HubHomepage for a user.
"""
if org_id:
organisation = Organisation.objects.get(id=org_id)
if org:
if not isinstance(org, Organisation):
org = Organisation.objects.get(id=org)
else:
organisation = Organisation.get_or_create_for_user(user)
org = Organisation.get_or_create_for_user(user)
if site := Site.objects.filter(hostname=hostname, port=port).first():
return site.root_page.specific

hub = HubHomepage(
title=hostname,
slug=slugify(hostname),
organisation=organisation,
organisation=org,
)
# get root
root_page = Page.get_first_root_node()
root_page.add_child(instance=hub)
hub.save()
Site.objects.create(
Site.objects.get_or_create(
hostname=hostname, port=port, site_name=hostname, root_page=hub
)
return hub
Expand Down
2 changes: 1 addition & 1 deletion hub/views/vector_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get(self, request, *args, **kwargs):
user_or_error: UserOrError = get_user_or_error(request)
user = user_or_error.user if user_or_error.user else None
permissions = ExternalDataSource.user_permissions(user, self.get_id())
logger.info(
logger.debug(
f"Got user permissions for {self.get_id()}, user {user}: {permissions}"
)
if not permissions.get("can_display_points", False):
Expand Down
16 changes: 16 additions & 0 deletions local_intelligence_hub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
TEST_MAILCHIMP_MEMBERLIST_API_KEY=(str, ""),
TEST_MAILCHIMP_MEMBERLIST_AUDIENCE_ID=(str, ""),
TEST_ACTIONNETWORK_MEMBERLIST_API_KEY=(str, ""),
SEED_AIRTABLE_MEMBERLIST_API_KEY=(str, ""),
SEED_AIRTABLE_MEMBERLIST_BASE_ID=(str, ""),
SEED_AIRTABLE_MEMBERLIST_TABLE_NAME=(str, ""),
TEST_TICKET_TAILOR_API_KEY=(str, ""),
DJANGO_SUPERUSER_USERNAME=(str, ""),
DJANGO_SUPERUSER_PASSWORD=(str, ""),
DJANGO_SUPERUSER_EMAIL=(str, ""),
DJANGO_LOG_LEVEL=(str, "INFO"),
DJANGO_HUB_LOG_LEVEL=(str, None),
POSTHOG_API_KEY=(str, False),
Expand Down Expand Up @@ -123,6 +129,16 @@
"TEST_AIRTABLE_CUSTOMDATALAYER_TABLE_NAME"
)
TEST_AIRTABLE_CUSTOMDATALAYER_API_KEY = env("TEST_AIRTABLE_CUSTOMDATALAYER_API_KEY")

# Seed data
SEED_AIRTABLE_MEMBERLIST_API_KEY = env("SEED_AIRTABLE_MEMBERLIST_API_KEY")
SEED_AIRTABLE_MEMBERLIST_BASE_ID = env("SEED_AIRTABLE_MEMBERLIST_BASE_ID")
SEED_AIRTABLE_MEMBERLIST_TABLE_NAME = env("SEED_AIRTABLE_MEMBERLIST_TABLE_NAME")
DJANGO_SUPERUSER_USERNAME = env("DJANGO_SUPERUSER_USERNAME")
DJANGO_SUPERUSER_PASSWORD = env("DJANGO_SUPERUSER_PASSWORD")
DJANGO_SUPERUSER_EMAIL = env("DJANGO_SUPERUSER_EMAIL")

#
DJANGO_LOG_LEVEL = env("DJANGO_LOG_LEVEL")
DJANGO_HUB_LOG_LEVEL = env("DJANGO_HUB_LOG_LEVEL")
DJANGO_HUB_LOG_LEVEL = (
Expand Down
9 changes: 0 additions & 9 deletions nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"d3-scale": "^4.0.2",
"d3-scale-chromatic": "^3.1.0",
"date-fns": "^3.6.0",
"env-var": "^7.5.0",
"fuse.js": "^7.0.0",
"graphiql": "^3.1.1",
"graphql": "^16.8.1",
Expand Down
Loading
Loading