Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #593 from SELab-2/develop
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
stijndcl authored May 22, 2022
2 parents 43715d4 + 929f9e0 commit 8a6324f
Show file tree
Hide file tree
Showing 416 changed files with 18,490 additions and 7,866 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/backend"
open-pull-requests-limit: 100
schedule:
interval: weekly
- package-ecosystem: npm
directory: "/frontend"
open-pull-requests-limit: 100
schedule:
interval: weekly
9 changes: 8 additions & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ jobs:
path: /usr/local/lib/python3.10/site-packages
key: venv-${{ runner.os }}-bullseye-3.10.2-v2-${{ hashFiles('**/poetry.lock') }}

- run: python -m pytest
- run: |
python -m coverage run -m pytest
python -m coverage xml
- run: apt update && apt install -y git
- name: Code Coverage
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV }}

Lint:
needs: [Test]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# OSOC-3

[![codecov](https://codecov.io/gh/SELab-2/OSOC-3/branch/develop/graph/badge.svg?token=gzlDMtycUN)](https://codecov.io/gh/SELab-2/OSOC-3)

## Table of Contents

[User manual](#user-manual)
Expand Down
8 changes: 6 additions & 2 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ DB_PORT=3306
# Can be generated using "openssl rand -hex 32"
SECRET_KEY=4d16a9cc83d74144322e893c879b5f639088c15dc1606b11226abbd7e97f5ee5
# The ACCESS JWT token should be valid for ...
ACCESS_TOKEN_EXPIRE_M = 5
ACCESS_TOKEN_EXPIRE_M=5
# The REFRESH JWT token should be valid for ...
REFRESH_TOKEN_EXPIRE_M = 2880
REFRESH_TOKEN_EXPIRE_M=2880

# GitHub OAuth
GITHUB_CLIENT_ID=25
GITHUB_CLIENT_SECRET=herebegithubclientsecret

# Frontend
FRONTEND_URL="http://localhost:3000"
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/

# Testing SQLite database
*test.db
/fill_my_database.py
20 changes: 12 additions & 8 deletions backend/create_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
fiddle in the database themselves.
"""
import argparse
import asyncio
import getpass
import sys
import traceback
Expand Down Expand Up @@ -43,25 +44,26 @@ def get_hashed_password() -> str:
return get_password_hash(first_pass)


def create_admin(name: str, email: str, pw: str):
async def create_admin(name: str, email: str, pw: str):
"""Create a new user in the database"""
with DBSession.begin() as session:
async with DBSession() as session:
try:
transaction = session.begin_nested()
user = create_user(session, name, commit=False)
transaction = await session.begin_nested()
user = await create_user(session, name, commit=False)
user.admin = True

# Add an email auth entry
create_auth_email(session, user, pw, email, commit=False)
await create_auth_email(session, user, pw, email, commit=False)
await session.commit()
except sqlalchemy.exc.SQLAlchemyError:
# Something went wrong: rollback the transaction & print the error
transaction.rollback()
await transaction.rollback()

# Print the traceback of the exception
print(traceback.format_exc())
exit(3)

session.close()
await session.close()


if __name__ == "__main__":
Expand All @@ -83,6 +85,8 @@ def create_admin(name: str, email: str, pw: str):
pw_hash = get_hashed_password()

# Create new database entry
create_admin(args.name, args.email, pw_hash)
loop = asyncio.new_event_loop()
loop.run_until_complete(create_admin(args.name, args.email, pw_hash))
loop.close()

print("Addition successful.")
36 changes: 36 additions & 0 deletions backend/create_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import asyncio
import traceback
from argparse import ArgumentParser

import sqlalchemy.exc
from sqlalchemy.ext.asyncio import AsyncSession

import src.app # Important import - avoids circular import
from src.database.crud import editions
from src.database.crud.webhooks import create_webhook
from src.database.engine import DBSession
from src.database.models import Edition, WebhookURL
from settings import FRONTEND_URL


async def do(args):
session: AsyncSession
async with DBSession() as session:
try:
edition: Edition = await editions.get_edition_by_name(session, args.edition)
webhook_url: WebhookURL = await create_webhook(session, edition)
print(f'WebhookURL created: {FRONTEND_URL}/editions/{edition.name}/webhooks/{webhook_url.uuid}')
except sqlalchemy.exc.SQLAlchemyError:
await session.rollback()
print(traceback.format_exc())
exit(3)


if __name__ == '__main__':
parser = ArgumentParser(description="Add new webhook to edition.")
parser.add_argument("-E", "--edition", type=str, required=True)
args = parser.parse_args()

loop = asyncio.new_event_loop()
loop.run_until_complete(do(args))
loop.close()
31 changes: 17 additions & 14 deletions backend/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from logging.config import fileConfig

from alembic import context
Expand All @@ -21,6 +22,7 @@
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata


# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
Expand Down Expand Up @@ -52,32 +54,33 @@ def run_migrations_offline():
context.run_migrations()


def run_migrations_online():
def do_run_migrations(connection):
context.configure(
connection=connection, target_metadata=target_metadata,
render_as_batch=True
)

with context.begin_transaction():
context.run_migrations()


async def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
#connectable = engine_from_config(
# config.get_section(config.config_ini_section),
# prefix="sqlalchemy.",
# poolclass=pool.NullPool,
#)

connectable = engine

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata,
render_as_batch=True
)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)

with context.begin_transaction():
context.run_migrations()
await connectable.dispose()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
asyncio.run(run_migrations_online())
104 changes: 0 additions & 104 deletions backend/migrations/versions/145816a4b2df_add_form_tables.py

This file was deleted.

24 changes: 0 additions & 24 deletions backend/migrations/versions/1862d7dea4cc_.py

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8a6324f

Please sign in to comment.