Skip to content

Commit

Permalink
Try to recover from missed user creation triggers, refs #71
Browse files Browse the repository at this point in the history
  • Loading branch information
rambo committed Jan 26, 2025
1 parent f356d02 commit 0b64504
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/takrmapi/tak_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,27 @@ async def revoke_user(self) -> bool:
return True
return False

async def _check_and_create_missing_user(self) -> bool:
"""check if user exists, if not try to create"""
if await self.helpers.user_cert_validate():
return True
await self.add_new_user()
if not await self.helpers.user_cert_validate():
LOGGER.error("User still does not have a valid cert, something is fscked up")
return False
return True

async def promote_user(self) -> bool:
"""Promote user to admin"""
if await self.helpers.user_cert_validate():
if await self._check_and_create_missing_user():
return await self.helpers.add_admin_to_tak_with_cert()
return False

async def demote_user(self) -> bool:
"""Demote user from being admin"""
# TODO # THIS WORKS POORLY UNTIL PROPER REST IS FOUND OR SOME OTHER ALTERNATIVE
# WE JUST RECREATE THE USER HERE AND GET RID OF THE ADMIN PERMISSIONS THAT WAY
if await self.helpers.user_cert_validate():
if await self._check_and_create_missing_user():
if not await self.helpers.delete_user_with_cert():
return False
return await self.helpers.add_user_to_tak_with_cert()
Expand All @@ -165,8 +175,7 @@ async def update_user(self) -> bool:
"""Update user certificate"""
# TODO # THIS NEED TO BE CHECKED WHAT IT ACTUALLY DOES IN BACKGROUND,
# DOES IT UPDATE THE CERTIFICATE OR ADD NEW USER OR WHAT??
await self.helpers.user_cert_write()
if await self.helpers.user_cert_validate():
if await self._check_and_create_missing_user():
# TODO check/find out if the user is admin and add as admin
return await self.helpers.add_user_to_tak_with_cert()
return False
Expand Down

0 comments on commit 0b64504

Please sign in to comment.