general: remove obsolete pastell connector (#44148)
This commit is contained in:
parent
aaba26e6ee
commit
02a3061f72
|
@ -1,28 +0,0 @@
|
|||
# passerelle - uniform access to multiple data sources and services
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import django.apps
|
||||
|
||||
class AppConfig(django.apps.AppConfig):
|
||||
name = 'passerelle.apps.pastell'
|
||||
label = 'pastell'
|
||||
|
||||
def get_connector_model(self):
|
||||
from . import models
|
||||
return models.Pastell
|
||||
|
||||
|
||||
default_app_config = 'passerelle.apps.pastell.AppConfig'
|
|
@ -1,56 +0,0 @@
|
|||
from django import forms
|
||||
|
||||
from passerelle.forms import GenericConnectorForm
|
||||
|
||||
from .models import Pastell
|
||||
|
||||
class PastellForm(GenericConnectorForm):
|
||||
class Meta:
|
||||
model = Pastell
|
||||
exclude = ('slug', 'users', 'document_type', 'document_fields')
|
||||
|
||||
|
||||
class PastellTypeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Pastell
|
||||
fields = ('document_type',)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PastellTypeForm, self).__init__(*args, **kwargs)
|
||||
choices = self.instance.get_document_type_choices()
|
||||
self.fields['document_type'].choices = choices
|
||||
self.fields['document_type'].widget = forms.Select(choices=choices)
|
||||
|
||||
|
||||
def save(self, commit=True):
|
||||
return super(PastellTypeForm, self).save(commit=commit)
|
||||
|
||||
|
||||
class PastellFieldsForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Pastell
|
||||
fields = ()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PastellFieldsForm, self).__init__(*args, **kwargs)
|
||||
fields = self.instance.get_document_fields()
|
||||
initial_data = self.instance.document_fields or {}
|
||||
for field_id, field_data in fields.items():
|
||||
if field_data.get('no-show') == '1':
|
||||
continue
|
||||
if field_data.get('name') is None:
|
||||
continue
|
||||
if field_data.get('type') in ('password', 'file'):
|
||||
continue
|
||||
self.fields[field_id] = forms.CharField(
|
||||
label=field_data.get('name'),
|
||||
required=field_data.get('requis') == '1',
|
||||
initial=initial_data.get(field_id),
|
||||
)
|
||||
if field_data.get('type') == 'textarea':
|
||||
self.fields[field_id].widget = forms.Textarea()
|
||||
|
||||
|
||||
def save(self, commit=True):
|
||||
self.instance.document_fields = self.cleaned_data
|
||||
return super(PastellFieldsForm, self).save(commit=commit)
|
|
@ -1,36 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import django.contrib.postgres.fields.jsonb
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Pastell',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('title', models.CharField(verbose_name='Title', max_length=50)),
|
||||
('slug', models.SlugField(verbose_name='Identifier', unique=True)),
|
||||
('description', models.TextField(verbose_name='Description')),
|
||||
('url', models.CharField(help_text='Pastell URL', max_length=128, verbose_name='URL')),
|
||||
('verify_cert', models.BooleanField(default=True, verbose_name='Check HTTPS Certificate validity')),
|
||||
('username', models.CharField(max_length=128, verbose_name='Username')),
|
||||
('password', models.CharField(max_length=128, verbose_name='Password')),
|
||||
('keystore', models.FileField(help_text='Certificate and private key in PEM format', upload_to=b'pastell', null=True, verbose_name='Keystore')),
|
||||
('document_type', models.CharField(max_length=128, verbose_name='Document Type', blank=True)),
|
||||
('document_fields', django.contrib.postgres.fields.jsonb.JSONField(null=True, verbose_name='Fields')),
|
||||
('users', models.ManyToManyField(to='base.ApiUser', related_name='_pastell_users_+', related_query_name='+', blank=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Pastell',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='pastell',
|
||||
name='log_level',
|
||||
field=models.CharField(default=b'NOTSET', max_length=10, verbose_name='Debug Enabled', blank=True, choices=[(b'DEBUG', b'DEBUG'), (b'INFO', b'INFO')]),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0002_pastell_log_level'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pastell',
|
||||
name='log_level',
|
||||
field=models.CharField(default=b'NOTSET', max_length=10, verbose_name='Log Level', choices=[(b'DEBUG', b'DEBUG'), (b'INFO', b'INFO')]),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0003_auto_20160316_0910'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pastell',
|
||||
name='log_level',
|
||||
field=models.CharField(default=b'NOTSET', max_length=10, verbose_name='Log Level', choices=[(b'NOTSET', b'NOTSET'), (b'DEBUG', b'DEBUG'), (b'INFO', b'INFO'), (b'WARNING', b'WARNING'), (b'ERROR', b'ERROR'), (b'CRITICAL', b'CRITICAL')]),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0004_auto_20160407_0456'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pastell',
|
||||
name='slug',
|
||||
field=models.SlugField(verbose_name='Identifier', unique=True),
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.12 on 2018-11-18 14:07
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0005_auto_20170920_0951'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='pastell',
|
||||
name='log_level',
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2020-05-04 12:02
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0006_remove_pastell_log_level'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pastell',
|
||||
name='keystore',
|
||||
field=models.FileField(help_text='Certificate and private key in PEM format', null=True, upload_to='pastell', verbose_name='Keystore'),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2020-05-04 12:06
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
from passerelle.utils.db import EnsureJsonbType
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pastell', '0007_auto_20200504_1402'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
EnsureJsonbType(model_name='Pastell', field_name='document_fields'),
|
||||
]
|
|
@ -1,96 +0,0 @@
|
|||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.core.cache import cache
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.template import Template, Context
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
|
||||
|
||||
class Pastell(BaseResource):
|
||||
url = models.CharField(max_length=128, blank=False,
|
||||
verbose_name=_('URL'),
|
||||
help_text=_('Pastell URL'))
|
||||
verify_cert = models.BooleanField(default=True,
|
||||
verbose_name=_('Check HTTPS Certificate validity'))
|
||||
username = models.CharField(max_length=128, blank=False,
|
||||
verbose_name=_('Username'))
|
||||
password = models.CharField(max_length=128, blank=False,
|
||||
verbose_name=_('Password'))
|
||||
keystore = models.FileField(upload_to='pastell', null=True,
|
||||
verbose_name=_('Keystore'),
|
||||
help_text=_('Certificate and private key in PEM format'))
|
||||
document_type = models.CharField(max_length=128, blank=True,
|
||||
verbose_name=_('Document Type'))
|
||||
document_fields = JSONField(null=True, verbose_name=_('Fields'))
|
||||
|
||||
category = _('Business Process Connectors')
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Pastell')
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('pastell-view', kwargs={'slug': self.slug})
|
||||
|
||||
@classmethod
|
||||
def get_verbose_name(cls):
|
||||
return cls._meta.verbose_name
|
||||
|
||||
@classmethod
|
||||
def get_manager_form_class(cls, *args, **kwargs):
|
||||
from .forms import PastellForm
|
||||
return PastellForm
|
||||
|
||||
def pastell_request(self, endpoint, **kwargs):
|
||||
if self.keystore:
|
||||
kwargs['cert'] = (self.keystore.path, self.keystore.path)
|
||||
if not self.verify_cert:
|
||||
kwargs['verify'] = False
|
||||
kwargs['auth'] = HTTPBasicAuth(self.username, self.password)
|
||||
return requests.get(self.url + '/api/' + endpoint, **kwargs).json()
|
||||
|
||||
def get_document_type_choices(self):
|
||||
cache_key = 'pastell-%s-document-types' % self.id
|
||||
choices = cache.get(cache_key)
|
||||
if choices:
|
||||
return choices
|
||||
|
||||
document_types = self.pastell_request('document-type.php')
|
||||
|
||||
choices = [(x, document_types.get(x).get('nom')) for x in document_types.keys()]
|
||||
cache.set(cache_key, choices, 300)
|
||||
|
||||
return choices
|
||||
|
||||
def get_document_fields(self):
|
||||
cache_key = 'pastell-%s-%s-document-fields' % (self.id, self.document_type)
|
||||
choices = cache.get(cache_key)
|
||||
if choices:
|
||||
return choices
|
||||
|
||||
data_dict = {'type': self.document_type}
|
||||
fields = self.pastell_request('document-type-info.php', params=data_dict)
|
||||
|
||||
cache.set(cache_key, fields, 300)
|
||||
|
||||
return fields
|
||||
|
||||
def create_document(self, data):
|
||||
data_dict = {}
|
||||
result = self.pastell_request('list-entite.php', params=data_dict)
|
||||
data_dict['id_e'] = result[0].get('id_e') # take first
|
||||
|
||||
data_dict['type'] = self.document_type
|
||||
result = self.pastell_request('create-document.php', params=data_dict)
|
||||
data_dict['id_d'] = result.get('id_d')
|
||||
|
||||
template_context = Context(data)
|
||||
for k, v in (self.document_fields or {}).items():
|
||||
template = Template(v)
|
||||
data_dict[k] = template.render(template_context)
|
||||
|
||||
self.pastell_request('modif-document.php', params=data_dict)
|
Binary file not shown.
Before Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB |
|
@ -1,36 +0,0 @@
|
|||
{% extends "passerelle/manage/service_view.html" %}
|
||||
{% load i18n passerelle %}
|
||||
|
||||
{% block description %}
|
||||
<p>
|
||||
{% trans 'Pastell URL:' %} {{ object.url }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% trans 'Document type:' %}
|
||||
{% if object.document_type %}
|
||||
{{ object.document_type }}
|
||||
(<a rel="popup" href="{% url 'pastell-type' slug=object.slug %}">{% trans 'change' %}</a>)
|
||||
{% else %}
|
||||
<a rel="popup" href="{% url 'pastell-type' slug=object.slug %}">{% trans 'select' %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
{% if object.document_type %}
|
||||
<h3>{% trans 'Document template' %}</h3>
|
||||
{% if fields %}
|
||||
{% for field in fields %}
|
||||
<p>{{ field.key }}: {{ field.value }}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
(<a rel="popup" href="{% url 'pastell-fields' slug=object.slug %}">{% trans 'edit' %}</a>)
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block security %}
|
||||
<p>
|
||||
{% trans 'Posting documents is limited to the following API users:' %}
|
||||
</p>
|
||||
{% access_rights_table resource=object permission='can_post_document' %}
|
||||
{% endblock %}
|
|
@ -1,15 +0,0 @@
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.conf.urls import url
|
||||
|
||||
from passerelle.apps.pastell.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<slug>[\w,-]+)/$', PastellDetailView.as_view(), name='pastell-view'),
|
||||
|
||||
url(r'^(?P<slug>[\w,-]+)/post/$', csrf_exempt(PostView.as_view()), name='pastell-post'),
|
||||
]
|
||||
|
||||
management_urlpatterns = [
|
||||
url(r'^(?P<slug>[\w,-]+)/type$', PastellTypeView.as_view(), name='pastell-type'),
|
||||
url(r'^(?P<slug>[\w,-]+)/fields$', PastellFieldsView.as_view(), name='pastell-fields'),
|
||||
]
|
|
@ -1,45 +0,0 @@
|
|||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
from django.views.generic.edit import UpdateView
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import Pastell
|
||||
from .forms import PastellTypeForm, PastellFieldsForm
|
||||
|
||||
class PostView(View, SingleObjectMixin):
|
||||
model = Pastell
|
||||
|
||||
@utils.protected_api('can_post_document')
|
||||
def post(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
self.get_object().create_document(data)
|
||||
result = {'result': 'ok'}
|
||||
return utils.response_for_json(request, result)
|
||||
|
||||
|
||||
class PastellDetailView(DetailView):
|
||||
model = Pastell
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PastellDetailView, self).get_context_data(**kwargs)
|
||||
if self.object.document_type and self.object.document_fields:
|
||||
context['fields'] = []
|
||||
for field in self.object.get_document_fields().keys():
|
||||
if self.object.document_fields.get(field):
|
||||
context['fields'].append({'key': field,
|
||||
'value': self.object.document_fields.get(field)})
|
||||
return context
|
||||
|
||||
|
||||
class PastellTypeView(UpdateView):
|
||||
model = Pastell
|
||||
form_class = PastellTypeForm
|
||||
template_name = 'passerelle/manage/service_form.html'
|
||||
|
||||
|
||||
class PastellFieldsView(UpdateView):
|
||||
model = Pastell
|
||||
form_class = PastellFieldsForm
|
||||
template_name = 'passerelle/manage/service_form.html'
|
|
@ -153,7 +153,6 @@ INSTALLED_APPS = (
|
|||
'passerelle.apps.orange',
|
||||
'passerelle.apps.ovh',
|
||||
'passerelle.apps.oxyd',
|
||||
'passerelle.apps.pastell',
|
||||
'passerelle.apps.phonecalls',
|
||||
'passerelle.apps.solis',
|
||||
'passerelle.apps.vivaticket',
|
||||
|
@ -164,7 +163,6 @@ INSTALLED_APPS = (
|
|||
# disable some applications for now
|
||||
PASSERELLE_APP_BDP_ENABLED = False
|
||||
PASSERELLE_APP_GDC_ENABLED = False
|
||||
PASSERELLE_APP_PASTELL_ENABLED = False
|
||||
PASSERELLE_APP_STRASBOURG_EU_ENABLED = False
|
||||
|
||||
# Authentication settings
|
||||
|
|
|
@ -14,11 +14,10 @@ from .views import (
|
|||
GenericViewLogsConnectorView, GenericLogView, GenericExportConnectorView,
|
||||
login, logout, menu_json)
|
||||
from .base.views import GenericViewJobsConnectorView, GenericJobView, GenericRestartJobView
|
||||
from .urls_utils import decorated_includes, required, app_enabled, manager_required
|
||||
from .urls_utils import decorated_includes, manager_required
|
||||
from .base.urls import access_urlpatterns, import_export_urlpatterns
|
||||
from .plugins import register_apps_urls
|
||||
|
||||
from passerelle.apps.pastell import urls as pastell_urls
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
|
@ -40,14 +39,6 @@ urlpatterns = [
|
|||
decorated_includes(manager_required, include(import_export_urlpatterns))),
|
||||
]
|
||||
|
||||
urlpatterns += required(
|
||||
app_enabled('pastell'), [
|
||||
url(r'^pastell/', include(pastell_urls.urlpatterns)),
|
||||
url(r'^manage/pastell/',
|
||||
decorated_includes(manager_required, include(pastell_urls.management_urlpatterns))),
|
||||
]
|
||||
)
|
||||
|
||||
# add patterns from apps
|
||||
urlpatterns = register_apps_urls(urlpatterns)
|
||||
|
||||
|
|
Loading…
Reference in New Issue