From 2283f20ab21c652fc83186eea5d6a0a4452c4bdb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 27 Mar 2024 17:32:57 +0100 Subject: [PATCH] fix access to table with schema and without --- .../versions/96092022dadb_code2roles.py | 24 +++++++++++++++++++ ereuse_devicehub/modules/oidc/models.py | 5 ++-- ereuse_devicehub/modules/oidc/views.py | 6 ++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/modules/oidc/migrations/versions/96092022dadb_code2roles.py b/ereuse_devicehub/modules/oidc/migrations/versions/96092022dadb_code2roles.py index 4a3ddcb6..33c2509e 100644 --- a/ereuse_devicehub/modules/oidc/migrations/versions/96092022dadb_code2roles.py +++ b/ereuse_devicehub/modules/oidc/migrations/versions/96092022dadb_code2roles.py @@ -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;") diff --git a/ereuse_devicehub/modules/oidc/models.py b/ereuse_devicehub/modules/oidc/models.py index d5737c00..265801d4 100644 --- a/ereuse_devicehub/modules/oidc/models.py +++ b/ereuse_devicehub/modules/oidc/models.py @@ -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) diff --git a/ereuse_devicehub/modules/oidc/views.py b/ereuse_devicehub/modules/oidc/views.py index 18e18583..33a664fd 100644 --- a/ereuse_devicehub/modules/oidc/views.py +++ b/ereuse_devicehub/modules/oidc/views.py @@ -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