Skip to content

Commit

Permalink
Event password is editable. \n If email is provided, event details se…
Browse files Browse the repository at this point in the history
…nt on save. Migrations done.
  • Loading branch information
csrubin committed Feb 27, 2024
1 parent 7ee1319 commit c6d6510
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""rename event password
"""rename pw and add email
Revision ID: 1216a96fe98b
Revision ID: 6bf5d0febdb0
Revises: 4b5f97fcf539
Create Date: 2024-02-27 10:38:56.058806
Create Date: 2024-02-27 13:45:48.810034
"""
from typing import Sequence, Union
Expand All @@ -12,24 +12,22 @@
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "1216a96fe98b"
revision: str = "6bf5d0febdb0"
down_revision: Union[str, None] = "4b5f97fcf539"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# op.add_column('events', sa.Column('event_password', sa.String(length=100), nullable=True))
# op.drop_column('events', 'auth_token')
op.add_column("events", sa.Column("email", sa.String(length=100), nullable=True))
op.alter_column("events", "auth_token", new_column_name="event_password")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# op.add_column('events', sa.Column('auth_token', sa.VARCHAR(length=100), autoincrement=False, nullable=True))
# op.drop_column('events', 'event_password')
op.add_column("events", sa.Column("auth_token", sa.VARCHAR(length=100), autoincrement=False, nullable=True))
op.alter_column("events", "event_password", new_column_name="auth_token")

op.drop_column("events", "email")
# ### end Alembic commands ###
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ version: '3'

services:
web:
env_file:
- .env
build: .
volumes:
- ./how2meet:/app/how2meet
Expand Down
3 changes: 2 additions & 1 deletion how2meet/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ class Event(Base):
__tablename__ = "events"

id = Column(Uuid, primary_key=True, index=True, default=uuid4)
event_password = Column(String(100))
name = Column(String(150), nullable=False)
organizer = Column(String(100))
email = Column(String(100)) # TODO: Add email validation?
created = Column(DateTime)
start_time = Column(DateTime)
end_time = Column(DateTime)
all_day = Column(Boolean)
location = Column(String(150))
description = Column(String(500))
event_password = Column(String(100))
guests = relationship("Guest", primaryjoin="Event.id == Guest.event_id", cascade="all, delete-orphan")

def __repr__(self):
Expand Down
7 changes: 5 additions & 2 deletions how2meet/db/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Event(BaseModel):
id: uuid.UUID
name: str
organizer: str
email: str
created: datetime
start_time: datetime
end_time: datetime
Expand All @@ -32,20 +33,22 @@ class Config:


class EventCreate(Event):
event_password: str
id: Optional[uuid.UUID] = Field(default=None, description="The ID of the event")
event_password: Optional[str] = Field(default=None, description="The password of the event")


class EventUpdate(Event):
event_password: Optional[str] = Field(default=None, description="The password of the event")
id: Optional[uuid.UUID] = Field(default=None, description="The ID of the event")
name: Optional[str] = Field(default=None, description="The name of the event")
organizer: Optional[str] = Field(default=None, description="The organizer of the event")
email: Optional[str] = Field(default=None, description="The email of the event")
created: Optional[datetime] = Field(default=None, description="The creation datetime of the event")
start_time: Optional[datetime] = Field(default=None, description="The start datetime of the event")
end_time: Optional[datetime] = Field(default=None, description="The end datetime of the event")
all_day: Optional[bool] = Field(default=None, description="Whether the event lasts all day")
location: Optional[str] = Field(default=None, description="The location of the event")
description: Optional[str] = Field(default=None, description="The description of the event")
event_password: Optional[str] = Field(default=None, description="The password of the event")


class EventDelete(BaseModel):
Expand Down
8 changes: 4 additions & 4 deletions how2meet/routers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_event(event: schemas.EventCreate, db: Session = Depends(get_db)) -> m
Args:
event: The event to be created.
db: The database session. Defaults to Depends(get_db).
db: The database session. Defaults to Depends(geft_db).
Returns:
models.Event: The created event.
Expand Down Expand Up @@ -51,7 +51,7 @@ def read_events(skip: int = 0, limit: int = 100, db: Session = Depends(get_db))
"""
events = crud.get_events(db, skip=skip, limit=limit)
for event in events:
del event.auth_token
del event.event_password
return events


Expand Down Expand Up @@ -88,7 +88,7 @@ def delete_event(event_id: uuid.UUID, event_delete: schemas.EventDelete, db: Ses
db_event = crud.get_event(db, event_id=event_id)
if db_event is None:
raise HTTPException(status_code=404, detail="Event not found")
if event_delete.auth_token != db_event.auth_token:
if event_delete.event_password != db_event.event_password:
raise HTTPException(status_code=403, detail="Unauthorized")
db.delete(db_event)
db.commit()
Expand All @@ -111,7 +111,7 @@ def update_event(event_id: uuid.UUID, updated_event: schemas.EventUpdate, db: Se
db_event = crud.get_event(db, event_id=event_id)
if db_event is None:
raise HTTPException(status_code=404, detail="Event not found")
if updated_event.auth_token != db_event.auth_token:
if updated_event.event_password != db_event.event_password:
raise HTTPException(status_code=403, detail="Unauthorized")
updated_event = crud.update_event(db, db_event, updated_event)
return updated_event
Expand Down
Loading

0 comments on commit c6d6510

Please sign in to comment.