Skip to content

Commit

Permalink
Everything Works?
Browse files Browse the repository at this point in the history
  • Loading branch information
jontyms committed May 27, 2024
1 parent 81c3e51 commit 5093ef0
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 136 deletions.
9 changes: 7 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from urllib.parse import urlparse

import requests

# FastAPI
from fastapi import Cookie, Depends, FastAPI, Request, Response, status
from fastapi.responses import FileResponse, RedirectResponse
Expand All @@ -17,19 +18,23 @@
from sqlmodel import Session, select

# Import data types
from app.models.user import (DiscordModel, EthicsFormModel, UserModel,
user_to_dict)
from app.models.user import DiscordModel, EthicsFormModel, UserModel, user_to_dict

# Import routes
from app.routes import admin, api, infra, stripe, wallet
from app.util.approve import Approve

# Import middleware
from app.util.authentication import Authentication
from app.util.database import get_session, init_db

# Import error handling
from app.util.errors import Errors
from app.util.forms import Forms

# Import the page rendering library
from app.util.kennelish import Kennelish

# Import options
from app.util.settings import Settings

Expand Down
144 changes: 78 additions & 66 deletions app/migrations/versions/b4cd696ddc31_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,104 @@
Create Date: 2024-05-26 08:57:17.927834
"""

from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'b4cd696ddc31'
revision: str = "b4cd696ddc31"
down_revision: Union[str, None] = None
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.create_table('usermodel',
sa.Column('id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column('discord_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('ucf_id', sa.Integer(), nullable=True),
sa.Column('nid', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('ops_email', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('infra_email', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('minecraft', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('github', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('first_name', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('surname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('is_returning', sa.Boolean(), nullable=True),
sa.Column('gender', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('major', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('class_standing', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('shirt_size', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('did_get_shirt', sa.Boolean(), nullable=True),
sa.Column('time_availability', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('phone_number', sa.Integer(), nullable=True),
sa.Column('sudo', sa.Boolean(), nullable=True),
sa.Column('did_pay_dues', sa.Boolean(), nullable=True),
sa.Column('join_date', sa.Integer(), nullable=True),
sa.Column('mentor_name', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('is_full_member', sa.Boolean(), nullable=True),
sa.Column('can_vote', sa.Boolean(), nullable=True),
sa.Column('experience', sa.Integer(), nullable=True),
sa.Column('curiosity', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('c3_interest', sa.Boolean(), nullable=True),
sa.Column('attending', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('comments', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('discord_id'),
sa.UniqueConstraint('nid'),
sa.UniqueConstraint('ucf_id')
op.create_table(
"usermodel",
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column("discord_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("ucf_id", sa.Integer(), nullable=True),
sa.Column("nid", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("ops_email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("infra_email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("minecraft", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("github", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("first_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("surname", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("is_returning", sa.Boolean(), nullable=True),
sa.Column("gender", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("major", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("class_standing", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("shirt_size", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("did_get_shirt", sa.Boolean(), nullable=True),
sa.Column(
"time_availability", sqlmodel.sql.sqltypes.AutoString(), nullable=True
),
sa.Column("phone_number", sa.Integer(), nullable=True),
sa.Column("sudo", sa.Boolean(), nullable=True),
sa.Column("did_pay_dues", sa.Boolean(), nullable=True),
sa.Column("join_date", sa.Integer(), nullable=True),
sa.Column("mentor_name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("is_full_member", sa.Boolean(), nullable=True),
sa.Column("can_vote", sa.Boolean(), nullable=True),
sa.Column("experience", sa.Integer(), nullable=True),
sa.Column("curiosity", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("c3_interest", sa.Boolean(), nullable=True),
sa.Column("attending", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("comments", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("discord_id"),
sa.UniqueConstraint("nid"),
sa.UniqueConstraint("ucf_id"),
)
op.create_table('discordmodel',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('mfa', sa.Boolean(), nullable=True),
sa.Column('avatar', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('banner', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('color', sa.Integer(), nullable=True),
sa.Column('nitro', sa.Integer(), nullable=True),
sa.Column('locale', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('username', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['usermodel.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"discordmodel",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("mfa", sa.Boolean(), nullable=True),
sa.Column("avatar", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("banner", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("color", sa.Integer(), nullable=True),
sa.Column("nitro", sa.Integer(), nullable=True),
sa.Column("locale", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("username", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
sa.ForeignKeyConstraint(
["user_id"],
["usermodel.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table('ethicsformmodel',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('hack_others', sa.Boolean(), nullable=True),
sa.Column('hack_ucf', sa.Boolean(), nullable=True),
sa.Column('interrupt_ucf', sa.Boolean(), nullable=True),
sa.Column('manip_traffic', sa.Boolean(), nullable=True),
sa.Column('bypass_dhcp', sa.Boolean(), nullable=True),
sa.Column('pirate', sa.Boolean(), nullable=True),
sa.Column('host_at_ucf', sa.Boolean(), nullable=True),
sa.Column('cloud_aup', sa.Boolean(), nullable=True),
sa.Column('signtime', sa.Integer(), nullable=True),
sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['usermodel.id'], ),
sa.PrimaryKeyConstraint('id')
op.create_table(
"ethicsformmodel",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("hack_others", sa.Boolean(), nullable=True),
sa.Column("hack_ucf", sa.Boolean(), nullable=True),
sa.Column("interrupt_ucf", sa.Boolean(), nullable=True),
sa.Column("manip_traffic", sa.Boolean(), nullable=True),
sa.Column("bypass_dhcp", sa.Boolean(), nullable=True),
sa.Column("pirate", sa.Boolean(), nullable=True),
sa.Column("host_at_ucf", sa.Boolean(), nullable=True),
sa.Column("cloud_aup", sa.Boolean(), nullable=True),
sa.Column("signtime", sa.Integer(), nullable=True),
sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
sa.ForeignKeyConstraint(
["user_id"],
["usermodel.id"],
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('ethicsformmodel')
op.drop_table('discordmodel')
op.drop_table('usermodel')
op.drop_table("ethicsformmodel")
op.drop_table("discordmodel")
op.drop_table("usermodel")
# ### end Alembic commands ###
11 changes: 6 additions & 5 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,13 @@ class UserModelMutable(BaseModel):
discord: Optional[DiscordModel] = None
ethics_form: Optional[EthicsFormModel] = None


class PublicContact(BaseModel):
first_name: str
surname: str
ops_email: str





def user_to_dict(model):
if model is None:
return None
Expand All @@ -165,7 +163,11 @@ def user_to_dict(model):
for key, value in model.__dict__.items():
if isinstance(value, (SQLModel, BaseModel)):
data[key] = user_to_dict(value)
elif isinstance(value, list) and value and isinstance(value[0], (SQLModel, BaseModel)):
elif (
isinstance(value, list)
and value
and isinstance(value[0], (SQLModel, BaseModel))
):
data[key] = user_to_dict(value)
return data

Expand All @@ -186,7 +188,6 @@ def user_update_instance(instance: SQLModel, data: dict[str, Any]) -> None:
setattr(instance, key, value)



# Removed unneeded functionality

# class CyberLabModel(SQLModel, table=True):
Expand Down
9 changes: 6 additions & 3 deletions app/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from sqlalchemy.orm import selectinload
from sqlmodel import Session, select

from app.models.user import (UserModel, UserModelMutable, user_to_dict,
user_update_instance)
from app.models.user import (
UserModel,
UserModelMutable,
user_to_dict,
user_update_instance,
)
from app.util.approve import Approve
from app.util.authentication import Authentication
from app.util.database import get_session
Expand Down Expand Up @@ -270,7 +274,6 @@ async def admin_list(
user = user_to_dict(user)
data.append(user)


return {"data": data}


Expand Down
21 changes: 12 additions & 9 deletions app/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
from sqlmodel import Session, SQLModel, select

from app.models.info import InfoModel
from app.models.user import (EthicsFormModel, PublicContact, UserModel,
UserModelMutable, user_to_dict,
user_update_instance)
from app.models.user import (
EthicsFormModel,
PublicContact,
UserModel,
UserModelMutable,
user_to_dict,
user_update_instance,
)
from app.util import kennelish
from app.util.authentication import Authentication
from app.util.database import get_session
Expand Down Expand Up @@ -94,14 +99,14 @@ async def get_form(num: str):
"""


#@router.post("/form/ethics_form_midway")
#@Authentication.member
#async def post_ethics_form(
# @router.post("/form/ethics_form_midway")
# @Authentication.member
# async def post_ethics_form(
# request: Request,
# token: Optional[str] = Cookie(None),
# user_jwt: Optional[object] = {},
# session: Session = Depends(get_session),
#):
# ):
# try:
# ethics_form_data = EthicsFormUpdate.model_validate(await request.json())
# except json.JSONDecodeError:
Expand Down Expand Up @@ -162,7 +167,6 @@ async def post_form(
# Transform the dictionary
validated_data = transform_dict(validated_data)


statement = (
select(UserModel)
.where(UserModel.id == user_jwt["id"])
Expand All @@ -174,7 +178,6 @@ async def post_form(
if not user:
raise HTTPException(status_code=422, detail="User not found")


user_update_instance(user, validated_data)

# Save the updated model back to the database
Expand Down
Loading

0 comments on commit 5093ef0

Please sign in to comment.