Skip to content

Commit

Permalink
Group/org updates and frontend changes to load in new data
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Jan 12, 2025
1 parent 74af533 commit 0da7a8d
Show file tree
Hide file tree
Showing 36 changed files with 312 additions and 79 deletions.
2 changes: 0 additions & 2 deletions backend/communities/groups/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class GroupFactory(factory.django.DjangoModelFactory):
class Meta:
model = Group

# Note: We should always set organizations for groups directly and not have them be generated.
# org = factory.SubFactory("communities.organizations.factories.OrganizationFactory")
created_by = factory.SubFactory("authentication.factories.UserFactory")
name = factory.Faker("word")
tagline = factory.Faker("word")
Expand Down
1 change: 0 additions & 1 deletion backend/communities/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class Group(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
# TODO: Remove null=True - needed for factories.
org = models.ForeignKey(
"communities.Organization",
on_delete=models.CASCADE,
Expand Down
2 changes: 1 addition & 1 deletion backend/communities/groups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class GroupSerializer(serializers.ModelSerializer[Group]):
texts = GroupTextSerializer(many=True, read_only=True)
location = LocationSerializer(read_only=True)
resources = ResourceSerializer(many=True, read_only=True)
events = EventSerializer(many=True, read_only=True)
org = GroupOrganizationSerializer(read_only=True)
events = EventSerializer(many=True, read_only=True)

class Meta:
model = Group
Expand Down
1 change: 0 additions & 1 deletion backend/communities/groups/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def test_url_validations() -> None:
get_involved_url=fake.url(),
terms_checked=True,
)

group.full_clean()


Expand Down
8 changes: 4 additions & 4 deletions backend/communities/groups/tests/test_group_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def test_group_text_languages() -> None:
group=group,
iso="spa",
primary=False,
description="Descripción",
get_involved="Cómo participar",
donate_prompt="Prompt de donación",
description="Description",
get_involved="How to participate",
donate_prompt="Donation prompt",
)
assert secondary_text.primary is False
assert secondary_text.iso == "spa"
assert secondary_text.description == "Descripción"
assert secondary_text.description == "Description"
8 changes: 0 additions & 8 deletions backend/communities/organizations/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,3 @@ class Meta:
description = factory.Faker(provider="text", locale="la", max_nb_chars=1000)
get_involved = factory.Faker(provider="text", locale="la")
donate_prompt = factory.Faker(provider="text", locale="la")


class StatusTypeFactory(factory.django.DjangoModelFactory):
class Meta:
model = "communities.StatusType"
django_get_or_create = ("name",)

name = "Active"
1 change: 0 additions & 1 deletion backend/communities/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Organization(models.Model):
faqs = models.ManyToManyField("content.Faq", blank=True)
resources = models.ManyToManyField("content.Resource", blank=True)
discussions = models.ManyToManyField("content.Discussion", blank=True)
events = models.ManyToManyField("events.Event", blank=True)

def __str__(self) -> str:
return self.name
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions backend/communities/organizations/tests/test_org_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Test cases for the OrganizationEvents entity.
"""

import pytest

from communities.organizations.factories import OrganizationFactory
from communities.organizations.models import Organization
from events.factories import EventFactory

pytestmark = pytest.mark.django_db


def test_multiple_events_per_org() -> None:
"""Test multiple events for a single organization."""
org = OrganizationFactory.create()
events = EventFactory.create_batch(3)

org.events.set(events)

org = Organization.objects.get(id=org.id)
org_events = org.events.all()

assert len(events) == len(org_events)

for event in events:
assert event in org_events
62 changes: 62 additions & 0 deletions backend/communities/organizations/tests/test_org_member.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Test cases for the OrganizationMember model.
"""

import pytest

from authentication.factories import UserFactory
from communities.organizations.factories import (
OrganizationFactory,
OrganizationMemberFactory,
)

pytestmark = pytest.mark.django_db


def test_org_member_str() -> None:
"""Test string representation of OrganizationMember model."""
org_member = OrganizationMemberFactory.build()
assert str(org_member) == f"{org_member.id}"


def test_org_member_roles() -> None:
"""Test the different roles an organization member can have."""
user = UserFactory()
org = OrganizationFactory()

print(org.__dict__)

# 1. Test owner role.
owner = OrganizationMemberFactory(
org=org, user=user, is_owner=True, is_admin=False, is_comms=False
)
assert owner.is_owner is True
assert owner.is_admin is False
assert owner.is_comms is False

# 2. Test admin role.
admin = OrganizationMemberFactory(
org=org, user=user, is_owner=False, is_admin=True, is_comms=False
)
assert admin.is_owner is False
assert admin.is_admin is True
assert admin.is_comms is False

# 3. Test comms role.
comms = OrganizationMemberFactory(
org=org, user=user, is_owner=False, is_admin=False, is_comms=True
)
assert comms.is_owner is False
assert comms.is_admin is False
assert comms.is_comms is True


def test_multiple_members_per_org() -> None:
"""Test multiple members in a single organization."""
org = OrganizationFactory()
members = [OrganizationMemberFactory(org=org) for _ in range(3)]

assert len(members) == 3

for member in members:
assert member.org == org
35 changes: 35 additions & 0 deletions backend/communities/organizations/tests/test_org_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Test cases for OrganizationResource model.
"""

import pytest

from communities.organizations.factories import OrganizationFactory
from content.factories import ResourceFactory
from content.models import Resource

pytestmark = pytest.mark.django_db


def test_org_resource_creation() -> None:
"""Test creating a OrganizationResource instance."""
org = OrganizationFactory()
resource = ResourceFactory()

org.resources.set([resource])

assert isinstance(org.resources.first(), Resource)
assert org.resources.first() == resource


def test_multiple_resources_per_org() -> None:
"""Test multiple resources for a single organization."""
org = OrganizationFactory()
resources = ResourceFactory.create_batch(3)

org.resources.set(resources)

assert len(resources) == 3

for resource in resources:
assert resource in org.resources.all()
49 changes: 49 additions & 0 deletions backend/communities/organizations/tests/test_org_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Test cases for the OrganizationText model.
"""

import pytest

from communities.organizations.factories import (
OrganizationFactory,
OrganizationTextFactory,
)

pytestmark = pytest.mark.django_db


def test_org_text_str() -> None:
"""Test string representation of OrganizationText model."""
org_text = OrganizationTextFactory.build()
assert hasattr(org_text, "description")


def test_org_text_languages() -> None:
"""Test organization text with different ISO languages."""
org = OrganizationFactory()

# 1. Test primary language text.
primary_text = OrganizationTextFactory(
org=org,
iso="eng",
primary=True,
description="Primary description",
get_involved="Get involved text",
donate_prompt="Donation prompt",
)
assert primary_text.primary is True
assert primary_text.iso == "eng"
assert primary_text.description == "Primary description"

# 2. Test secondary language text.
secondary_text = OrganizationTextFactory(
org=org,
iso="spa",
primary=False,
description="Description",
get_involved="How to participate",
donate_prompt="Donation prompt",
)
assert secondary_text.primary is False
assert secondary_text.iso == "spa"
assert secondary_text.description == "Description"
34 changes: 34 additions & 0 deletions backend/communities/organizations/tests/test_org_topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Test cases for OrganizationTopic model.
"""

import pytest

from communities.organizations.factories import OrganizationFactory
from content.factories import TopicFactory
from content.models import Topic

pytestmark = pytest.mark.django_db


def test_org_topic_creation() -> None:
"""Test creating a OrganizationTopic instance."""
org = OrganizationFactory()
topic = TopicFactory()

org.topics.set([topic])

assert isinstance(org.topics.first(), Topic)
assert org.topics.first() == topic


def test_multiple_topics_per_org() -> None:
"""Test multiple topics for a single organization."""
org = OrganizationFactory()
topics = TopicFactory.create_batch(3)

org.topics.set(topics)

assert len(topics) == 3
for topic in topics:
assert topic in org.topics.all()
4 changes: 2 additions & 2 deletions backend/core/management/commands/populate_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def handle(self, *args: str, **options: Unpack[Options]) -> None:
)

user_org_event = EventFactory(
name=f"{user_topic.name} Event o{o}:e{e}",
name=f"{user_topic.name} Event [o{o}:e{e}]",
tagline=f"{event_type_verb} {user_topic.name}",
type=event_type,
created_by=user,
org=user_org,
orgs=user_org,
)

event_texts = EventTextFactory(iso="en", primary=True)
Expand Down
4 changes: 2 additions & 2 deletions backend/events/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
class EventFactory(factory.django.DjangoModelFactory):
class Meta:
model = Event
django_get_or_create = ("created_by", "org")
django_get_or_create = ("created_by", "orgs")

org = factory.SubFactory("communities.organizations.factories.OrganizationFactory")
orgs = factory.SubFactory("communities.organizations.factories.OrganizationFactory")
created_by = factory.SubFactory("authentication.factories.UserFactory")
name = factory.Faker("word")
tagline = factory.Faker("word")
Expand Down
4 changes: 2 additions & 2 deletions backend/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Event(models.Model):
related_name="created_events",
on_delete=models.CASCADE,
)
org = models.ForeignKey(
"communities.Organization", related_name="org", on_delete=models.CASCADE
orgs = models.ForeignKey(
"communities.Organization", related_name="events", on_delete=models.CASCADE
)
name = models.CharField(max_length=255)
tagline = models.CharField(max_length=255, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion backend/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EventSerializer(serializers.ModelSerializer[Event]):
texts = EventTextSerializer(many=True, read_only=True)
offline_location = LocationSerializer(read_only=True)
resources = ResourceSerializer(many=True, read_only=True)
org = EventOrganizationSerializer(read_only=True)
orgs = EventOrganizationSerializer(read_only=True)

class Meta:
model = Event
Expand Down
12 changes: 7 additions & 5 deletions frontend/components/card/CardDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
</div>
<div v-if="event" class="flex-col space-y-6 py-2">
<div class="flex items-center gap-3">
<MetaTagOrganization
v-for="(o, i) in event.organizations.slice(0, 1)"
<MetaTagOrganization :organization="event.orgs" />
<!-- TODO: Once we have more than one organization. -->
<!-- <MetaTagOrganization
v-for="(o, i) in event.orgs.slice(0, 1)"
:key="i"
:organization="o"
/>
<button
v-if="event.organizations.length > 1"
v-if="event.orgs.length > 1"
@click="openModalOrganizationOverview()"
@keydown.enter="openModalOrganizationOverview()"
class="text-sm font-semibold text-black"
>
(+{{ event.organizations.length - 1 }} more)
</button>
(+{{ event.orgs.length - 1 }} more)
</button> -->
<ModalOrganizationOverview
@closeModal="openModalOrganizationOverview()"
:cta="true"
Expand Down
Loading

0 comments on commit 0da7a8d

Please sign in to comment.