- Initialisation of the EveAI Chat Client.
- Introduction of Tenant Makes
This commit is contained in:
@@ -5,12 +5,13 @@ from flask_security import roles_accepted, current_user
|
||||
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
|
||||
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.models.user import User, Tenant, Role, TenantDomain, TenantProject, PartnerTenant, TenantMake
|
||||
from common.extensions import db, security, minio_client, simple_encryption, cache_manager
|
||||
from common.utils.dynamic_field_utils import create_default_config_from_type_config
|
||||
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, \
|
||||
TenantProjectForm, EditTenantProjectForm
|
||||
TenantProjectForm, EditTenantProjectForm, TenantMakeForm
|
||||
from common.utils.database import Database
|
||||
from common.utils.view_assistants import prepare_table_for_macro, form_validation_failed
|
||||
from common.utils.simple_encryption import generate_api_key
|
||||
@@ -622,6 +623,108 @@ def delete_tenant_project(tenant_project_id):
|
||||
return redirect(prefixed_url_for('user_bp.tenant_projects'))
|
||||
|
||||
|
||||
@user_bp.route('/tenant_make', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def tenant_make():
|
||||
form = TenantMakeForm()
|
||||
if form.validate_on_submit():
|
||||
tenant_id = session['tenant']['id']
|
||||
new_tenant_make = TenantMake()
|
||||
form.populate_obj(new_tenant_make)
|
||||
new_tenant_make.tenant_id = tenant_id
|
||||
customisation_config = cache_manager.customisations_config_cache.get_config("CHAT_CLIENT_CUSTOMISATION")
|
||||
new_tenant_make.chat_customisation_options = create_default_config_from_type_config(
|
||||
customisation_config["configuration"])
|
||||
form.add_dynamic_fields("configuration", customisation_config, new_tenant_make.chat_customisation_options)
|
||||
set_logging_information(new_tenant_make, dt.now(tz.utc))
|
||||
|
||||
try:
|
||||
db.session.add(new_tenant_make)
|
||||
db.session.commit()
|
||||
flash('Tenant Make successfully added!', 'success')
|
||||
current_app.logger.info(f'Tenant Make {new_tenant_make.name} successfully added for tenant {tenant_id}!')
|
||||
# Enable step 2 of creation of retriever - add configuration of the retriever (dependent on type)
|
||||
return redirect(prefixed_url_for('user_bp.tenant_makes', tenant_make_id=new_tenant_make.id))
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to add Tenant Make. Error: {e}', 'danger')
|
||||
current_app.logger.error(f'Failed to add Tenant Make {new_tenant_make.name}'
|
||||
f'for tenant {tenant_id}. Error: {str(e)}')
|
||||
|
||||
return render_template('user/tenant_make.html', form=form)
|
||||
|
||||
|
||||
@user_bp.route('/tenant_makes', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def tenant_makes():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = request.args.get('per_page', 10, type=int)
|
||||
|
||||
query = TenantMake.query.order_by(TenantMake.id)
|
||||
|
||||
pagination = query.paginate(page=page, per_page=per_page)
|
||||
tenant_makes = pagination.items
|
||||
|
||||
# prepare table data
|
||||
rows = prepare_table_for_macro(tenant_makes,
|
||||
[('id', ''), ('name', ''), ('website', ''), ('active', '')])
|
||||
|
||||
# Render the tenant makes in a template
|
||||
return render_template('user/tenant_makes.html', rows=rows, pagination=pagination)
|
||||
|
||||
|
||||
@user_bp.route('/tenant_make/<int:tenant_make_id>', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def edit_tenant_make(tenant_make_id):
|
||||
"""Edit an existing tenant make configuration."""
|
||||
# Get the tenant make or return 404
|
||||
tenant_make = TenantMake.query.get_or_404(tenant_make_id)
|
||||
|
||||
# Create form instance with the tenant make
|
||||
form = TenantMakeForm(request.form, obj=tenant_make)
|
||||
|
||||
customisation_config = cache_manager.customisations_config_cache.get_config("CHAT_CLIENT_CUSTOMISATION")
|
||||
form.add_dynamic_fields("configuration", customisation_config, tenant_make.chat_customisation_options)
|
||||
|
||||
if form.validate_on_submit():
|
||||
# Update basic fields
|
||||
form.populate_obj(tenant_make)
|
||||
tenant_make.chat_customisation_options = form.get_dynamic_data("configuration")
|
||||
|
||||
# Update logging information
|
||||
update_logging_information(tenant_make, dt.now(tz.utc))
|
||||
|
||||
# Save changes to database
|
||||
try:
|
||||
db.session.add(tenant_make)
|
||||
db.session.commit()
|
||||
flash('Tenant Make updated successfully!', 'success')
|
||||
current_app.logger.info(f'Tenant Make {tenant_make.id} updated successfully')
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
flash(f'Failed to update tenant make. Error: {str(e)}', 'danger')
|
||||
current_app.logger.error(f'Failed to update tenant make {tenant_make_id}. Error: {str(e)}')
|
||||
return render_template('user/edit_tenant_make.html', form=form, tenant_make_id=tenant_make_id)
|
||||
|
||||
return redirect(prefixed_url_for('user_bp.tenant_makes'))
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('user/edit_tenant_make.html', form=form, tenant_make_id=tenant_make_id)
|
||||
|
||||
|
||||
@user_bp.route('/handle_tenant_make_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def handle_tenant_make_selection():
|
||||
action = request.form['action']
|
||||
if action == 'create_tenant_make':
|
||||
return redirect(prefixed_url_for('user_bp.tenant_make'))
|
||||
tenant_make_identification = request.form.get('selected_row')
|
||||
tenant_make_id = ast.literal_eval(tenant_make_identification).get('value')
|
||||
|
||||
if action == 'edit_tenant_make':
|
||||
return redirect(prefixed_url_for('user_bp.edit_tenant_make', tenant_make_id=tenant_make_id))
|
||||
|
||||
def reset_uniquifier(user):
|
||||
security.datastore.set_uniquifier(user)
|
||||
db.session.add(user)
|
||||
|
||||
Reference in New Issue
Block a user