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.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():
op.drop_table('code_roles', schema=f'{get_inv()}')
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 werkzeug.security import gen_salt
from flask import current_app
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.models import Thing
from ereuse_devicehub.resources.user.models import User
@ -81,8 +82,8 @@ class OAuth2Token(Thing, OAuth2TokenMixin):
member = db.relationship('MemberFederated')
class Code2Roles(Thing):
__tablename__ = 'code_roles'
class CodeRoles(Thing):
# __tablename__ = 'code_roles'
id = db.Column(db.Integer, primary_key=True)
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 (
MemberFederated,
OAuth2Client,
Code2Roles
CodeRoles
)
from ereuse_devicehub.modules.oidc.oauth2 import (
authorization,
@ -260,7 +260,7 @@ class AllowCodeOidc4vpView(GenericMixin):
return roles
def get_response_uri(selfi, roles):
code = Code2Roles(roles=roles)
code = CodeRoles(roles=roles)
db.session.add(code)
db.session.commit()
@ -288,7 +288,7 @@ class AllowCodeOidc4vp2View(View):
return redirect(url)
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:
return