- Partner model additions
- menu changes to allow for partners - partner views and forms now in partner_forms.py and partner_views.py - Introduction of services layer - Allow all configuration to handle partner configurations, and adaptation of caching to allow for this
This commit is contained in:
@@ -8,7 +8,7 @@ import ast
|
||||
|
||||
from common.models.user import User, Tenant, Role, TenantDomain, TenantProject, PartnerTenant
|
||||
from common.extensions import db, security, minio_client, simple_encryption
|
||||
from common.services.user_service import UserService
|
||||
from common.services.user_services import UserServices
|
||||
from common.utils.security_utils import send_confirmation_email, send_reset_email
|
||||
from config.type_defs.service_types import SERVICE_TYPES
|
||||
from .user_forms import TenantForm, CreateUserForm, EditUserForm, TenantDomainForm, TenantSelectionForm, \
|
||||
@@ -19,7 +19,8 @@ from common.utils.simple_encryption import generate_api_key
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
from common.utils.eveai_exceptions import EveAIException
|
||||
from common.utils.document_utils import set_logging_information, update_logging_information
|
||||
from common.services.tenant_service import TenantService
|
||||
from common.services.tenant_services import TenantServices
|
||||
from common.services.user_services import UserServices
|
||||
|
||||
user_bp = Blueprint('user_bp', __name__, url_prefix='/user')
|
||||
|
||||
@@ -37,6 +38,10 @@ def log_after_request(response):
|
||||
@user_bp.route('/tenant', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin')
|
||||
def tenant():
|
||||
if not current_user.has_roles('Partner Admin') and UserServices.can_user_create_tenant():
|
||||
current_app.logger.error(f'User {current_user.email} cannot create tenant in the current user')
|
||||
flash(f"You don't have the appropriate permissions to create a tenant", 'danger')
|
||||
return redirect(prefixed_url_for('user_bp.select_tenant'))
|
||||
form = TenantForm()
|
||||
if request.method == 'GET':
|
||||
code = f"TENANT-{str(uuid.uuid4())}"
|
||||
@@ -58,10 +63,10 @@ def tenant():
|
||||
|
||||
if current_user.has_roles('Partner Admin') and 'partner' in session:
|
||||
# Always associate with the partner for Partner Admins
|
||||
TenantService.associate_tenant_with_partner(new_tenant.id)
|
||||
TenantServices.associate_tenant_with_partner(new_tenant.id)
|
||||
elif current_user.has_roles('Super User') and form.assign_to_partner.data and 'partner' in session:
|
||||
# Super User chose to associate with partner
|
||||
TenantService.associate_tenant_with_partner(new_tenant.id)
|
||||
TenantServices.associate_tenant_with_partner(new_tenant.id)
|
||||
|
||||
except SQLAlchemyError as e:
|
||||
current_app.logger.error(f'Failed to add tenant to database. Error: {str(e)}')
|
||||
@@ -183,7 +188,7 @@ def edit_user(user_id):
|
||||
# Update roles
|
||||
current_roles = set(role.id for role in user.roles)
|
||||
selected_roles = set(form.roles.data)
|
||||
if UserService.validate_role_assignments(selected_roles):
|
||||
if UserServices.validate_role_assignments(selected_roles):
|
||||
# Add new roles
|
||||
for role_id in selected_roles - current_roles:
|
||||
role = Role.query.get(role_id)
|
||||
@@ -273,10 +278,10 @@ def handle_tenant_selection():
|
||||
|
||||
tenant_identification = request.form['selected_row']
|
||||
tenant_id = ast.literal_eval(tenant_identification).get('value')
|
||||
if not TenantService.can_user_edit_tenant(tenant_id):
|
||||
if not UserServices.can_user_edit_tenant(tenant_id):
|
||||
current_app.logger.info(f"User not authenticated to edit tenant {tenant_id}.")
|
||||
flash(f"You are not authenticated to manage tenant {tenant_id}", 'danger')
|
||||
return redirect(prefixed_url_for('select_tenant'))
|
||||
return redirect(prefixed_url_for('user_bp.select_tenant'))
|
||||
the_tenant = Tenant.query.get(tenant_id)
|
||||
|
||||
# set tenant information in the session
|
||||
|
||||
Reference in New Issue
Block a user