Skip to content

Commit 16debfc

Browse files
feat: Add auto disable of deleted accounts
1 parent ec002e0 commit 16debfc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

coffeebuddy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from flask_sqlalchemy import SQLAlchemy
99
from sqlalchemy.orm import DeclarativeBase
1010

11-
__version__ = "2.2.1"
11+
__version__ = "2.3.0"
1212

1313

1414
logging.basicConfig(

coffeebuddy/extensions/webex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ def send_message(
223223
)
224224

225225

226+
def disable_deleted_accounts(app: flask.Flask) -> None:
227+
"""Disable accounts that have been deleted in the webex."""
228+
with app.app_context():
229+
api = webexteamssdk.WebexTeamsAPI(access_token=app.config["WEBEX_ACCESS_TOKEN"])
230+
for user in User.query.filter(User.enabled).all():
231+
if not list(api.people.list(email=user.email)):
232+
user.enabled = False
233+
app.db.session.commit()
234+
api.messages.create(
235+
roomId=app.config["WEBEX_DATABASE_BACKUP"],
236+
markdown=f"## Disabled: {user} ({user.id})",
237+
)
238+
239+
226240
def init():
227241
app = flask.current_app
228242
if app.testing:
@@ -296,3 +310,7 @@ def backup_database():
296310
roomId=app.config["WEBEX_DATABASE_BACKUP"],
297311
files=[str(backupfile)],
298312
)
313+
314+
scheduler.scheduled_job("cron", day_of_week="sat", args=(app,))(
315+
disable_deleted_accounts
316+
)

coffeebuddy/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def top_selected_manually(
228228
).all()
229229

230230
@staticmethod
231-
def all_enabled() -> List["User"]:
231+
def all_enabled() -> list[str, list["User"]]:
232232
db = flask.current_app.db
233233
users = [
234234
(

0 commit comments

Comments
 (0)