-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from sysblok/dev
feat: fetch focalboard credentials
- Loading branch information
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import json | ||
import logging | ||
import telegram | ||
|
||
from ...db.db_client import DBClient | ||
from ...strings import load | ||
from .utils import get_sender_id, get_sender_username, reply | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_board_credentials(update: telegram.Update, tg_context): | ||
member = next(( | ||
member for member in DBClient().get_all_members() | ||
if member.telegram == f"@{get_sender_username(update)}" | ||
), None) | ||
if member is None or not member.trello: | ||
logger.usage( | ||
f'Trello not found for {get_sender_username(update)}, ID={get_sender_id(update)}' | ||
) | ||
reply(load('get_board_credentials_handler__not_found'), update) | ||
return | ||
try: | ||
print(member.trello) | ||
with open('board_credentials.json', encoding="utf-8") as fin: | ||
try: | ||
board_json = json.loads(fin.read()) | ||
creds = next(( | ||
cred for cred in board_json if cred["trelloUsername"] == member.trello | ||
), None) | ||
if not creds: | ||
logger.usage( | ||
f'Board creds not found for user {get_sender_username(update)}' | ||
) | ||
reply(load('get_board_credentials_handler__not_found'), update) | ||
return | ||
logger.usage(f'Board creds found for username {get_sender_username(update)}') | ||
reply( | ||
load( | ||
'get_board_credentials_handler__found', | ||
username=creds["focalboardUsername"][1:], | ||
password=creds["focalboardPassword"] | ||
), | ||
update | ||
) | ||
except json.JSONDecodeError as e: | ||
logger.error(e) | ||
except IOError: | ||
logger.warning(f"Board passwords file not found", exc_info=e) |