Jul 2nd - Optimized code 3
This commit is contained in:
+17
-11
@@ -1318,10 +1318,12 @@ def settings():
|
||||
'email_ingestion_move_to' : request.form.get('email_ingestion_move_to', 'Processed').strip(),
|
||||
'email_ingestion_interval': request.form.get('email_ingestion_interval', '5').strip(),
|
||||
}
|
||||
# Password: only update if a new value was provided
|
||||
# Password: only update if a new value was provided. Encrypted
|
||||
# at rest — see app/services/crypto_service.py.
|
||||
new_pw = request.form.get('email_ingestion_password', '').strip()
|
||||
if new_pw:
|
||||
fields['email_ingestion_password'] = new_pw
|
||||
from app.services.crypto_service import encrypt_secret
|
||||
fields['email_ingestion_password'] = encrypt_secret(new_pw)
|
||||
|
||||
changes = []
|
||||
for key, value in fields.items():
|
||||
@@ -1408,14 +1410,17 @@ def settings():
|
||||
registration_enabled = SystemSetting.get_bool('registration_enabled', default=True)
|
||||
survey_enabled = SystemSetting.get_bool('survey_enabled', default=True)
|
||||
email_settings = {
|
||||
'enabled' : SystemSetting.get_bool('email_ingestion_enabled', default=False),
|
||||
'host' : SystemSetting.get('email_ingestion_host', ''),
|
||||
'port' : SystemSetting.get('email_ingestion_port', '993'),
|
||||
'user' : SystemSetting.get('email_ingestion_user', ''),
|
||||
'password': SystemSetting.get('email_ingestion_password', ''),
|
||||
'folder' : SystemSetting.get('email_ingestion_folder', 'INBOX'),
|
||||
'move_to' : SystemSetting.get('email_ingestion_move_to', 'Processed'),
|
||||
'interval': SystemSetting.get('email_ingestion_interval', '5'),
|
||||
'enabled' : SystemSetting.get_bool('email_ingestion_enabled', default=False),
|
||||
'host' : SystemSetting.get('email_ingestion_host', ''),
|
||||
'port' : SystemSetting.get('email_ingestion_port', '993'),
|
||||
'user' : SystemSetting.get('email_ingestion_user', ''),
|
||||
# The stored password is never sent back to the browser — the field
|
||||
# is always rendered blank with a placeholder indicating whether one
|
||||
# is already configured (see settings.html).
|
||||
'has_password': bool(SystemSetting.get('email_ingestion_password', '')),
|
||||
'folder' : SystemSetting.get('email_ingestion_folder', 'INBOX'),
|
||||
'move_to' : SystemSetting.get('email_ingestion_move_to', 'Processed'),
|
||||
'interval' : SystemSetting.get('email_ingestion_interval', '5'),
|
||||
}
|
||||
branding_settings = {
|
||||
'app_name' : SystemSetting.get('app_name', 'TechDesk'),
|
||||
@@ -1477,7 +1482,8 @@ def email_ingestion_test():
|
||||
|
||||
# Fall back to the stored password if the admin left the field blank
|
||||
if not password:
|
||||
password = SystemSetting.get('email_ingestion_password', '')
|
||||
from app.services.crypto_service import decrypt_secret
|
||||
password = decrypt_secret(SystemSetting.get('email_ingestion_password', ''))
|
||||
|
||||
if not host or not user or not password:
|
||||
return jsonify(ok=False, message='Host, username, and password are required.')
|
||||
|
||||
@@ -86,22 +86,6 @@ def save_attachment(file, ticket_id=None, comment_id=None, uploader_id=None):
|
||||
)
|
||||
db.session.add(att)
|
||||
return att
|
||||
filename = secure_filename(file.filename)
|
||||
ext = filename.rsplit('.', 1)[1].lower() if '.' in filename else ''
|
||||
stored_name = f"{uuid.uuid4().hex}.{ext}"
|
||||
upload_dir = current_app.config['UPLOAD_FOLDER']
|
||||
file.save(os.path.join(upload_dir, stored_name))
|
||||
att = Attachment(
|
||||
ticket_id = ticket_id,
|
||||
comment_id = comment_id,
|
||||
filename = filename,
|
||||
stored_name= stored_name,
|
||||
file_size = os.path.getsize(os.path.join(upload_dir, stored_name)),
|
||||
mime_type = file.content_type,
|
||||
uploaded_by= uploader_id,
|
||||
)
|
||||
db.session.add(att)
|
||||
return att
|
||||
|
||||
|
||||
# ─── Dashboard ────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user