Commit 1a84ad40 authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

[bin] added script for user deletion

parent 0d7ef720
#!/usr/bin/env python
import sys
import os
base = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
if os.path.isdir(base):
sys.path.insert(0, base)
from argparse import ArgumentParser
import logging
logger = logging.getLogger(__name__)
parser = ArgumentParser()
parser.add_argument('-c', '--config-dir', help='Directory containing configuration files.')
parser.add_argument('-d', '--data-dir', help='Directory containing server.')
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose output.")
parser.add_argument('--yes-delete', action="store_true", help='Yes, actually delete stuff.')
parser.add_argument("user", help="User identifier (name/email)")
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
import vispa
import vispa.models
from sqlalchemy.orm import scoped_session, sessionmaker
vispa.setup_config(args.config_dir)
session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
session.configure(bind=vispa.models.open_database(args.data_dir))
from vispa.models.user import User
from vispa.models.group import group_manager_association, Group_User_Assoc
from vispa.models.project import project_manager_association, project_user_assoc_role_association
from vispa.models.workgroup import workgroup_manager_association, workgroup_user_association
from vispa.models.workspace import Workspace
from vispa.models.jsondata import JSONData
user = User.get(session, args.user)
for obj in [
Workspace,
workgroup_manager_association,
workgroup_user_association,
project_manager_association,
project_user_assoc_role_association,
JSONData,
group_manager_association,
Group_User_Assoc,
]:
tab = getattr(obj, "__table__", obj)
q = session.query(tab).filter_by(user_id=user.id)
n = q.count()
logger.info("%3d entries in %s", n, tab)
if n:
logger.debug("%r", q.all())
if args.yes_delete:
q.delete(synchronize_session=False)
print(user.name)
if args.yes_delete:
session.delete(user)
try:
session.commit()
except Exception as e:
session.rollback()
raise e
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment