Skip to content

Commit

Permalink
Merge pull request #142 from SELab-2/dev
Browse files Browse the repository at this point in the history
Release 2
  • Loading branch information
reyniersbram authored Apr 18, 2024
2 parents d14f67d + 5e2e59a commit 861bbaf
Show file tree
Hide file tree
Showing 187 changed files with 13,534 additions and 5,661 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ jobs:
run: autopep8 -rd --exit-code backend

pytest:
name: Unit Testing
name: Backend Unit Testing
runs-on: self-hosted
env:
DATABASE_URI: "${{ secrets.POSTGRES_CONNECTION }}"
FRONTEND_URL: "https://localhost:8080"
CAS_SERVER_URL: "https://login.ugent.be"
SECRET_KEY: "test"
ALGORITHM: "HS256"
FILE_PATH: "files"
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12
Expand Down Expand Up @@ -82,6 +83,26 @@ jobs:
working-directory: backend
if: always()
run: alembic downgrade base

vitest:
name: Frontend Unit Testing
runs-on: self-hosted
env:
VITE_APP_URL: https://localhost:8080
VITE_API_URL: http://localhost:5173
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
working-directory: frontend
run: npm install
- name: Run Tests
working-directory: frontend
run: npm run test:unit

pyright:
name: Pyright
runs-on: self-hosted
Expand Down
6 changes: 6 additions & 0 deletions backend/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FRONTEND_URL="https://localhost:8080"
CAS_SERVER_URL="https://login.ugent.be"
DATABASE_URI="postgresql://username:password@url:port/db-name"
SECRET_KEY="test" # e.g. generate with `openssl rand -hex 32`
ALGORITHM="HS256" # algorithm used to sign JWT tokens
FILE_PATH="files"
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
config.yml
.env
.coverage
files
44 changes: 44 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ CAS_SERVER_URL="https://login.ugent.be"
DATABASE_URI="database connection string: postgresql://..., see discord..."
SECRET_KEY="<secret key to sign JWT tokens>" # e.g. generate with `openssl rand -hex 32`
ALGORITHM="HS256" # algorithm used to sign JWT tokens
FILE_PATH="files" # Location where uploaded files are stored
```

### Install docker

To be able to run the automated tests or run a local development database,
follow the installation instructions for either
[docker engine](https://docs.docker.com/engine/install/) (CLI) or [docker desktop](https://www.docker.com/get-started/) (GUI, includes docker engine).

### Usage

#### Activate the environment:
Expand All @@ -39,6 +46,43 @@ source venv/bin/activate

This will start a local development server on port `5173`

## Recommended: run a local instance of the database in a docker container

```sh
# Pull the latest postgres image
docker pull postgres
# Run the postgres deamon in a docker container
docker run --name my_postgres_container \
-p 5432:5432 \
-e POSTGRES_USER=username \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=dbname \
-d \
postgres
```

#### Change this line in `.env` to reflect database connection info
```yml
DATABASE_URI="postgresql://username:password@localhost:5432/dbname"
```

#### Run alembic to initialize the database
```sh
alembic upgrade head
```

#### Managing the database
```sh
# Stop the database container
docker stop my_postgres_container
# Start the database container again
docker start my_postgres_container

# Remove a stopped container
docker rm my_postgres_container
```
If you installed Docker Desktop, you can use the GUI to manage your containers and images.

## The API

## Login
Expand Down
2 changes: 1 addition & 1 deletion backend/alembic/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Generic single-database configuration.
Generic single-database configuration.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Add instructor project table
Revision ID: 20886268d8b4
Revises: fe818acfa209
Create Date: 2024-04-04 22:20:35.996274
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '20886268d8b4'
down_revision: Union[str, None] = 'fe818acfa209'
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('instructor_project',
sa.Column('uid', sa.String(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
['project_id'], ['project.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(
['uid'], ['website_user.uid'], ondelete='CASCADE')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('instructor_project')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""add uuid files and requirements for project
Revision ID: 5011e8183104
Revises: 76859289ea2d
Create Date: 2024-03-27 21:50:17.418154
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '5011e8183104'
down_revision: Union[str, None] = '76859289ea2d'
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('requirement',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('mandatory', sa.Boolean(), nullable=False),
sa.Column('value', sa.String(), nullable=False),
sa.ForeignKeyConstraint(
['project_id'], ['project.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.add_column('submission', sa.Column('files_uuid', sa.String(), nullable=False))
op.drop_constraint('teacher_subject_uid_fkey',
'teacher_subject', type_='foreignkey')
op.drop_constraint('teacher_subject_subject_id_fkey',
'teacher_subject', type_='foreignkey')
op.create_foreign_key('teacher_subject_subject_id_fkey', 'teacher_subject', 'subject', [
'subject_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('teacher_subject_website_user_fkey', 'teacher_subject', 'website_user',
['uid'], ['uid'], ondelete='CASCADE')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('teacher_subject_subject_id_fkey',
'teacher_subject', type_='foreignkey')
op.drop_constraint('teacher_subject_website_user_fkey',
'teacher_subject', type_='foreignkey')
op.create_foreign_key('teacher_subject_subject_id_fkey',
'teacher_subject', 'subject', ['subject_id'], ['id'])
op.create_foreign_key('teacher_subject_uid_fkey',
'teacher_subject', 'website_user', ['uid'], ['uid'])
op.drop_column('submission', 'files_uuid')
op.drop_table('requirement')
# ### end Alembic commands ###
34 changes: 34 additions & 0 deletions backend/alembic/versions/5df13f3f88cc_update_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""update message
Revision ID: 5df13f3f88cc
Revises: ec4231ba1311
Create Date: 2024-04-05 17:11:51.091498
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '5df13f3f88cc'
down_revision: Union[str, None] = 'ec4231ba1311'
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.alter_column('project', 'is_visible',
existing_type=sa.BOOLEAN(),
nullable=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('project', 'is_visible',
existing_type=sa.BOOLEAN(),
nullable=True)
# ### end Alembic commands ###
7 changes: 5 additions & 2 deletions backend/alembic/versions/76859289ea2d_add_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ENUM
from src.submission.models import Status


# revision identifiers, used by Alembic.
Expand All @@ -23,8 +25,7 @@ def upgrade() -> None:
op.create_table('submission',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('date', sa.DateTime(), nullable=False),
sa.Column('status', sa.Enum('InProgress', 'Accepted',
'Denied', name='status'), nullable=False),
sa.Column('status', ENUM(Status, name='status'), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=False),
sa.Column('project_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
Expand All @@ -39,4 +40,6 @@ def upgrade() -> None:
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('submission')
enum = ENUM(Status, name='status')
enum.drop(op.get_bind())
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""is_teacher_boolean_and_instructor
Revision ID: a88aec136b59
Revises: 5011e8183104
Create Date: 2024-04-03 21:47:10.758518
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'a88aec136b59'
down_revision: Union[str, None] = '5011e8183104'
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('instructor_subject',
sa.Column('uid', sa.String(), nullable=True),
sa.Column('subject_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
['subject_id'], ['subject.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(
['uid'], ['website_user.uid'], ondelete='CASCADE')
)
op.drop_table('teacher_subject')
op.add_column('website_user', sa.Column('is_teacher', sa.Boolean(),
nullable=False, server_default=sa.false()))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('website_user', 'is_teacher')
op.create_table('teacher_subject',
sa.Column('uid', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.Column('subject_id', sa.INTEGER(),
autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['subject_id'], ['subject.id'],
name='teacher_subject_subject_id_fkey', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['uid'], ['website_user.uid'],
name='teacher_subject_website_user_fkey', ondelete='CASCADE')
)
op.drop_table('instructor_subject')
# ### end Alembic commands ###
44 changes: 44 additions & 0 deletions backend/alembic/versions/aa8ad1b4f8dc_add_capacity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""add_capacity
Revision ID: aa8ad1b4f8dc
Revises: 5df13f3f88cc
Create Date: 2024-04-05 21:54:32.401866
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'aa8ad1b4f8dc'
down_revision: Union[str, None] = '5df13f3f88cc'
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('project', sa.Column('capacity', sa.Integer(), nullable=False))
op.drop_constraint('student_group_team_id_fkey',
'student_group', type_='foreignkey')
op.drop_constraint('student_group_uid_fkey', 'student_group', type_='foreignkey')
op.create_foreign_key('student_group_team_id_fkey', 'student_group', 'team', [
'team_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('student_group_uid_fkey', 'student_group', 'website_user',
['uid'], ['uid'], ondelete='CASCADE')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('student_group_team_id_fkey',
'student_group', type_='foreignkey')
op.drop_constraint('student_group_uid_fkey', 'student_group', type_='foreignkey')
op.create_foreign_key('student_group_uid_fkey', 'student_group',
'website_user', ['uid'], ['uid'])
op.create_foreign_key('student_group_team_id_fkey',
'student_group', 'team', ['team_id'], ['id'])
op.drop_column('project', 'capacity')
# ### end Alembic commands ###
Loading

0 comments on commit 861bbaf

Please sign in to comment.