2022-03-20 10:46:23 +01:00
|
|
|
import sys
|
2024-04-21 20:44:08 +02:00
|
|
|
|
|
|
|
from sqlalchemy.exc import (DatabaseError, DataError, InterfaceError,
|
|
|
|
InvalidRequestError)
|
|
|
|
|
2022-03-20 10:46:23 +01:00
|
|
|
from app import create_app, db
|
2024-04-21 20:44:08 +02:00
|
|
|
from models.distribusimodel import Distribusis # noqa: F401
|
|
|
|
from models.usermodel import User # noqa: F401
|
2022-03-20 10:46:23 +01:00
|
|
|
|
2022-03-21 20:08:56 +01:00
|
|
|
|
2022-03-20 10:46:23 +01:00
|
|
|
def admintool():
|
|
|
|
"""Admin CLI tool. To elevate a user to admin"""
|
|
|
|
app = create_app()
|
|
|
|
app.app_context().push()
|
|
|
|
elevateusertoadmin()
|
|
|
|
|
|
|
|
|
|
|
|
def elevateusertoadmin():
|
|
|
|
"""To elevates user of first command line argument to admin"""
|
|
|
|
user = User.query.filter_by(email=sys.argv[1]).first()
|
|
|
|
print(f"user {user.username} found with email {user.email}")
|
|
|
|
try:
|
|
|
|
user.admin = True
|
|
|
|
db.session.commit()
|
|
|
|
print(f"Account {user.email} succesfully made into an admin")
|
|
|
|
except InvalidRequestError:
|
|
|
|
db.session.rollback()
|
|
|
|
print("Something went wrong!")
|
|
|
|
except InterfaceError:
|
|
|
|
db.session.rollback()
|
|
|
|
print("Error connecting to the database")
|
|
|
|
except DataError:
|
|
|
|
db.session.rollback()
|
|
|
|
print("Invalid Entry")
|
|
|
|
except DatabaseError:
|
|
|
|
db.session.rollback()
|
|
|
|
print("Error connecting to the database")
|
|
|
|
|
|
|
|
|
|
|
|
admintool()
|