mirror of
https://github.com/imartinez/privateGPT.git
synced 2025-06-29 08:47:19 +00:00
updated with few bug fixes for authentication and department
This commit is contained in:
parent
043ba4ffd6
commit
59d9413898
4
.env
4
.env
@ -4,7 +4,7 @@ ENVIRONMENT=dev
|
|||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_USER=postgres
|
DB_USER=postgres
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_PASSWORD=quick
|
DB_PASSWORD=admin
|
||||||
DB_NAME=QuickGpt
|
DB_NAME=QuickGpt
|
||||||
|
|
||||||
SUPER_ADMIN_EMAIL=superadmin@email.com
|
SUPER_ADMIN_EMAIL=superadmin@email.com
|
||||||
@ -22,4 +22,4 @@ SMTP_USERNAME=shresthasaurab030
|
|||||||
SMTP_PASSWORD=huurxwxeorxjorzw
|
SMTP_PASSWORD=huurxwxeorxjorzw
|
||||||
|
|
||||||
LDAP_SERVER=ldap://192.168.101.111
|
LDAP_SERVER=ldap://192.168.101.111
|
||||||
LDAP_ENABLE=False
|
LDAP_ENABLE=True
|
118
alembic/versions/8c4bd1aaf45a_create_model.py
Normal file
118
alembic/versions/8c4bd1aaf45a_create_model.py
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
"""Create model
|
||||||
|
|
||||||
|
Revision ID: 8c4bd1aaf45a
|
||||||
|
Revises:
|
||||||
|
Create Date: 2024-02-22 13:19:29.947241
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '8c4bd1aaf45a'
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('companies',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_companies_id'), 'companies', ['id'], unique=False)
|
||||||
|
op.create_index(op.f('ix_companies_name'), 'companies', ['name'], unique=True)
|
||||||
|
op.create_table('roles',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=100), nullable=True),
|
||||||
|
sa.Column('description', sa.Text(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_roles_id'), 'roles', ['id'], unique=False)
|
||||||
|
op.create_index(op.f('ix_roles_name'), 'roles', ['name'], unique=False)
|
||||||
|
op.create_table('departments',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(), nullable=True),
|
||||||
|
sa.Column('company_id', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('total_users', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('total_documents', sa.Integer(), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_departments_id'), 'departments', ['id'], unique=False)
|
||||||
|
op.create_index(op.f('ix_departments_name'), 'departments', ['name'], unique=True)
|
||||||
|
op.create_table('subscriptions',
|
||||||
|
sa.Column('sub_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('company_id', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('start_date', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('end_date', sa.DateTime(), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('sub_id')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_subscriptions_sub_id'), 'subscriptions', ['sub_id'], unique=False)
|
||||||
|
op.create_table('users',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('email', sa.String(length=225), nullable=False),
|
||||||
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
||||||
|
sa.Column('fullname', sa.String(length=225), nullable=False),
|
||||||
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||||
|
sa.Column('last_login', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
|
sa.Column('company_id', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('department_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('email'),
|
||||||
|
sa.UniqueConstraint('fullname'),
|
||||||
|
sa.UniqueConstraint('fullname', name='unique_username_no_spacing')
|
||||||
|
)
|
||||||
|
op.create_table('document',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('filename', sa.String(length=225), nullable=False),
|
||||||
|
sa.Column('uploaded_by', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('uploaded_at', sa.DateTime(), nullable=False),
|
||||||
|
sa.Column('department_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['uploaded_by'], ['users.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('filename')
|
||||||
|
)
|
||||||
|
op.create_index(op.f('ix_document_id'), 'document', ['id'], unique=False)
|
||||||
|
op.create_table('user_roles',
|
||||||
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('role_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('company_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['company_id'], ['companies.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('user_id', 'role_id', 'company_id'),
|
||||||
|
sa.UniqueConstraint('user_id', 'role_id', 'company_id', name='unique_user_role')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('user_roles')
|
||||||
|
op.drop_index(op.f('ix_document_id'), table_name='document')
|
||||||
|
op.drop_table('document')
|
||||||
|
op.drop_table('users')
|
||||||
|
op.drop_index(op.f('ix_subscriptions_sub_id'), table_name='subscriptions')
|
||||||
|
op.drop_table('subscriptions')
|
||||||
|
op.drop_index(op.f('ix_departments_name'), table_name='departments')
|
||||||
|
op.drop_index(op.f('ix_departments_id'), table_name='departments')
|
||||||
|
op.drop_table('departments')
|
||||||
|
op.drop_index(op.f('ix_roles_name'), table_name='roles')
|
||||||
|
op.drop_index(op.f('ix_roles_id'), table_name='roles')
|
||||||
|
op.drop_table('roles')
|
||||||
|
op.drop_index(op.f('ix_companies_name'), table_name='companies')
|
||||||
|
op.drop_index(op.f('ix_companies_id'), table_name='companies')
|
||||||
|
op.drop_table('companies')
|
||||||
|
# ### end Alembic commands ###
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
LDAP_SERVER = settings.LDAP_SERVER
|
LDAP_SERVER = settings.LDAP_SERVER
|
||||||
# LDAP_ENABLE = settings.LDAP_ENABLE
|
# LDAP_ENABLE = settings.LDAP_ENABLE
|
||||||
LDAP_ENABLE = False
|
LDAP_ENABLE = True
|
||||||
|
|
||||||
router = APIRouter(prefix="/auth", tags=["auth"])
|
router = APIRouter(prefix="/auth", tags=["auth"])
|
||||||
|
|
||||||
|
@ -339,9 +339,8 @@ def admin_update_user(
|
|||||||
)
|
)
|
||||||
role = crud.user_role.update(db, db_obj=user_role, obj_in=role_in)
|
role = crud.user_role.update(db, db_obj=user_role, obj_in=role_in)
|
||||||
|
|
||||||
user_in = schemas.UserUpdate(fullname=user_update.fullname,
|
user_in = schemas.UserAdmin(fullname=user_update.fullname, department_id=user_update.department_id)
|
||||||
email=existing_user.email, company_id=existing_user.user_role.company_id, department_id=user_update.department_id)
|
crud.user.update(db, db_obj=existing_user, obj_in=user_in)
|
||||||
user = crud.user.update(db, db_obj=existing_user, obj_in=user_in)
|
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
|
@ -8,7 +8,7 @@ SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{username}:{password}@{host}:{p
|
|||||||
port='5432',
|
port='5432',
|
||||||
db_name='QuickGpt',
|
db_name='QuickGpt',
|
||||||
username='postgres',
|
username='postgres',
|
||||||
password="quick",
|
password="admin",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from .role import Role, RoleCreate, RoleInDB, RoleUpdate
|
from .role import Role, RoleCreate, RoleInDB, RoleUpdate
|
||||||
from .token import TokenSchema, TokenPayload
|
from .token import TokenSchema, TokenPayload
|
||||||
from .user import User, UserCreate, UserInDB, UserUpdate, UserBaseSchema, Profile, UsernameUpdate, DeleteUser, UserAdminUpdate
|
from .user import User, UserCreate, UserInDB, UserUpdate, UserBaseSchema, Profile, UsernameUpdate, DeleteUser, UserAdminUpdate, UserAdmin
|
||||||
from .user_role import UserRole, UserRoleCreate, UserRoleInDB, UserRoleUpdate
|
from .user_role import UserRole, UserRoleCreate, UserRoleInDB, UserRoleUpdate
|
||||||
from .subscription import Subscription, SubscriptionBase, SubscriptionCreate, SubscriptionUpdate
|
from .subscription import Subscription, SubscriptionBase, SubscriptionCreate, SubscriptionUpdate
|
||||||
from .company import Company, CompanyBase, CompanyCreate, CompanyUpdate
|
from .company import Company, CompanyBase, CompanyCreate, CompanyUpdate
|
||||||
|
@ -29,6 +29,7 @@ class UserUpdate(BaseModel):
|
|||||||
last_login: Optional[datetime] = None
|
last_login: Optional[datetime] = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserLoginSchema(BaseModel):
|
class UserLoginSchema(BaseModel):
|
||||||
email: EmailStr = Field(alias="email")
|
email: EmailStr = Field(alias="email")
|
||||||
password: str
|
password: str
|
||||||
@ -71,3 +72,7 @@ class UserAdminUpdate(BaseModel):
|
|||||||
fullname: str
|
fullname: str
|
||||||
role: str
|
role: str
|
||||||
department_id: int
|
department_id: int
|
||||||
|
|
||||||
|
class UserAdmin(BaseModel):
|
||||||
|
fullname: str
|
||||||
|
department_id: int
|
@ -7,6 +7,7 @@ class Ldap:
|
|||||||
self.server = ldap3.Server(server_uri, get_info=ldap3.ALL)
|
self.server = ldap3.Server(server_uri, get_info=ldap3.ALL)
|
||||||
print(f"Connected to ldap server: {self.server}")
|
print(f"Connected to ldap server: {self.server}")
|
||||||
self.conn = ldap3.Connection(self.server, user=ldap_user, password=ldap_pass, auto_bind=True)
|
self.conn = ldap3.Connection(self.server, user=ldap_user, password=ldap_pass, auto_bind=True)
|
||||||
|
print(self.conn)
|
||||||
|
|
||||||
def who_am_i(self):
|
def who_am_i(self):
|
||||||
return self.conn.extend.standard.who_am_i()
|
return self.conn.extend.standard.who_am_i()
|
||||||
|
Loading…
Reference in New Issue
Block a user