Skip to content
Snippets Groups Projects
Commit a460444a authored by kaiyou's avatar kaiyou
Browse files

Add a temporary account purge feature

parent 4e6ba135
No related branches found
No related tags found
No related merge requests found
from flask import cli
from hiboo import models
from hiboo.profile import common
import time
......@@ -21,3 +22,10 @@ def tasks_loop():
while True:
common.apply_all_transitions()
time.sleep(30)
@tasks.command("purge")
def purge():
# Temporary command to list purgeable accounts before we include
# this in the main task loop
print(models.User.get_unused().all())
......@@ -114,6 +114,17 @@ class User(db.Model):
profile.status = Profile.ACTIVE
return profile
@classmethod
def get_unused(cls, interval=datetime.timedelta(hours=2)):
return (cls.query
.join(cls.profiles.and_(Profile.status != Profile.PURGED), isouter=True)
.filter(Profile.uuid == None)
.filter(
datetime.datetime.now() - interval >
sqlalchemy.sql.func.coalesce(cls.updated_at, cls.created_at)
)
)
class Auth(db.Model):
""" An authenticator is a method to authenticate a user.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment