Skip to content

Commit

Permalink
Merge pull request #314 from medieteknik-kth/hemsidan-redesign
Browse files Browse the repository at this point in the history
Firebase Init and Cleanup
  • Loading branch information
BoViKa authored Sep 1, 2024
2 parents b415050 + 30a589d commit e6e9e63
Show file tree
Hide file tree
Showing 47 changed files with 1,627 additions and 767 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
on:
pull_request:
push:
branches:
- master
permissions:
checks: write
contents: read
pull-requests: write
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_MEDIETEKNIK }}
projectId: medieteknik
2 changes: 0 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ WORKDIR /app
COPY . /app
COPY env/service-account-file.json /app/service-account-file.json

# Set up the relevant environment variable
ENV GOOGLE_APPLICATION_CREDENTIALS="/app/service-account-file.json"

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
Expand Down
4 changes: 2 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 DateTime, String, Integer, Column, ForeignKey, inspect, text
from sqlalchemy import String, Integer, Column, ForeignKey, inspect, text
from sqlalchemy.dialects.postgresql import UUID
from utility.database import db
from utility.constants import AVAILABLE_LANGUAGES
Expand Down Expand Up @@ -91,7 +91,7 @@ class CommitteeTranslation(db.Model):
)

title = Column(String(125))
description = Column(String(500))
description = Column(String(512))

# Foreign keys
committee_id = Column(UUID(as_uuid=True), ForeignKey("committee.committee_id"))
Expand Down
2 changes: 1 addition & 1 deletion backend/models/committees/committee_category.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from typing import List
from sqlalchemy import String, Integer, Column, ForeignKey, inspect, text
from sqlalchemy import String, Column, ForeignKey, inspect, text
from sqlalchemy.dialects.postgresql import UUID
from utility.database import db
from utility.constants import AVAILABLE_LANGUAGES
Expand Down
16 changes: 9 additions & 7 deletions backend/models/committees/committee_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CommitteePositionCategory(enum.Enum):
NÄRINGSLIV_OCH_KOMMUNIKATION = "NÄRINGSLIV OCH KOMMUNIKATION"
STUDIESOCIALT = "STUDIESOCIALT"
FANBORGEN = "FANBORGEN"
UTBILDNING = "UTBILDNING"


class CommitteePosition(db.Model):
Expand All @@ -43,7 +44,7 @@ class CommitteePosition(db.Model):
server_default=text("gen_random_uuid()"),
)

email = Column(String(255), unique=True)
email = Column(String(255))
weight = Column(Integer, default=1_000)
role = Column(
Enum(CommitteePositionsRole),
Expand Down Expand Up @@ -118,18 +119,19 @@ def to_dict(
]

if is_public_route:
del data["weight"]
del data["role"]

if include_parent:
if include_parent and self.committee_id:
parent_committee = Committee.query.filter_by(
committee_id=self.committee_id
).first()

if parent_committee and isinstance(parent_committee, Committee):
data["committee"] = parent_committee.to_dict(
provided_languages=provided_languages,
)
if not parent_committee or not isinstance(parent_committee, Committee):
return data

data["committee"] = parent_committee.to_dict(
provided_languages=provided_languages,
)

return data

Expand Down
10 changes: 7 additions & 3 deletions backend/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ def index():

@app.route("/api/v1/csrf-token")
def get_csrf_token():
if "csrf_token" not in session:
session["csrf_token"] = generate_csrf()
return jsonify({"token": session["csrf_token"]})
token = session.get("csrf_token")
print(token)
if not token:
new_token = generate_csrf()
session["csrf_token"] = new_token
return jsonify({"token": new_token})
return jsonify({"token": token})

@app.route("/oauth/kth/login")
def kth_login():
Expand Down
4 changes: 2 additions & 2 deletions backend/routes/committee_position_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_committee_position():
data: Dict[str, Any] = json.loads(json.dumps(data))

email = data.get("email")
category: CommitteePositionCategory = data.get("category")
category: str = data.get("category")
weight = data.get("weight")
translations: List[Dict[str, Any]] = data.get("translations")
committee_title = data.get("committee_title")
Expand All @@ -53,7 +53,7 @@ def create_committee_position():

new_position = CommitteePosition(
email=email if email else None,
category=category,
category=None if category == "NONE" else category.replace(" ", "_").upper(),
weight=weight,
active=True,
role=CommitteePositionsRole.COMMITTEE.value,
Expand Down
43 changes: 42 additions & 1 deletion backend/routes/student_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from flask import Blueprint, jsonify, make_response, request
from flask_jwt_extended import (
create_access_token,
get_jwt,
get_jwt_identity,
jwt_required,
current_user,
Expand All @@ -21,7 +20,9 @@
from models.committees.committee_position import CommitteePosition
from models.core.student import Student, StudentMembership
from services.core.student import login, assign_password, get_permissions, update
from utility.gc import delete_file, upload_file
from utility.translation import retrieve_languages
from utility.database import db

student_bp = Blueprint("student", __name__)

Expand Down Expand Up @@ -57,6 +58,46 @@ def update_student():
)


@student_bp.route("/reception", methods=["PUT"])
@csrf_protected
@jwt_required()
def update_reception():
student_id = get_jwt_identity()
student = Student.query.filter_by(student_id=student_id).one_or_none()

if not student or not isinstance(student, Student):
return jsonify({"error": "Invalid credentials"}), 401

reception_image = request.files.get("reception_image")
reception_name = request.form.get("reception_name")

if not reception_image:
return jsonify({"error": "Invalid data"}), 400

file_extension = reception_image.filename.split(".")[-1]

if getattr(student, "reception_profile_picture_url"):
delete_file(
getattr(student, "reception_profile_picture_url"),
)

result = upload_file(
file=reception_image,
file_name=f"{student.student_id}.{file_extension}",
path="profile/reception",
)

if not result:
return jsonify({"error": "Failed to upload"}), 400

setattr(student, "reception_profile_picture_url", result)
setattr(student, "reception_name", reception_name)

db.session.commit()

return jsonify({"url": result}), 201


@student_bp.route("/refresh", methods=["POST"])
@jwt_required(refresh=True)
def refresh_token():
Expand Down
4 changes: 4 additions & 0 deletions backend/services/committees/public/committee_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def get_all_committee_members(
.filter_by(
committee_id=committee.committee_id,
)
.filter(
CommitteePosition.active.is_(True),
StudentMembership.termination_date.is_(None),
)
.join(
Student,
StudentMembership.student_id == Student.student_id,
Expand Down
8 changes: 4 additions & 4 deletions backend/services/content/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ def create_item(
authors_items_ids = []

translation_table = None
if isinstance(item_table, News):
if isinstance(item_table, News) or item_table is News:
authors_items_ids = [a.news_id for a in all_authors_items]
translation_table = NewsTranslation
elif isinstance(item_table, Event):
elif isinstance(item_table, Event) or item_table is Event:
authors_items_ids = [a.event_id for a in all_authors_items]
translation_table = EventTranslation
elif isinstance(item_table, Album):
elif isinstance(item_table, Album) or item_table is Album:
authors_items_ids = [a.album_id for a in all_authors_items]
translation_table = AlbumTranslation
elif isinstance(item_table, Document):
elif isinstance(item_table, Document) or item_table is Document:
authors_items_ids = [a.document_id for a in all_authors_items]
translation_table = DocumentTranslation
else:
Expand Down
20 changes: 18 additions & 2 deletions backend/utility/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ def validate_csrf(csrf_token) -> Response | bool:
return response

if csrf_token != header_csrf_token:
response = make_response(jsonify({"message": "Invalid CSRF Token"}))
response = make_response(
jsonify(
{
"message": "Invalid Header CSRF Token",
"csrf_token": csrf_token,
"header_csrf_token": header_csrf_token,
}
)
)
response.status_code = HTTPStatus.FORBIDDEN
return response

if csrf_token != session_csrf_token:
response = make_response(jsonify({"message": "Invalid CSRF Token"}))
response = make_response(
jsonify(
{
"message": "Invalid Session CSRF Token",
"csrf_token": csrf_token,
"session_csrf_token": session_csrf_token,
}
)
)
response.status_code = HTTPStatus.FORBIDDEN
return response

Expand Down
32 changes: 32 additions & 0 deletions frontend/.firebase/hosting.cHVibGlj.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
index.html,1725154496799,d9d7bc4ab8a92b15cc2009280fe4aea0d497560fe7b84d597ebcd2ad04f7c317
404.html,1725154496712,762bf484ba67404bd1a3b181546ea28d60dfddf18e9dd4795d8d25bcf3c1a890
images/logo.webp,1720431006580,2e2ed372391f67e94e94c4e0fecb24320da557538daa7fb4eabf4b7f411e9681
images/svg/youtube.svg,1710785650591,e9016d78170c690d49d935a91bd81e02a734d4abafc67b0747ae8e803c827aab
images/svg/ths.svg,1717953182261,5b1b5af7e08278a04437bfe6030dfce7ea53232079ad7388f70ee247c90dac8b
images/svg/linkedin.svg,1710787637900,d01bff426eb95b311bccd560e257c1a426d0789b3721b80b8aa6e2223e363a3f
images/svg/mbd.svg,1711051608799,6d486107a644d05cc58f7ecc67eeb6f433540450d21835b17a1cecbf7b972e35
images/svg/medieteknik.svg,1717953208687,20a606c6b0f7ab0fbb9092d9f70c6a76c33a366768dd5ce7cd1a4aade30a10c5
images/svg/instagram.svg,1710785600065,a093432cf165a98aa1a6b49122fe951860ca71dd9d4727a45ca9ec388b39544c
images/cs.jpg,1708855444172,3a8f31249f57a708100ed5e597bbd003e8d706d9a6318436299ccef0934da9ce
images/svg/datateknik.svg,1717954310511,7e222db520ffa91ed3eadfd3fa85812a277a5bf45ae8630d5a98f4306f332c26
images/logobig_light.jpg,1713814110573,25b0591ae761e535a9ef043dd0740647fa78b3df140442cd4390656040e45665
images/logobig_dark.jpg,1714179224566,9d5e1feb5cd3ca7b6a70f0118bf9c159e4f73e6c245dd1c942bf8788bad2d903
images/logobig.png,1710782675272,7bc0f40f5bf714f1b70ccb4fbc1f0a6627afcb3136b2aad436b8ca678294a15a
images/svg/facebook.svg,1710784995921,410040bc378c6c86fd75695f1f2a4eb749ad0ad1c53dfbe451d7f4981960086b
images/ict.jpg,1708856955078,8a840e4b6ca2f83901c1e34ec8abd8fd9802343d39c5fb7dc94443d79ea65ee3
images/sd.jpg,1709014945099,fa0727975b29d57738a268da4e7e262cdcb75b061285bc8ef1b0d39bed9322c7
screenshots/phone.webp,1720428750813,09a5b82e9868b09f5a93ff1398bb8212ec54b74cdd8a64a3db8723de953016c5
images/ml.jpg,1708856962239,8138b0b058ca7752ee40cc32cc4aa25d9d854d5165e4880d5d32e82aafaa6be7
images/svg/kth.svg,1711063787967,04db06aa8f5073b9693efb4ffa236e1df2fca8776a31265bde377c07fb8950d7
images/imt.jpg,1708856946101,503fec3af341c92bfb964b5f7332cd773429e63dfbd059599dcd79a7de1becae
images/KTH.jpg,1711828165385,4f497bda7e0c7f3b997214c01c0dcc389a5546218ff43275ec7a40a75b0bd93f
screenshots/desktop.webp,1720428118145,fb766eed3c7cb6c53358353f3c0d83346d55c386f8b8a543926266ec71872a5b
images/testbg.jpg,1709696850461,02ac934a8ce6cb7efa6917f3c7853e084a969d34d4cd4cf635f53fe983b068c9
images/ths_placeholder.jpg,1709687564492,af2c7227a1247730687e733f1daff25129f7f3ddd4497d2dab6c3afd2f6e2356
images/kth-landskap.jpg,1711819019756,b28a8cb7a0e430bf961ecf7870100d1b83ab8660476a1fca0b36f73aa313d20a
images/kth-landskap.webp,1721805296540,5c9b68ff00d4ea5981d7776bc57f0bb5acca568e57175c974c54993d0934d8d3
images/international_placeholder.jpg,1709687695136,ca11b7b0dc9562294ad4b1e0d778243b1b4cdb1d7daf8bb5f6f7749f6ffc3976
images/bg.webp,1720432387556,56af6239eed0080c917231b4e1e2fabfea36de843c5004b92e9941461e81c11f
images/testbg2.jpg,1696497351214,ba0e6b61f35bde9dd9949426da569529ec7b33d63fbdbab307b99a0b14217046
images/bg2.webp,1723934109217,5848c87093a6345d24e8891469b68ab4916aba33add37dd0faa4b5d1d9491119
images/bg2.jpg,1723589234023,b05c4b16cfe029c4a04ec98a3d92dd767efc0ce149d46fc31f46b48902d1feb9
5 changes: 5 additions & 0 deletions frontend/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "medieteknik"
}
}
25 changes: 25 additions & 0 deletions frontend/firebase-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[debug] [2024-09-01T01:41:52.373Z] ----------------------------------------------------------------------
[debug] [2024-09-01T01:41:52.375Z] Command: C:\Program Files\nodejs\node.exe C:\Users\andre\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js init hosting:github
[debug] [2024-09-01T01:41:52.375Z] CLI Version: 13.16.0
[debug] [2024-09-01T01:41:52.375Z] Platform: win32
[debug] [2024-09-01T01:41:52.376Z] Node Version: v21.5.0
[debug] [2024-09-01T01:41:52.376Z] Time: Sun Sep 01 2024 03:41:52 GMT+0200 (Central European Summer Time)
[debug] [2024-09-01T01:41:52.376Z] ----------------------------------------------------------------------
[debug]
[debug] [2024-09-01T01:41:52.432Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2024-09-01T01:41:52.433Z] > authorizing via signed-in user ([email protected])
[info]
######## #### ######## ######## ######## ### ###### ########
## ## ## ## ## ## ## ## ## ## ##
###### ## ######## ###### ######## ######### ###### ######
## ## ## ## ## ## ## ## ## ## ##
## #### ## ## ######## ######## ## ## ###### ########

You're about to initialize a Firebase project in this directory:

D:\Programming\Medieteknik\medieteknik.com\frontend

Before we get started, keep in mind:

* You are initializing within an existing Firebase project directory

14 changes: 14 additions & 0 deletions frontend/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"remoteconfig": {
"template": "remoteconfig.template.json"
},
"extensions": {}
}
33 changes: 33 additions & 0 deletions frontend/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>
Loading

0 comments on commit e6e9e63

Please sign in to comment.