fix access to table with schema and without

This commit is contained in:
Cayo Puigdefabregas 2024-03-27 17:32:57 +01:00
parent a4c7b2a744
commit 2283f20ab2
3 changed files with 30 additions and 5 deletions

View File

@ -49,6 +49,30 @@ def upgrade():
op.execute(f"CREATE SEQUENCE {get_inv()}.code_roles_seq;") op.execute(f"CREATE SEQUENCE {get_inv()}.code_roles_seq;")
op.create_table(
'code_roles',
sa.Column('id', sa.BigInteger(), nullable=False),
sa.Column(
'updated',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column(
'created',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column('code', citext.CIText(), nullable=False),
sa.Column('roles', citext.CIText(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.execute(f"CREATE SEQUENCE code_roles_seq;")
def downgrade(): def downgrade():
op.drop_table('code_roles', schema=f'{get_inv()}') op.drop_table('code_roles', schema=f'{get_inv()}')
op.execute(f"DROP SEQUENCE {get_inv()}.code_roles_seq;") op.execute(f"DROP SEQUENCE {get_inv()}.code_roles_seq;")
op.drop_table('code_roles')
op.execute(f"DROP SEQUENCE code_roles_seq;")

View File

@ -6,6 +6,7 @@ from authlib.integrations.sqla_oauth2 import (
from flask import g from flask import g
from werkzeug.security import gen_salt from werkzeug.security import gen_salt
from flask import current_app
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.models import Thing from ereuse_devicehub.resources.models import Thing
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User
@ -81,8 +82,8 @@ class OAuth2Token(Thing, OAuth2TokenMixin):
member = db.relationship('MemberFederated') member = db.relationship('MemberFederated')
class Code2Roles(Thing): class CodeRoles(Thing):
__tablename__ = 'code_roles' # __tablename__ = 'code_roles'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
code = db.Column(db.String(40), default=gen_code, nullable=False) code = db.Column(db.String(40), default=gen_code, nullable=False)

View File

@ -29,7 +29,7 @@ from ereuse_devicehub.modules.oidc.forms import (
from ereuse_devicehub.modules.oidc.models import ( from ereuse_devicehub.modules.oidc.models import (
MemberFederated, MemberFederated,
OAuth2Client, OAuth2Client,
Code2Roles CodeRoles
) )
from ereuse_devicehub.modules.oidc.oauth2 import ( from ereuse_devicehub.modules.oidc.oauth2 import (
authorization, authorization,
@ -260,7 +260,7 @@ class AllowCodeOidc4vpView(GenericMixin):
return roles return roles
def get_response_uri(selfi, roles): def get_response_uri(selfi, roles):
code = Code2Roles(roles=roles) code = CodeRoles(roles=roles)
db.session.add(code) db.session.add(code)
db.session.commit() db.session.commit()
@ -288,7 +288,7 @@ class AllowCodeOidc4vp2View(View):
return redirect(url) return redirect(url)
def get_user_info(self): def get_user_info(self):
code = Code2Roles.query.filter_by(code=self.code).first() code = CodeRoles.query.filter_by(code=self.code).first()
if not code: if not code:
return return