Accidental refactor, split out legacy.py into separate sumodules and update all call sites.
This commit is contained in:
parent
2109d24483
commit
3efaa255e8
92 changed files with 4458 additions and 4269 deletions
|
@ -2,33 +2,31 @@
|
|||
|
||||
import string
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
|
||||
from random import SystemRandom
|
||||
from app import app, avatar, superusers, authentication
|
||||
from flask import request
|
||||
|
||||
from endpoints.api import (ApiResource, nickname, resource, validate_json_request, request_error,
|
||||
log_action, internal_only, NotFound, require_user_admin, format_date,
|
||||
InvalidToken, require_scope, format_date, hide_if, show_if, parse_args,
|
||||
query_param, abort, require_fresh_login, path_param, verify_not_prod)
|
||||
|
||||
from endpoints.api.logs import get_logs
|
||||
|
||||
from data import model
|
||||
from auth.permissions import SuperUserPermission
|
||||
from auth.auth_context import get_authenticated_user
|
||||
from auth import scopes
|
||||
from util.useremails import send_confirmation_email, send_recovery_email
|
||||
|
||||
import features
|
||||
|
||||
from app import app, avatar, superusers, authentication
|
||||
from endpoints.api import (ApiResource, nickname, resource, validate_json_request,
|
||||
internal_only, require_scope, show_if, parse_args,
|
||||
query_param, abort, require_fresh_login, path_param, verify_not_prod)
|
||||
from endpoints.api.logs import get_logs
|
||||
from data import model
|
||||
from auth.permissions import SuperUserPermission
|
||||
from auth import scopes
|
||||
from util.useremails import send_confirmation_email, send_recovery_email
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_immediate_subdirectories(directory):
|
||||
return [name for name in os.listdir(directory) if os.path.isdir(os.path.join(directory, name))]
|
||||
|
||||
|
||||
def get_services():
|
||||
services = set(get_immediate_subdirectories(app.config['SYSTEM_SERVICES_PATH']))
|
||||
services = services - set(app.config['SYSTEM_SERVICE_BLACKLIST'])
|
||||
|
@ -55,7 +53,7 @@ class SuperUserGetLogsForService(ApiResource):
|
|||
with open(app.config['SYSTEM_LOGS_FILE'], 'r') as f:
|
||||
logs = [line for line in f if line.find(service + '[') >= 0]
|
||||
|
||||
except Exception as ex:
|
||||
except Exception:
|
||||
logger.exception('Cannot read logs')
|
||||
abort(400)
|
||||
|
||||
|
@ -102,7 +100,6 @@ class SuperUserLogs(ApiResource):
|
|||
def get(self, args):
|
||||
""" List the usage logs for the current system. """
|
||||
if SuperUserPermission().can():
|
||||
performer_name = args['performer']
|
||||
start_time = args['starttime']
|
||||
end_time = args['endtime']
|
||||
|
||||
|
@ -144,7 +141,7 @@ class ChangeLog(ApiResource):
|
|||
def get(self):
|
||||
""" Returns the change log for this installation. """
|
||||
if SuperUserPermission().can():
|
||||
with open ('CHANGELOG.md', 'r') as f:
|
||||
with open('CHANGELOG.md', 'r') as f:
|
||||
return {
|
||||
'log': f.read()
|
||||
}
|
||||
|
@ -165,7 +162,7 @@ class SuperUserOrganizationList(ApiResource):
|
|||
def get(self):
|
||||
""" Returns a list of all organizations in the system. """
|
||||
if SuperUserPermission().can():
|
||||
orgs = model.get_organizations()
|
||||
orgs = model.organization.get_organizations()
|
||||
return {
|
||||
'organizations': [org_view(org) for org in orgs]
|
||||
}
|
||||
|
@ -204,7 +201,7 @@ class SuperUserList(ApiResource):
|
|||
def get(self):
|
||||
""" Returns a list of all users in the system. """
|
||||
if SuperUserPermission().can():
|
||||
users = model.get_active_users()
|
||||
users = model.user.get_active_users()
|
||||
return {
|
||||
'users': [user_view(user) for user in users]
|
||||
}
|
||||
|
@ -226,14 +223,14 @@ class SuperUserList(ApiResource):
|
|||
|
||||
# Generate a temporary password for the user.
|
||||
random = SystemRandom()
|
||||
password = ''.join([random.choice(string.ascii_uppercase + string.digits) for _ in range(32)])
|
||||
password = ''.join([random.choice(string.ascii_uppercase + string.digits) for _ in range(32)])
|
||||
|
||||
# Create the user.
|
||||
user = model.create_user(username, password, email, auto_verify=not features.MAILING)
|
||||
user = model.user.create_user(username, password, email, auto_verify=not features.MAILING)
|
||||
|
||||
# If mailing is turned on, send the user a verification email.
|
||||
if features.MAILING:
|
||||
confirmation = model.create_confirm_email_code(user)
|
||||
confirmation = model.user.create_confirm_email_code(user)
|
||||
send_confirmation_email(user.username, user.email, confirmation.code)
|
||||
|
||||
return {
|
||||
|
@ -258,14 +255,14 @@ class SuperUserSendRecoveryEmail(ApiResource):
|
|||
@require_scope(scopes.SUPERUSER)
|
||||
def post(self, username):
|
||||
if SuperUserPermission().can():
|
||||
user = model.get_nonrobot_user(username)
|
||||
user = model.user.get_nonrobot_user(username)
|
||||
if not user:
|
||||
abort(404)
|
||||
|
||||
if superusers.is_superuser(username):
|
||||
abort(403)
|
||||
abort(403)
|
||||
|
||||
code = model.create_reset_password_email_code(user.email)
|
||||
code = model.user.create_reset_password_email_code(user.email)
|
||||
send_recovery_email(user.email, code.code)
|
||||
return {
|
||||
'email': user.email
|
||||
|
@ -309,7 +306,7 @@ class SuperUserManagement(ApiResource):
|
|||
def get(self, username):
|
||||
""" Returns information about the specified user. """
|
||||
if SuperUserPermission().can():
|
||||
user = model.get_nonrobot_user(username)
|
||||
user = model.user.get_nonrobot_user(username)
|
||||
if not user:
|
||||
abort(404)
|
||||
|
||||
|
@ -324,14 +321,14 @@ class SuperUserManagement(ApiResource):
|
|||
def delete(self, username):
|
||||
""" Deletes the specified user. """
|
||||
if SuperUserPermission().can():
|
||||
user = model.get_nonrobot_user(username)
|
||||
user = model.user.get_nonrobot_user(username)
|
||||
if not user:
|
||||
abort(404)
|
||||
|
||||
if superusers.is_superuser(username):
|
||||
abort(403)
|
||||
abort(403)
|
||||
|
||||
model.delete_user(user)
|
||||
model.user.delete_user(user)
|
||||
return 'Deleted', 204
|
||||
|
||||
abort(403)
|
||||
|
@ -344,26 +341,26 @@ class SuperUserManagement(ApiResource):
|
|||
def put(self, username):
|
||||
""" Updates information about the specified user. """
|
||||
if SuperUserPermission().can():
|
||||
user = model.get_nonrobot_user(username)
|
||||
if not user:
|
||||
abort(404)
|
||||
user = model.user.get_nonrobot_user(username)
|
||||
if not user:
|
||||
abort(404)
|
||||
|
||||
if superusers.is_superuser(username):
|
||||
abort(403)
|
||||
if superusers.is_superuser(username):
|
||||
abort(403)
|
||||
|
||||
user_data = request.get_json()
|
||||
if 'password' in user_data:
|
||||
model.change_password(user, user_data['password'])
|
||||
user_data = request.get_json()
|
||||
if 'password' in user_data:
|
||||
model.user.change_password(user, user_data['password'])
|
||||
|
||||
if 'email' in user_data:
|
||||
model.update_email(user, user_data['email'], auto_verify=True)
|
||||
if 'email' in user_data:
|
||||
model.user.update_email(user, user_data['email'], auto_verify=True)
|
||||
|
||||
if 'enabled' in user_data:
|
||||
# Disable/enable the user.
|
||||
user.enabled = bool(user_data['enabled'])
|
||||
user.save()
|
||||
if 'enabled' in user_data:
|
||||
# Disable/enable the user.
|
||||
user.enabled = bool(user_data['enabled'])
|
||||
user.save()
|
||||
|
||||
return user_view(user, password=user_data.get('password'))
|
||||
return user_view(user, password=user_data.get('password'))
|
||||
|
||||
abort(403)
|
||||
|
||||
|
@ -395,9 +392,9 @@ class SuperUserOrganizationManagement(ApiResource):
|
|||
def delete(self, name):
|
||||
""" Deletes the specified organization. """
|
||||
if SuperUserPermission().can():
|
||||
org = model.get_organization(name)
|
||||
org = model.organization.get_organization(name)
|
||||
|
||||
model.delete_user(org)
|
||||
model.user.delete_user(org)
|
||||
return 'Deleted', 204
|
||||
|
||||
abort(403)
|
||||
|
@ -410,12 +407,12 @@ class SuperUserOrganizationManagement(ApiResource):
|
|||
def put(self, name):
|
||||
""" Updates information about the specified user. """
|
||||
if SuperUserPermission().can():
|
||||
org = model.get_organization(name)
|
||||
org_data = request.get_json()
|
||||
org = model.organization.get_organization(name)
|
||||
org_data = request.get_json()
|
||||
|
||||
if 'name' in org_data:
|
||||
org = model.change_username(org.id, org_data['name'])
|
||||
if 'name' in org_data:
|
||||
org = model.user.change_username(org.id, org_data['name'])
|
||||
|
||||
return org_view(org)
|
||||
return org_view(org)
|
||||
|
||||
abort(403)
|
||||
|
|
Reference in a new issue