API - move set-admin command in users blueprint

This commit is contained in:
Sam 2022-02-13 14:36:10 +01:00
parent e773be0e1a
commit 18e4ba61fc
5 changed files with 17 additions and 17 deletions

View File

@ -162,7 +162,7 @@ serve-python-dev:
$(FLASK) run --with-threads -h $(HOST) -p $(PORT) --cert=adhoc
set-admin:
$(FLASK) set-admin $(USERNAME)
$(FLASK) users set-admin $(USERNAME)
test-e2e: init-db
$(PYTEST) e2e --driver firefox $(PYTEST_ARGS)

View File

@ -4,4 +4,4 @@ cd /usr/src/app
source .env.docker
flask set-admin $1
flask users set-admin $1

View File

@ -3,14 +3,11 @@
import os
from typing import Dict, Optional
import click
import gunicorn.app.base
from flask import Flask
from flask_migrate import upgrade
from fittrackee import create_app
from fittrackee.users.exceptions import UserNotFoundException
from fittrackee.users.utils import set_admin_rights
HOST = os.getenv('HOST', '0.0.0.0')
PORT = os.getenv('PORT', '5000')
@ -45,17 +42,6 @@ def upgrade_db() -> None:
upgrade(directory=BASEDIR + '/migrations')
@app.cli.command('set-admin')
@click.argument('username')
def set_admin(username: str) -> None:
"""Set admin rights for given user"""
try:
set_admin_rights(username)
print(f"User '{username}' updated.")
except UserNotFoundException:
print(f"User '{username}' not found.")
def main() -> None:
options = {'bind': f'{HOST}:{PORT}', 'workers': WORKERS}
StandaloneApplication(app, options).run()

View File

@ -2,6 +2,7 @@ import os
import shutil
from typing import Any, Dict, Tuple, Union
import click
from flask import Blueprint, request, send_file
from sqlalchemy import exc
@ -18,13 +19,26 @@ from fittrackee.workouts.models import Record, Workout, WorkoutSegment
from fittrackee.workouts.utils_files import get_absolute_file_path
from .decorators import authenticate, authenticate_as_admin
from .exceptions import UserNotFoundException
from .models import User, UserSportPreference
from .utils import set_admin_rights
users_blueprint = Blueprint('users', __name__)
USER_PER_PAGE = 10
@users_blueprint.cli.command('set-admin')
@click.argument('username')
def set_admin(username: str) -> None:
"""Set admin rights for given user"""
try:
set_admin_rights(username)
print(f"User '{username}' updated.")
except UserNotFoundException:
print(f"User '{username}' not found.")
@users_blueprint.route('/users', methods=['GET'])
@authenticate
def get_users(auth_user: User) -> Dict:

View File

@ -62,7 +62,7 @@ Sphinx = "^4.4.0"
[tool.poetry.scripts]
fittrackee = 'fittrackee.__main__:main'
fittrackee_set_admin = 'fittrackee.__main__:set_admin'
fittrackee_set_admin = 'fittrackee.users.users:set_admin'
fittrackee_upgrade_db = 'fittrackee.__main__:upgrade_db'
fittrackee_worker = 'flask_dramatiq:worker'