2022-03-20 10:46:23 +01:00
|
|
|
import sys
|
2024-04-21 20:44:08 +02:00
|
|
|
|
2024-04-28 13:15:23 +02:00
|
|
|
from sqlalchemy.exc import (
|
2024-05-28 23:02:17 +02:00
|
|
|
DatabaseError,
|
|
|
|
DataError,
|
|
|
|
InterfaceError,
|
|
|
|
InvalidRequestError,
|
2024-04-28 13:15:23 +02:00
|
|
|
)
|
2024-04-28 13:04:07 +02:00
|
|
|
|
2022-03-20 10:46:23 +01:00
|
|
|
from app import create_app, db
|
2024-04-28 15:34:29 +02:00
|
|
|
from models.distribusi_model import Distribusis # noqa: F401
|
|
|
|
from models.user_model 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():
|
2024-05-28 23:02:17 +02:00
|
|
|
"""Admin CLI tool. To elevate a user to admin"""
|
|
|
|
app = create_app()
|
|
|
|
app.app_context().push()
|
|
|
|
elevateusertoadmin()
|
2022-03-20 10:46:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
def elevateusertoadmin():
|
2024-05-28 23:02:17 +02:00
|
|
|
"""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")
|
2022-03-20 10:46:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
admintool()
|