summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author <bdauvergne@entrouvert.com>2009-09-21 15:51:09 (GMT)
committer <bdauvergne@entrouvert.com>2009-09-21 15:51:09 (GMT)
commit2f7809fa941d4535ed03e68d3386c70347e47631 (patch)
tree72c0d0c1aa2c47e78e34d6c4ceb41c9c61444156
parentee33db1bb8d42d9ddfe67051dae305b311266ecb (diff)
downloadpratic-2f7809fa941d4535ed03e68d3386c70347e47631.zip
pratic-2f7809fa941d4535ed03e68d3386c70347e47631.tar.gz
pratic-2f7809fa941d4535ed03e68d3386c70347e47631.tar.bz2
- add static function to retrieve service_instances for a given service type
- add error checking when one is trying to delete a service for which service instances still exist.
-rw-r--r--idp/extra/modules/__init__.py5
-rw-r--r--idp/extra/modules/directory.py23
-rw-r--r--idp/extra/modules/services_ui.ptl25
3 files changed, 51 insertions, 2 deletions
diff --git a/idp/extra/modules/__init__.py b/idp/extra/modules/__init__.py
index e69de29..dd87174 100644
--- a/idp/extra/modules/__init__.py
+++ b/idp/extra/modules/__init__.py
@@ -0,0 +1,5 @@
+try:
+ from quixote.ptl import compile_package
+ compile_package(__path__)
+except ImportError:
+ pass
diff --git a/idp/extra/modules/directory.py b/idp/extra/modules/directory.py
index 4c66212..5f4717f 100644
--- a/idp/extra/modules/directory.py
+++ b/idp/extra/modules/directory.py
@@ -1,6 +1,7 @@
import sys
from sha import sha
import base64
+import re
try:
import ldap
@@ -486,6 +487,26 @@ def get_service_instances(collectivity):
+def get_service_instances_by_service_type(sid):
+ store = get_store()
+ result = store.ldap_conn.search_s(store.pratic_ldap_base,
+ ldap.SCOPE_SUBTREE, ldap.filter.filter_format('(&(objectClass=cdg59serviceInstance)(cdg59serviceType=%s))', (sid,)))
+ service_instances = [ServiceInstance(x) for x in result]
+ # fill missing fields for global services
+ services = get_services()
+ for si in service_instances:
+ try:
+ s = get_service(si.cdg59serviceType)
+ if s and s.cdg59isGlobal:
+ si.cdg59metadataURL = s.cdg59metadataURL
+ si.cdg59URL = s.cdg59URL
+ except KeyError:
+ # ignore error for removed service type
+ continue
+ return service_instances
+
+
+
def get_service_instance(collectivity, siid):
store = get_store()
result = store.ldap_conn.search_s(collectivity.dn,
@@ -501,7 +522,7 @@ def get_service_instance(collectivity, siid):
si.cdg59URL = s.cdg59URL
except KeyError:
# ignore error for removed service type
- continue
+ pass
return si
diff --git a/idp/extra/modules/services_ui.ptl b/idp/extra/modules/services_ui.ptl
index 7145958..4524e3e 100644
--- a/idp/extra/modules/services_ui.ptl
+++ b/idp/extra/modules/services_ui.ptl
@@ -2,6 +2,8 @@ import lasso
import tempfile
import re
import urllib2
+import ldap.dn
+import ldap
from quixote import get_request, get_response, get_session, redirect, get_publisher
from quixote.directory import Directory
@@ -362,9 +364,30 @@ class ServiceDirectory(Directory):
form.add_submit('cancel', _('Cancel'))
if form.get_submit() == 'cancel':
return redirect('../..')
- if not form.is_submitted() or form.has_errors():
+ service_instances = None
+ if form.is_submitted and not form.has_errors():
+ service_instances = directory.get_service_instances_by_service_type(self.service.cdg59sid)
+ if not service_instances:
+ html_text = html_text('<p>%s :</p>' % _('Cannot delete service. There are still service instances for this service'))
+ html_text += html_text('<ul>')
+ for si in service_instances:
+ sid=si.cdg59siid
+ try:
+ ou=[x[1] for x in ldap.dn.str2dn(si.dn, flags.DN_FORMAT_LDAPV3) if x[0] == 'ou' ]
+ collectivity = directory.get_collectivity(ou)
+ ou = collectivity.ou
+ link = url_quote("../../%s/%s/edit" % (ou,sid))
+ html_text += html_text('<li><a href="%s">%s - %s</a></li>' % (link, collectivity.cn, si.name))
+ except:
+ html_text += html_text('<li>%s</li>' % html_escape(si.dn))
+
+ html_text += html_text('</ul>')
+ get_session().message = ('error', html_text)
+
+ if not form.is_submitted() or form.has_errors() or service_instances:
get_response().breadcrumb.append(('delete', _('Delete')))
html_top('services', title = _('Delete Service'))
+
'<h2>%s</h2>' % _('Deleting Service: %s') % self.service.cn
form.render()
else: