Employees: external photo base URL is a setting
External HR Picture values are relative paths; the resolver hardcoded /static/employees/ (which the SPA then mounts under the subpath, e.g. /ops/static/...), but sites like WJ serve those photos from the classic EmployeeDBAPP on another URL entirely. New setting employee_photo_base_url (blank keeps the old behavior; a full URL like https://host/EmployeeDBAPP/images/ passes through withBase untouched), declared in the plugin config schema.
This commit is contained in:
@@ -43,9 +43,10 @@ EMPLOYEE_PHOTO_EXTENSIONS = {'.png', '.jpg', '.jpeg', '.gif', '.webp'}
|
||||
# URL prefix a served upload resolves to (self-hosted mode).
|
||||
EMPLOYEE_PHOTO_URL_PREFIX = '/api/employees/photo/'
|
||||
|
||||
# URL prefix external HR relative picture paths resolve under. The HR employees
|
||||
# table stores Picture as a relative path (e.g. 'Support/210009518.png') that
|
||||
# the site serves from /static/employees/; this matches the shopfloor feed.
|
||||
# Fallback URL prefix external HR relative picture paths resolve under when
|
||||
# the employee_photo_base_url setting is unset. Sites whose photos live on
|
||||
# another host (e.g. the classic EmployeeDBAPP) set the setting to a full URL
|
||||
# such as https://host/EmployeeDBAPP/images/ instead.
|
||||
EMPLOYEE_PHOTO_STATIC_PREFIX = '/static/employees/'
|
||||
|
||||
|
||||
@@ -96,7 +97,10 @@ def _external_photo_url(picture):
|
||||
return None
|
||||
if text.startswith(('http://', 'https://', '/')):
|
||||
return text
|
||||
return EMPLOYEE_PHOTO_STATIC_PREFIX + text
|
||||
from shopdb.api import Setting
|
||||
base = (Setting.get('employee_photo_base_url') or '').strip() \
|
||||
or EMPLOYEE_PHOTO_STATIC_PREFIX
|
||||
return base.rstrip('/') + '/' + text.lstrip('/')
|
||||
|
||||
|
||||
def _hr_picture(sso):
|
||||
|
||||
@@ -79,6 +79,11 @@ class EmployeesPlugin(BasePlugin):
|
||||
"""Employee directory DB connection. Host/name/user are settings the
|
||||
wizard can edit; the password stays in .env (emitted, not stored)."""
|
||||
return [
|
||||
{'key': 'employee_photo_base_url', 'label': 'Photo base URL',
|
||||
'type': 'text', 'secret': False,
|
||||
'help': 'Where external HR relative Picture paths resolve, e.g. '
|
||||
'https://host/EmployeeDBAPP/images/. Blank = this '
|
||||
'site\'s /static/employees/.'},
|
||||
{'key': 'employee_db_host', 'label': 'Employee DB host', 'type': 'text',
|
||||
'secret': False, 'default': 'localhost',
|
||||
'help': 'This DB must expose an "employees" table or view with columns '
|
||||
|
||||
Reference in New Issue
Block a user