added model and migration for resume
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Gulliver 2024-08-30 19:08:35 +02:00
parent 92f5393a4c
commit c4f5979d95
6 changed files with 96 additions and 42 deletions

5
app.py
View File

@ -42,5 +42,8 @@ db = SQLAlchemy(app)
migrate = Migrate(app, db, compare_type=True) migrate = Migrate(app, db, compare_type=True)
app.logger.info("Hello from KI") app.logger.info("Hello from KI")
from ki import module # noqa from ki import module # noqa
from ki import resume
app.register_blueprint(resume.bp_resume, url_prefix='/resume')

View File

@ -1,7 +1,14 @@
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from flask import Blueprint from flask import Blueprint
from ki.token_auth import token_auth
from ki.resume_models import Resume
bp_resume = Blueprint('resume', __name__, bp_resume = Blueprint('resume', __name__,
template_folder='templates') template_folder='templates')
@bp_resume.route('/') @bp_resume.route('/')
@token_auth @token_auth
@ -9,20 +16,17 @@ def show(page):
""" """
return the list of resumes as object with data array inside return the list of resumes as object with data array inside
""" """
return jsonify() pass
@bp_resume.route("/<resume_id>") @bp_resume.route("/<resume_id>")
@token_auth @token_auth
def get_resume(resume_id): def get_resume(resume_id):
""" """
lookup for resume with resume_id, check if its from this user and provide its contents lookup for resume with resume_id, check if its from this user
in the appropriate format and provide its contents in the appropriate format
shall support 'format' parameter with values of 'html', 'pdf' shall support 'format' parameter with values of 'html', 'pdf'
if no parameter is given, json is returned if no parameter is given, json is returned
""" """
return jsonify( r = Resume()
id=resume_id return r.to_dict()
)

View File

@ -2,11 +2,9 @@
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
from datetime import datetime
from sqlalchemy import Boolean, Column, Integer, SmallInteger, String, DateTime, ForeignKey from sqlalchemy import Column, Integer, String, ForeignKey, JSON
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from app import db from app import db
@ -14,10 +12,17 @@ class Resume(db.Model):
__tablename__ = 'resume' __tablename__ = 'resume'
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
profile_id = Column(Integer, ForeignKey("profile.id"), nullable=True)
user_id = Column(Integer, ForeignKey("user.id", ondelete='CASCADE'))
label = Column("label", String(50), nullable=True)
data = Column('data', JSON)
user = relationship("User", backref='user', passive_deletes=True)
def to_dict(self): def to_dict(self):
return { return {
"id": self.id, "id": self.id,
'profile_id': profile_id 'user_id': self.user_id,
"label": self.label,
"data": self.data
} }

View File

@ -4,42 +4,18 @@
import os import os
from flask import g, make_response, request, send_file from flask import g, make_response, request, send_file
from functools import wraps
from ki.auth import auth from ki.auth import auth
from ki.handlers import find_profiles as find_profiles_handler from ki.handlers import find_profiles as find_profiles_handler
from ki.handlers import update_profile as update_profile_handler from ki.handlers import update_profile as update_profile_handler
from ki.models import ContactType, Language, Skill, Token, User from ki.models import ContactType, Language, Skill, User
from app import app from app import app
from ki.token_auth import token_auth
content_type_svg = "image/svg+xml" content_type_svg = "image/svg+xml"
content_type_png = "image/png" content_type_png = "image/png"
def token_auth(func):
@wraps(func)
def _token_auth(*args, **kwargs):
auth_header = request.headers.get("Authorization")
if (auth_header is None):
return make_response({}, 401)
if not auth_header.startswith("Bearer"):
return make_response({}, 401)
token = Token.query.filter(Token.token == auth_header[7:]).first()
if token is None:
return make_response({}, 403)
g.user = token.user
return func(*args, **kwargs)
return _token_auth
def models_to_list(models): def models_to_list(models):
models_list = [] models_list = []

31
ki/token_auth.py Normal file
View File

@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from flask import g, make_response, request
from functools import wraps
from ki.models import Token
def token_auth(func):
@wraps(func)
def _token_auth(*args, **kwargs):
auth_header = request.headers.get("Authorization")
if (auth_header is None):
return make_response({}, 401)
if not auth_header.startswith("Bearer"):
return make_response({}, 401)
token = Token.query.filter(Token.token == auth_header[7:]).first()
if token is None:
return make_response({}, 403)
g.user = token.user
return func(*args, **kwargs)
return _token_auth

View File

@ -0,0 +1,35 @@
"""add resume
Revision ID: 6be5073423b4
Revises: b5023977cbda
Create Date: 2024-08-30 18:18:14.555874
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6be5073423b4'
down_revision = 'b5023977cbda'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('resume',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('label', sa.String(length=50), nullable=True),
sa.Column('data', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('resume')
# ### end Alembic commands ###