diff --git a/backend/alembic/versions/6368515778c5_add_auth_method_to_person.py b/backend/alembic/versions/6368515778c5_add_auth_method_to_person.py new file mode 100644 index 00000000..d93afeba --- /dev/null +++ b/backend/alembic/versions/6368515778c5_add_auth_method_to_person.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +"""add auth_method to person + +Revision ID: 6368515778c5 +Revises: cd7de470586e +Create Date: 2022-12-17 17:57:33.022549 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "6368515778c5" +down_revision = "cd7de470586e" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("person", sa.Column("auth_method", sa.String(length=128), nullable=True)) + op.execute("UPDATE person SET auth_method = 'local'") + op.alter_column("person", "auth_method", nullable=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("person", "auth_method") + # ### end Alembic commands ### diff --git a/backend/app/ocgpt/models/person.py b/backend/app/ocgpt/models/person.py index e66db5e3..57f134a4 100644 --- a/backend/app/ocgpt/models/person.py +++ b/backend/app/ocgpt/models/person.py @@ -18,6 +18,7 @@ class Person(SQLModel, table=True): ), ) username: str = Field(nullable=False, max_length=128) + auth_method: str = Field(nullable=False, max_length=128, default="local") display_name: str = Field(nullable=False, max_length=256) created_date: Optional[datetime] = Field( sa_column=sa.Column(sa.DateTime(), nullable=False, server_default=sa.func.current_timestamp()) diff --git a/backend/app/ocgpt/prompt_repository.py b/backend/app/ocgpt/prompt_repository.py index 7b39d0b8..8c621df1 100644 --- a/backend/app/ocgpt/prompt_repository.py +++ b/backend/app/ocgpt/prompt_repository.py @@ -22,7 +22,13 @@ class PromptRepository: if not user: return None person: Person = ( - self.db.query(Person).filter(Person.api_client_id == self.api_client.id, Person.username == user.id).first() + self.db.query(Person) + .filter( + Person.api_client_id == self.api_client.id, + Person.username == user.id, + Person.auth_method == user.auth_method, + ) + .first() ) if person is None: # user is unknown, create new record