Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medieteknik | v1.6 #318

Merged
merged 57 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6727f1d
Merge pull request #317 from medieteknik-kth/master
BeastlyMC956 Sep 16, 2024
a53108f
[backend] Can delete events
BeastlyMC956 Sep 16, 2024
23bb487
[frontend] Moved to Vercel for hosting.
BeastlyMC956 Sep 16, 2024
996834b
[frontend] Improved Performance
BeastlyMC956 Sep 16, 2024
fe8663a
[frontend] UI Adjustments
BeastlyMC956 Sep 16, 2024
e3de1c3
[frontend] Improved Provider
BeastlyMC956 Sep 16, 2024
fe4bb8a
[frontend] New Graphical Identity Page
BeastlyMC956 Sep 21, 2024
f8fb2a4
[frontend] Renamed `Head` to `HeadComponent`
BeastlyMC956 Oct 1, 2024
2af6f52
[project] Search function for documents
BeastlyMC956 Oct 1, 2024
b4e3116
[frontend] UI Adjustments
BeastlyMC956 Oct 1, 2024
86e9a45
[frontend] Separated forms for Accounts
BeastlyMC956 Oct 1, 2024
af13c90
[frontend] Custom titles
BeastlyMC956 Oct 1, 2024
182ef2d
[frontend] Adjustments
BeastlyMC956 Oct 1, 2024
52d1014
[backend] Student Profiles
BeastlyMC956 Oct 1, 2024
39d8f9a
[frontend] Improvements to Article Creation
BeastlyMC956 Oct 4, 2024
8888eec
[project] Removing files and added `settings.json`
BeastlyMC956 Oct 5, 2024
a465b67
[frontend] Changed how the news `slug` URL
BeastlyMC956 Oct 7, 2024
4272e83
[backend] Added hidden column to committees
BeastlyMC956 Oct 9, 2024
7c62f72
[frontend] UI Adjustments
BeastlyMC956 Oct 9, 2024
86280d6
[frontend] Updated Committee Model
BeastlyMC956 Oct 9, 2024
2373cc6
[frontend] Adjusted Config files
BeastlyMC956 Oct 9, 2024
92cb8ed
[frontend] Initial tests
BeastlyMC956 Oct 9, 2024
46facf7
[frontend] I18n changes
BeastlyMC956 Oct 9, 2024
5876bae
[frontend] More improvements to Articles
BeastlyMC956 Oct 9, 2024
72c57ac
[frontend] Profiles now work
BeastlyMC956 Oct 9, 2024
c356868
[frontend] Improved Login Page
BeastlyMC956 Oct 14, 2024
dc385ee
[frontend] Up-to-date manifest
BeastlyMC956 Oct 15, 2024
12c0d8f
[frontend] Separate zod schemas
BeastlyMC956 Oct 15, 2024
5525105
[project] New positions page
BeastlyMC956 Oct 15, 2024
bfb6eb2
[backend] Upload and Delete News
BeastlyMC956 Oct 18, 2024
2eabe23
[backend] Functioning Media and bug fixes
BeastlyMC956 Oct 18, 2024
5d437ae
[frontend] Improvement of the Bulletin board
BeastlyMC956 Oct 18, 2024
32c08f4
[frontend] Small tweaks
BeastlyMC956 Oct 18, 2024
7b41f87
[frontend] Improved Header
BeastlyMC956 Oct 21, 2024
c7e2876
[frontend] Cleanup
BeastlyMC956 Oct 21, 2024
641f161
[frontend] Initial media page
BeastlyMC956 Oct 21, 2024
3e2fa51
[frontend] Disabled the explore more section
BeastlyMC956 Oct 21, 2024
7bd4687
[backend] Bugfixes
BeastlyMC956 Oct 21, 2024
ddd08d5
[frontend] Config adjustments
BeastlyMC956 Oct 21, 2024
d9dd3dc
[frontend] Update to Next.js v15 ✨
BeastlyMC956 Oct 22, 2024
75e9e18
[frontend] Changes to cookie UI
BeastlyMC956 Oct 22, 2024
c90ff65
[frontend] Improved Account Page
BeastlyMC956 Oct 22, 2024
93b0675
[frontend] Added Translations to legal
BeastlyMC956 Oct 23, 2024
89644ad
[frontend] Added ESLint v9 back
BeastlyMC956 Oct 24, 2024
d061847
[backend] Had to fallback to port 8080
BeastlyMC956 Oct 24, 2024
0bd01a8
[backend] Albums!
BeastlyMC956 Oct 24, 2024
db9509d
[project] Fully functioning Media page
BeastlyMC956 Oct 25, 2024
93631e1
[backend] New Document routes
BeastlyMC956 Oct 25, 2024
899ed85
[frontend] More Translations and bug fixes
BeastlyMC956 Oct 25, 2024
5f12f62
[backend] Removed some dependencies
BeastlyMC956 Oct 27, 2024
cb6e654
[project] Intercepting modal login page
BeastlyMC956 Oct 27, 2024
51000f1
[frontend] UI/UX adjustments
BeastlyMC956 Oct 27, 2024
e502699
[backend] Can delete recruitments
BeastlyMC956 Oct 27, 2024
a8dee65
[frontend] UI and delete recruitment
BeastlyMC956 Oct 27, 2024
2fc1bba
[backend] Small Adjustments
BeastlyMC956 Oct 29, 2024
c3f9c01
[frontend] Minor adjustments for many files
BeastlyMC956 Oct 29, 2024
0642ce9
[project] Small fixes
BeastlyMC956 Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 0 additions & 25 deletions .github/workflows/firebase-hosting-pull-request.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Tests
on:
push:
branches: master
pull_request:
branches: master
jobs:
jest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Run Jest
run: npm run test
4 changes: 4 additions & 0 deletions backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "off"
}
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ COPY . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
COPY env/service-account-file.json /app/service-account-file.json

# Expose port 80
EXPOSE 80
# Expose port 8080
EXPOSE 8080

# Run the application with gunicorn
CMD ["gunicorn", "main:app"]
3 changes: 1 addition & 2 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
container_name: medieteknik_web
build: .
ports:
- "80:80"
- "8080:8080"
environment:
- DATABASE_URL=${DATABASE_URL}
depends_on:
Expand All @@ -19,7 +19,6 @@ services:
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

volumes:
postgres-data:
Expand Down
4 changes: 2 additions & 2 deletions backend/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from dotenv import load_dotenv

loglevel = os.environ.get("LOG_LEVEL", "info")
workers = 3 * round(multiprocessing.cpu_count() / 2) + 1
bind = "0.0.0.0:80"
workers = multiprocessing.cpu_count() + 1
bind = "0.0.0.0:8080"
timeout = 120

env = os.path.join(os.getcwd(), ".env")
Expand Down
2 changes: 2 additions & 0 deletions backend/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from models.content import (
Album, # noqa: F401
AlbumTranslation, # noqa: F401
Media, # noqa: F401
MediaTranslation, # noqa: F401
Author, # noqa: F401
Document, # noqa: F401
DocumentTranslation, # noqa: F401
Expand Down
1 change: 0 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
},
)

# OIDC
oidc.init_app(app)

# Register routes (blueprints)
Expand Down
5 changes: 3 additions & 2 deletions backend/models/committees/committee.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from typing import Any, Dict, List
from sqlalchemy import String, Integer, Column, ForeignKey, inspect, text
from sqlalchemy import Boolean, String, Integer, Column, ForeignKey, inspect, text
from sqlalchemy.dialects.postgresql import UUID
from utility.database import db
from utility.constants import AVAILABLE_LANGUAGES
Expand All @@ -22,6 +22,8 @@ class Committee(db.Model):
total_news = Column(Integer, nullable=False, default=0)
total_events = Column(Integer, nullable=False, default=0)
total_documents = Column(Integer, nullable=False, default=0)
total_media = Column(Integer, nullable=False, default=0)
hidden = Column(Boolean, nullable=False, default=False)

# Foreign key
committee_category_id = Column(
Expand Down Expand Up @@ -70,7 +72,6 @@ def to_dict(
)
translations.append(translation)

del data["committee_id"]
del data["committee_category_id"]

data["translations"] = [
Expand Down
6 changes: 4 additions & 2 deletions backend/models/committees/committee_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def to_dict(
del data["committee_id"]

data["translations"] = [
translation.to_dict() for translation in set(translations)
translation.to_dict()
for translation in set(translations)
if translation is not None
]

if is_public_route:
Expand Down Expand Up @@ -262,7 +264,7 @@ def to_dict(self, provided_languages: List[str] = AVAILABLE_LANGUAGES):
del data["committee_position_recruitment_id"]

committee_position = CommitteePosition.query.get(data["committee_position_id"])
del data["committee_position_id"]
del data["committee_position_id"]

if not committee_position or not isinstance(
committee_position, CommitteePosition
Expand Down
3 changes: 3 additions & 0 deletions backend/models/content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from .album import Album, AlbumTranslation
from .media import Media, MediaTranslation
from .author import Author, AuthorResource, AuthorType
from .base import Item, PublishedStatus
from .calendar import Calendar
Expand All @@ -14,6 +15,8 @@
__all__ = [
"Album",
"AlbumTranslation",
"Media",
"MediaTranslation",
"Author",
"AuthorResource",
"AuthorType",
Expand Down
88 changes: 48 additions & 40 deletions backend/models/content/album.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
from typing import List
import uuid
from sqlalchemy.dialects.postgresql import ARRAY, UUID
from sqlalchemy import Column, ForeignKey, Integer, String, inspect
from sqlalchemy.dialects.postgresql import TIMESTAMP
from sqlalchemy import (
UUID,
Column,
ForeignKey,
Integer,
String,
func,
inspect,
text,
)
from models.content.media import Media
from utility.constants import AVAILABLE_LANGUAGES
from utility.translation import get_translation
from utility.database import db
from models.content.base import Item


class Album(Item):
"""
Album model which inherits from the base Item model

Attributes:
album_id: Primary key
media_urls: List of media URLs (images, videos, etc.)
"""
from utility.translation import get_translation

album_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)

media_urls = Column(ARRAY(String))
class Album(db.Model):
__tablename__ = "album"

# Foreign keys
item_id = Column(UUID(as_uuid=True), ForeignKey("item.item_id"))
album_id = Column(
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
server_default=text("gen_random_uuid()"),
)
total_images = Column(Integer, default=0)
total_videos = Column(Integer, default=0)
preview_media_id = Column(UUID(as_uuid=True))
updated_at = Column(TIMESTAMP, default=func.now(), server_default=text("now()"))

# Relationships
item = db.relationship("Item", back_populates="album")
translations = db.relationship("AlbumTranslation", back_populates="album")
media = db.relationship("Media", back_populates="album", passive_deletes=True)

__mapper_args__ = {"polymorphic_identity": "album"}

def to_dict(
self, provided_languages: List[str] = AVAILABLE_LANGUAGES, is_public_route=True
):
base_data = super().to_dict(
provided_languages=provided_languages, is_public_route=is_public_route
)

if not base_data:
return {}

translations = []
def to_dict(self, provided_languages: List[str] = AVAILABLE_LANGUAGES):
data = {}
translations: List[AlbumTranslation] = []

for language_code in provided_languages:
translation = get_translation(
Expand All @@ -51,23 +48,34 @@ def to_dict(
)
translations.append(translation)

del base_data["album_id"]
data["translations"] = [translation.to_dict() for translation in translations]
data["album_id"] = self.album_id
data["total_images"] = self.total_images
data["total_videos"] = self.total_videos
data["updated_at"] = self.updated_at

base_data["media_urls"] = self.media_urls
base_data["translations"] = [
translation.to_dict() for translation in translations
]
if self.preview_media_id:
media: Media | None = Media.query.filter_by(
media_id=self.preview_media_id
).first()

return base_data
if not media:
data["preview_media"] = None

data["preview_media"] = media.to_dict(provided_languages=provided_languages)

return data


class AlbumTranslation(db.Model):
__tablename__ = "album_translation"

album_translation_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
album_translation_id = Column(
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)

title = Column(String(255))
description = Column(String(2500))
description = Column(String(512))

# Foreign keys
album_id = Column(UUID(as_uuid=True), ForeignKey("album.album_id"))
Expand Down
4 changes: 2 additions & 2 deletions backend/models/content/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Item(db.Model):
created_at = Column(DateTime, default=func.now(), server_default=func.now())
last_updated = Column(
DateTime,
default=datetime.now(timezone.utc),
default=func.now(),
onupdate=datetime.now(timezone.utc),
)
categories = Column(ARRAY(String), default=[])
Expand All @@ -77,7 +77,7 @@ class Item(db.Model):
news = db.relationship("News", back_populates="item", passive_deletes=True)
event = db.relationship("Event", back_populates="item", passive_deletes=True)
document = db.relationship("Document", back_populates="item", passive_deletes=True)
album = db.relationship("Album", back_populates="item", passive_deletes=True)
media = db.relationship("Media", back_populates="item", passive_deletes=True)

# Polymorphism
type = Column(String(50))
Expand Down
4 changes: 1 addition & 3 deletions backend/models/content/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import timedelta
import enum
from textwrap import dedent
from typing import List
Expand Down Expand Up @@ -123,7 +122,6 @@ def to_dict(
if not isinstance(translation, EventTranslation):
return None

del data["event_id"]
del data["calendar_id"]
del data["parent_event_id"]
del data["type"]
Expand Down Expand Up @@ -163,7 +161,7 @@ class EventTranslation(db.Model):
)

title = Column(String(255))
description = Column(String(500))
description = Column(String(1024))
main_image_url = Column(String(length=2096))
sub_image_urls = Column(ARRAY(String))

Expand Down
Loading
Loading