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
|
||||
|
||||
def add_capabilities(
|
||||
def update(
|
||||
self,
|
||||
db: Session,
|
||||
capabilities: list[UserCapability],
|
||||
) -> None:
|
||||
"""
|
||||
Add some capabilities to this user.
|
||||
Update this user in the database.
|
||||
"""
|
||||
|
||||
for capability in capabilities:
|
||||
if capability not in self.capabilities:
|
||||
db.add(models.UserCapability(
|
||||
user_name=self.name,
|
||||
capability=capability.value,
|
||||
))
|
||||
old_dbuser = models.User.load(db, self.name)
|
||||
old_user = self.from_orm(old_dbuser)
|
||||
|
||||
for capability in self.capabilities:
|
||||
if capability not in old_user.capabilities:
|
||||
old_dbuser.capabilities.append(
|
||||
models.UserCapability(capability=capability.value)
|
||||
)
|
||||
|
||||
db.commit()
|
||||
|
||||
|
|
|
@ -39,15 +39,15 @@ async def install(
|
|||
|
||||
# create an administrative user
|
||||
with Connection.use() as db:
|
||||
User.create(
|
||||
new_user = User.create(
|
||||
db=db,
|
||||
user=admin_user,
|
||||
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(
|
||||
"/config",
|
||||
|
|
Loading…
Reference in a new issue