From f41fefbaa7964976957780a6be5e79ec6f2a71dd Mon Sep 17 00:00:00 2001 From: lokses Date: Thu, 10 Sep 2026 13:17:41 +0300 Subject: [PATCH] =?UTF-8?q?nextcloud/onlyoffice:=20=D1=82=D0=B8=D0=BF=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D0=BD=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B8=20UI=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ConnectorConfig(onlyoffice) + миграция, подсказка по extra_config в админке. - /documents/onlyoffice/ в whitelist 2FA — Document Server забирает файл без сессии портала (доступ по подписанному file-token + JWT DS). - Страница редактора и кнопки «открыть в OnlyOffice» в браузере документов. Co-Authored-By: Claude Opus 4.8 --- apps/employees/middleware.py | 1 + core/admin.py | 5 +++ core/migrations/0019_onlyoffice_connector.py | 30 ++++++++++++++++ core/models/connector_config.py | 8 ++++- templates/pages/documents-editor.html | 36 ++++++++++++++++++++ templates/partials/documents-browser.html | 7 ++++ templates/partials/pharmacy-documents.html | 5 +++ 7 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 core/migrations/0019_onlyoffice_connector.py create mode 100644 templates/pages/documents-editor.html diff --git a/apps/employees/middleware.py b/apps/employees/middleware.py index a2a56ce..bd94d4f 100644 --- a/apps/employees/middleware.py +++ b/apps/employees/middleware.py @@ -40,6 +40,7 @@ class TwoFactorMiddleware: '/2fa/', '/logout/', '/accounts/login/', '/login/', '/set-password/', '/admin/login/', '/admin/logout/', '/i18n/', '/static/', + '/documents/onlyoffice/', # Document Server забирает файл без сессии портала ) def __init__(self, get_response): diff --git a/core/admin.py b/core/admin.py index 581e541..40de151 100644 --- a/core/admin.py +++ b/core/admin.py @@ -274,6 +274,11 @@ class ConnectorConfigAdmin(ModelAdmin): }), (_('Дополнительные параметры'), { 'fields': ('extra_config',), + 'description': _( + 'OnlyOffice: {"public_url": "https://docs.example", ' + '"callback_base": "https://portal.example"} — ' + 'token = JWT_SECRET Document Server. Nextcloud остаётся хранилищем файлов.' + ), }), ) diff --git a/core/migrations/0019_onlyoffice_connector.py b/core/migrations/0019_onlyoffice_connector.py new file mode 100644 index 0000000..d5c6f5f --- /dev/null +++ b/core/migrations/0019_onlyoffice_connector.py @@ -0,0 +1,30 @@ +# Generated by Django 6.0.3 on 2026-09-10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0018_recruiting_pharmacy_access'), + ] + + operations = [ + migrations.AlterField( + model_name='connectorconfig', + name='connector_type', + field=models.CharField( + choices=[ + ('mattermost', 'Mattermost'), + ('ad', 'Active Directory'), + ('carbonio', 'Carbonio CE'), + ('mail', 'Почта (IMAP/SMTP)'), + ('nextcloud', 'Nextcloud'), + ('onlyoffice', 'OnlyOffice'), + ], + max_length=20, + unique=True, + verbose_name='Тип коннектора', + ), + ), + ] diff --git a/core/models/connector_config.py b/core/models/connector_config.py index 117eb07..662d8a8 100644 --- a/core/models/connector_config.py +++ b/core/models/connector_config.py @@ -12,6 +12,7 @@ class ConnectorConfig(BaseModel): ('carbonio', 'Carbonio CE'), ('mail', 'Почта (IMAP/SMTP)'), ('nextcloud', 'Nextcloud'), + ('onlyoffice', 'OnlyOffice'), ] connector_type = models.CharField( @@ -38,7 +39,12 @@ class ConnectorConfig(BaseModel): # Дополнительные параметры коннектора extra_config = models.JSONField( _('Дополнительные параметры'), default=dict, blank=True, - help_text=_('Специфичные для коннектора настройки в формате JSON') + help_text=_( + 'JSON. Nextcloud: verify_ssl, timeout. ' + 'OnlyOffice: public_url (URL Document Server), ' + 'callback_base (публичный URL портала для скачивания/сохранения файла), ' + 'verify_ssl.' + ), ) notes = models.TextField(_('Примечания'), blank=True) diff --git a/templates/pages/documents-editor.html b/templates/pages/documents-editor.html new file mode 100644 index 0000000..fd8c4ed --- /dev/null +++ b/templates/pages/documents-editor.html @@ -0,0 +1,36 @@ +{% load i18n %} +
+ +
+
+

{{ filename }}

+

+ {% if mode == 'edit' %}{% trans "Редактирование в OnlyOffice" %}{% else %}{% trans "Просмотр в OnlyOffice" %}{% endif %} +

+
+ {% if back.kind == 'pharmacy' %} + {% trans "К аптеке" %} + {% else %} + {% trans "К документам" %} + {% endif %} +
+ +
+
+ + + diff --git a/templates/partials/documents-browser.html b/templates/partials/documents-browser.html index db29c3e..694597d 100644 --- a/templates/partials/documents-browser.html +++ b/templates/partials/documents-browser.html @@ -44,9 +44,16 @@ hx-target="#documents-browser" hx-swap="innerHTML" style="color:var(--color-foreground); text-decoration:none; font-weight:500;">📁 {{ f.name }} {% else %} + {% if f.is_office and onlyoffice_ready %} + {{ f.name }} + {% trans "скачать" %} + {% else %} 📄 {{ f.name }} {% endif %} + {% endif %} {% if f.size is not None %}{{ f.size|filesizeformat }}{% endif %} diff --git a/templates/partials/pharmacy-documents.html b/templates/partials/pharmacy-documents.html index 805eebd..be59dd6 100644 --- a/templates/partials/pharmacy-documents.html +++ b/templates/partials/pharmacy-documents.html @@ -33,8 +33,13 @@ {% if f.is_dir %} {{ f.name }} {% else %} + {% if f.is_office and onlyoffice_ready %} + {{ f.name }} + {% else %} {{ f.name }} + {% endif %} {% endif %}