User update
This commit is contained in:
parent
98cdc43bb2
commit
e3acc9b7e0
2 changed files with 14 additions and 13 deletions
|
@ -160,21 +160,22 @@ class User(UserBase):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_capabilities(
|
def update(
|
||||||
self,
|
self,
|
||||||
db: Session,
|
db: Session,
|
||||||
capabilities: list[UserCapability],
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Add some capabilities to this user.
|
Update this user in the database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for capability in capabilities:
|
old_dbuser = models.User.load(db, self.name)
|
||||||
if capability not in self.capabilities:
|
old_user = self.from_orm(old_dbuser)
|
||||||
db.add(models.UserCapability(
|
|
||||||
user_name=self.name,
|
for capability in self.capabilities:
|
||||||
capability=capability.value,
|
if capability not in old_user.capabilities:
|
||||||
))
|
old_dbuser.capabilities.append(
|
||||||
|
models.UserCapability(capability=capability.value)
|
||||||
|
)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,15 @@ async def install(
|
||||||
|
|
||||||
# create an administrative user
|
# create an administrative user
|
||||||
with Connection.use() as db:
|
with Connection.use() as db:
|
||||||
User.create(
|
new_user = User.create(
|
||||||
db=db,
|
db=db,
|
||||||
user=admin_user,
|
user=admin_user,
|
||||||
crypt_context=await config.crypto.crypt_context,
|
crypt_context=await config.crypto.crypt_context,
|
||||||
).add_capabilities(
|
|
||||||
db=db,
|
|
||||||
capabilities=[UserCapability.admin],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new_user.capabilities.append(UserCapability.admin)
|
||||||
|
new_user.update(db)
|
||||||
|
|
||||||
|
|
||||||
@router.put(
|
@router.put(
|
||||||
"/config",
|
"/config",
|
||||||
|
|
Loading…
Reference in a new issue