don't make everyone an admin :)
This commit is contained in:
parent
5eb9d4d113
commit
1c1ea694d1
2 changed files with 19 additions and 4 deletions
|
@ -30,6 +30,9 @@ class Certificate(CertificateBase):
|
||||||
class UserCapability(Enum):
|
class UserCapability(Enum):
|
||||||
admin = "admin"
|
admin = "admin"
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self._value_
|
||||||
|
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
|
@ -108,7 +111,7 @@ class User(UserBase):
|
||||||
user = models.User(
|
user = models.User(
|
||||||
name=user.name,
|
name=user.name,
|
||||||
password=crypt_context.hash(user.password),
|
password=crypt_context.hash(user.password),
|
||||||
capabilities=[models.UserCapability(capability="admin")],
|
capabilities=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
db.add(user)
|
db.add(user)
|
||||||
|
@ -120,6 +123,15 @@ class User(UserBase):
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def add_capabilities(
|
||||||
|
self,
|
||||||
|
db: Session,
|
||||||
|
capabilities: list[UserCapability],
|
||||||
|
) -> bool:
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class DistinguishedNameBase(BaseModel):
|
class DistinguishedNameBase(BaseModel):
|
||||||
cn_only: bool
|
cn_only: bool
|
||||||
|
|
|
@ -26,14 +26,17 @@ async def install(
|
||||||
Connection.connect(await config.db.db_engine)
|
Connection.connect(await config.db.db_engine)
|
||||||
|
|
||||||
async for db in Connection.get():
|
async for db in Connection.get():
|
||||||
# user.capabilities.append("admin")
|
admin_user = schemas.User.create(
|
||||||
|
|
||||||
schemas.User.create(
|
|
||||||
db=db,
|
db=db,
|
||||||
user=user,
|
user=user,
|
||||||
crypt_context=await config.crypto.crypt_context,
|
crypt_context=await config.crypto.crypt_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
admin_user.add_capabilities(
|
||||||
|
db=db,
|
||||||
|
capabilities=[schemas.UserCapability.admin],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.put(
|
@router.put(
|
||||||
"/config",
|
"/config",
|
||||||
|
|
Loading…
Reference in a new issue