Skip to content

Commit

Permalink
Remove can_register Column from Event Entity #232 (#235)
Browse files Browse the repository at this point in the history
* Remove organizers from paginated list of registrations

* Fix Github avatars and improve display of organizers
This commit updates the backend EventOrganizer model to include the
Github avatar of the user and likewise updates the frontend to ensure
that the desired user avatar is displayed rather than the currently
logged in user's avatar.

This commit also removes organizer registrations from the list of
registrations. Instead, organizers are displayed on the event details
card. Clicking the organizer chip will allow you to email that organizer.

* Remove can_register column from Event Entity
This commit removes the can_register column from the Event Entity as it
is simply a computer value based on registration_limit being greater
than 0. It likewise updates all instances of can_register and either
removes it or replaces the logic to just use registration_limit.

* Generate migration script
This commit generates the migration script for merging in to main using
the migration generate script.

* Clean up migration script file

* Fix failing event service tests

---------

Co-authored-by: Kris Jordan <[email protected]>
  • Loading branch information
jadekeegan and KrisJordan authored Dec 31, 2023
1 parent 2ec504e commit 299c7ec
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 37 deletions.
6 changes: 0 additions & 6 deletions backend/entities/event_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class EventEntity(EntityBase):
public: Mapped[bool] = mapped_column(Boolean)
# Maximim number of people who can register for the event
registration_limit: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
# Whether or not registration is open
can_register: Mapped[bool] = mapped_column(Boolean, default=True)

# Organization hosting the event
# NOTE: This defines a one-to-many relationship between the organization and events tables.
Expand Down Expand Up @@ -69,7 +67,6 @@ def from_draft_model(cls, model: DraftEvent) -> Self:
description=model.description,
public=model.public,
registration_limit=model.registration_limit,
can_register=model.can_register,
organization_id=model.organization_id,
)

Expand All @@ -91,7 +88,6 @@ def from_model(cls, model: Event) -> Self:
description=model.description,
public=model.public,
registration_limit=model.registration_limit,
can_register=model.can_register,
organization_id=model.organization_id,
)

Expand Down Expand Up @@ -135,7 +131,6 @@ def to_model(self, subject: User | None = None) -> Event:
description=self.description,
public=self.public,
registration_limit=self.registration_limit,
can_register=self.can_register,
organization_id=self.organization_id,
registration_count=len(attendees),
is_attendee=is_attendee,
Expand All @@ -162,7 +157,6 @@ def to_details_model(self, subject: User | None = None) -> EventDetails:
public=self.public,
registration_limit=self.registration_limit,
registration_count=event.registration_count,
can_register=self.can_register,
organization_id=self.organization_id,
organization=self.organization.to_model(),
is_attendee=event.is_attendee,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Migration for 232-remove-can-register-column-from-event
Revision ID: 17162b9faf79
Revises: 1952e411745f
Create Date: 2023-12-31 15:25:44.947516
"""
from alembic import op
import sqlalchemy as sa


revision = "17162b9faf79"
down_revision = "1952e411745f"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.drop_column("event", "can_register")


def downgrade() -> None:
op.add_column(
"event",
sa.Column(
"can_register",
sa.Boolean(),
nullable=False,
default=False,
server_default=sa.text("false"),
),
)
1 change: 0 additions & 1 deletion backend/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class DraftEvent(BaseModel):
description: str
public: bool
registration_limit: int
can_register: bool
organization_id: int
organizers: list[EventOrganizer] = []

Expand Down
11 changes: 8 additions & 3 deletions backend/services/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def update(self, subject: User, event: Event) -> EventDetails:
event_entity.description = event.description
event_entity.location = event.location
event_entity.public = event.public
event_entity.can_register = event.can_register
event_entity.registration_limit = event.registration_limit

# If attempting to edit organizers, enforce registration management permissions
Expand Down Expand Up @@ -569,7 +568,10 @@ def get_registered_users_of_event(
.join(
EventRegistrationAlias, EventRegistrationAlias.user_id == UserEntity.id
)
.where(EventRegistrationAlias.event_id == event_id, EventRegistrationAlias.registration_type == RegistrationType.ATTENDEE)
.where(
EventRegistrationAlias.event_id == event_id,
EventRegistrationAlias.registration_type == RegistrationType.ATTENDEE,
)
)

# Statement to determine number of rows in query result
Expand All @@ -579,7 +581,10 @@ def get_registered_users_of_event(
.join(
EventRegistrationAlias, EventRegistrationAlias.user_id == UserEntity.id
)
.where(EventRegistrationAlias.event_id == event_id, EventRegistrationAlias.registration_type == RegistrationType.ATTENDEE)
.where(
EventRegistrationAlias.event_id == event_id,
EventRegistrationAlias.registration_type == RegistrationType.ATTENDEE,
)
)

# Filter results by query
Expand Down
4 changes: 0 additions & 4 deletions backend/test/services/event/event_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def date_maker(days_in_future: int, hour: int, minutes: int) -> datetime.datetim
description="Mark your calendars for the 2023 Carolina Data Challenge (CDC)! CDC is UNC's weekend-long datathon that brings together hundreds of participants from across campus, numerous corporate sponsors, tons of free food as well as merch, and hundreds of dollars of prizes!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cads.id,
)

Expand All @@ -63,7 +62,6 @@ def date_maker(days_in_future: int, hour: int, minutes: int) -> datetime.datetim
description="This is a sample description.",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id,
)

Expand All @@ -74,7 +72,6 @@ def date_maker(days_in_future: int, hour: int, minutes: int) -> datetime.datetim
description="HackNC is a weekend for students of all skill levels to broaden their talents. Your challenge is to make an awesome project in just 24 hours. You will have access to hands-on tech workshops, sponsor networking, as well as exciting talks about the awesome things happening right now with computer science and technology - not to mention all of the free food, shirts, stickers, and swag! We are the largest hackathon in the southeastern United States.",
public=True,
registration_limit=50,
can_register=True,
organization_id=hacknc.id,
)

Expand All @@ -85,7 +82,6 @@ def date_maker(days_in_future: int, hour: int, minutes: int) -> datetime.datetim
description="If you are interested in web scraping, come out to learn!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cads.id,
)

Expand Down
10 changes: 4 additions & 6 deletions backend/test/services/event/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,9 @@ def test_get_registered_users_of_event(event_svc_integration: EventService):
root, event_one.id, pagination_params
)

assert len(page.items) == 2
assert page.length == 2
assert len(page.items) == 1
assert page.length == 1
assert page.items[0].id == ambassador.id
assert page.items[1].id == user.id


def test_organizer_get_registered_users_of_event(event_svc_integration: EventService):
Expand All @@ -505,10 +504,9 @@ def test_organizer_get_registered_users_of_event(event_svc_integration: EventSer
user, event_one.id, pagination_params
)

assert len(page.items) == 2
assert page.length == 2
assert len(page.items) == 1
assert page.length == 1
assert page.items[0].id == ambassador.id
assert page.items[1].id == user.id


def test_organizer_get_registered_users_of_event_filtered(
Expand Down
10 changes: 0 additions & 10 deletions backend/test/services/event/event_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
description="Mark your calendars for the 2023 Carolina Data Challenge (CDC)! CDC is UNC's weekend-long datathon that brings together hundreds of participants from across campus, numerous corporate sponsors, tons of free food as well as merch, and hundreds of dollars of prizes!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
)

Expand All @@ -41,7 +40,6 @@
description="This is a sample description.",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
)

Expand All @@ -53,7 +51,6 @@
description="This is a sample description.",
public=True,
registration_limit=1,
can_register=True,
organization_id=cssg.id | 0,
)

Expand All @@ -66,7 +63,6 @@
description="This is a sample description.",
public=True,
registration_limit=50,
can_register=True,
organization_id=cads.id | 0,
organizers=[
EventOrganizer(
Expand All @@ -88,7 +84,6 @@
description="This is a sample description.",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
)

Expand All @@ -100,7 +95,6 @@
description="Mark your calendars for the 2023 Carolina Data Challenge (CDC)! CDC is UNC's weekend-long datathon that brings together hundreds of participants from across campus, numerous corporate sponsors, tons of free food as well as merch, and hundreds of dollars of prizes!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
organizers=[
EventOrganizer(
Expand All @@ -122,7 +116,6 @@
description="Mark your calendars for the 2023 Carolina Data Challenge (CDC)! CDC is UNC's weekend-long datathon that brings together hundreds of participants from across campus, numerous corporate sponsors, tons of free food as well as merch, and hundreds of dollars of prizes!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
organizers=[
EventOrganizer(
Expand Down Expand Up @@ -152,7 +145,6 @@
description="Come join us for a new workshop!",
public=True,
registration_limit=50,
can_register=True,
organization_id=cssg.id | 0,
)

Expand All @@ -164,7 +156,6 @@
description="This is a sample description.",
public=True,
registration_limit=1,
can_register=True,
organization_id=cssg.id | 0,
organizers=[
EventOrganizer(
Expand Down Expand Up @@ -202,7 +193,6 @@
description="This is a sample description.",
public=True,
registration_limit=1,
can_register=True,
organization_id=cssg.id | 0,
organizers=[
EventOrganizer(
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/app/event/event-editor/event-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class EventEditorComponent {
description: this.description,
public: this.public.value! == 'true',
registration_limit: this.registration_limit,
can_register: this.registration_limit.value! > 0,
userLookup: ''
});

Expand Down Expand Up @@ -129,7 +128,6 @@ export class EventEditorComponent {
description: this.event.description,
public: this.event.public,
registration_limit: this.event.registration_limit,
can_register: this.event.can_register,
userLookup: ''
});

Expand Down Expand Up @@ -211,7 +209,6 @@ export class EventEditorComponent {

// Set fields not explicitly in form
this.event.organizers = this.organizers;
this.event.can_register = this.event.registration_limit > 0;

if (this.event.id == null) {
this.eventService.createEvent(this.event).subscribe({
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/app/event/event.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface Event {
description: string;
public: boolean;
registration_limit: number;
can_register: boolean;
organization_id: number | null;
organization: Organization | null;
registration_count: number;
Expand All @@ -41,7 +40,6 @@ export interface EventJson {
description: string;
public: boolean;
registration_limit: number;
can_register: boolean;
organization_id: number | null;
organization: Organization | null;
registration_count: number;
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/event/event.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const eventDetailResolver: ResolveFn<Event | undefined> = (
description: '',
public: true,
registration_limit: 0,
can_register: false,
organization_id: null,
organization: null,
registration_count: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@
</div>

<!-- Register Button -->
<div class="registration-information" *ngIf="profile && event.can_register">
<div
class="registration-information"
*ngIf="profile && event.registration_limit > 0">
<mat-divider class="padded-divider" />
<p>
<strong>Seats Remaining:</strong>
Expand Down

0 comments on commit 299c7ec

Please sign in to comment.