0001-forms-remove-support-for-prefilling-fields-with-ID-W.patch
wcs/admin/fields.ptl | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
try: |
|
18 |
import lasso |
|
19 |
except ImportError: |
|
20 |
lasso = None |
|
21 | ||
22 | 17 |
from quixote import redirect, get_publisher |
23 | 18 |
from quixote.directory import Directory |
24 | 19 | |
... | ... | |
71 | 66 | |
72 | 67 |
large = False |
73 | 68 |
section = None |
74 |
wsf_support = False |
|
75 | 69 |
page_no = None |
76 | 70 | |
77 | 71 |
def html_top(self, *args, **kwargs): |
... | ... | |
83 | 77 |
self.field = [x for x in self.objectdef.fields if x.id == field_id][0] |
84 | 78 |
except IndexError: |
85 | 79 |
raise errors.TraversalError() |
86 |
if not lasso or not lasso.WSF_SUPPORT: |
|
87 |
self.wsf_support = False |
|
88 | 80 |
if not self.field.label: |
89 | 81 |
self.field.label = _('None') |
90 | 82 |
self.unhtmled_label = re.sub('<.*?>', ' ', self.field.label) |
wcs/admin/forms.ptl | ||
---|---|---|
175 | 175 | |
176 | 176 |
class FieldDefPage(FieldDefPage): |
177 | 177 |
section = 'forms' |
178 |
wsf_support = True |
|
179 | 178 | |
180 | 179 | |
181 | 180 |
class FieldsDirectory(FieldsDirectory): |
wcs/admin/settings.ptl | ||
---|---|---|
114 | 114 | |
115 | 115 |
class UserFieldDefPage(FieldDefPage): |
116 | 116 |
section = 'settings' |
117 |
wsf_support = False |
|
118 | 117 | |
119 | 118 |
class UserFieldsDirectory(FieldsDirectory): |
120 | 119 |
_q_exports = ['', 'update_order', 'new', 'mapping'] |
wcs/fields.py | ||
---|---|---|
53 | 53 |
options = [('none', _('None')), |
54 | 54 |
('string', _('String')), |
55 | 55 |
('formula', _('Formula (Python)')), |
56 |
('user', _('User Field')), |
|
57 |
('wsf', _('WSF Expression'))] |
|
56 |
('user', _('User Field'))] |
|
58 | 57 | |
59 | 58 |
self.add(SingleSelectWidget, 'type', options = options, value = value.get('type')) |
60 | 59 | |
... | ... | |
81 | 80 | |
82 | 81 |
self.add(SingleSelectWidget, 'value', value = value.get('value'), |
83 | 82 |
options = user_fields) |
84 |
elif self.value.get('type') == 'wsf': |
|
85 |
self.add(StringWidget, 'value', value = value.get('value')) |
|
86 | 83 | |
87 | 84 |
self.add(SubmitWidget, 'apply', value = _('Apply')) |
88 | 85 | |
... | ... | |
138 | 135 |
else: |
139 | 136 |
extra_fields = [] |
140 | 137 |
for attribute in self.get_admin_attributes() + extra_fields: |
141 |
if attribute in ('in_listing', 'wsf_prefill_explicit'): continue |
|
138 |
if attribute in ('in_listing', ): |
|
139 |
continue |
|
142 | 140 |
if hasattr(self, attribute) and getattr(self, attribute) is not None: |
143 | 141 |
val = getattr(self, attribute) |
144 | 142 |
if type(val) is dict: |
... | ... | |
266 | 264 |
hint = None |
267 | 265 |
required = True |
268 | 266 |
in_listing = True |
269 |
wsf_prefill_explicit = False |
|
270 | 267 |
extra_attributes = [] |
271 | 268 |
prefill = {} |
272 | 269 | |
... | ... | |
331 | 328 |
form.add(PrefillSelectionWidget, 'prefill', title = _('Prefill'), |
332 | 329 |
value = self.prefill) |
333 | 330 | |
334 |
if False and self.wsf_support: |
|
335 |
form.add(CheckboxWidget, 'wsf_prefill_explicit', |
|
336 |
title = _('Needs ID-WSF prefill explicit request'), |
|
337 |
value = self.wsf_prefill_explicit) |
|
338 | ||
339 | 331 |
def check_admin_form(self, form): |
340 | 332 |
return |
341 | 333 | |
342 | 334 |
def get_admin_attributes(self): |
343 | 335 |
return Field.get_admin_attributes(self) + ['required', 'hint', |
344 | 336 |
'varname', 'in_listing', |
345 |
'extra_css_class', 'prefill', |
|
346 |
'wsf_prefill_explicit'] |
|
337 |
'extra_css_class', 'prefill'] |
|
347 | 338 | |
348 | 339 |
def get_csv_heading(self): |
349 | 340 |
return [self.label] |
wcs/forms/root.ptl | ||
---|---|---|
45 | 45 |
from qommon.admin.texts import TextsDirectory |
46 | 46 | |
47 | 47 |
from backoffice import FormDefUI |
48 |
import qommon.idwsf as idwsf |
|
49 | 48 | |
50 | 49 |
try: |
51 | 50 |
from qommon.certificate import Certificate |
... | ... | |
54 | 53 |
m2crypto = False |
55 | 54 | |
56 | 55 |
try: |
57 |
import lasso |
|
58 |
except ImportError: |
|
59 |
lasso = None |
|
60 | ||
61 |
import qommon.liberty as liberty |
|
62 |
import StringIO as sio |
|
63 |
try: |
|
64 | 56 |
import elementtree.ElementTree as ET |
65 | 57 |
except ImportError: |
66 | 58 |
try: |
... | ... | |
224 | 216 |
break |
225 | 217 |
'</ol></div>' |
226 | 218 | |
227 |
def get_disco_epr(self): |
|
228 |
session=get_session() |
|
229 |
if not session.lasso_session_dump: |
|
230 |
return None |
|
231 |
lasso_session=lasso.Session.newFromDump(session.lasso_session_dump) |
|
232 |
if not lasso_session: |
|
233 |
return None |
|
234 |
assertions = lasso_session.assertions |
|
235 |
if not assertions or not assertions.values(): |
|
236 |
return None |
|
237 |
assertion = assertions.values()[0] |
|
238 |
if not isinstance(assertion, lasso.Saml2Assertion): |
|
239 |
return None |
|
240 |
return assertion.idwsf2GetDiscoveryBootstrapEpr() |
|
241 | ||
242 |
def get_eprs(self, service_type): |
|
243 |
disco_epr = self.get_disco_epr() |
|
244 |
if not disco_epr: |
|
245 |
return [] |
|
246 |
disco = idwsf.DiscoveryClient2(epr=disco_epr, |
|
247 |
server=misc.get_lasso_server(protocol='saml2')) |
|
248 |
disco.setLogger(get_logger()) |
|
249 |
eprs = disco.lookupService(service_type) |
|
250 |
return eprs |
|
251 | ||
252 |
def do_queries(self, epr, queries, namespaces, flatten=True): |
|
253 |
dst = idwsf.DSTClient2(epr=epr, |
|
254 |
server=misc.get_lasso_server(protocol='saml2')) |
|
255 |
dst.setLogger(get_logger()) |
|
256 |
result = dst.query(queries, flatten = flatten, namespaces = namespaces) |
|
257 |
return result |
|
258 | ||
259 |
def get_namespaces(self): |
|
260 |
namespaces = { |
|
261 |
'pp': getattr(lasso, 'PP11_HREF', getattr(lasso, 'PP_HREF', None)), # support old lasso |
|
262 |
'ep': getattr(lasso, 'EP_HREF', ''), |
|
263 |
'eoa': 'urn:entrouvert:id-sis-adeline:2005-09', # eo schema for adeline |
|
264 |
'cafp': 'urn:entrouvert:id-sis-caf-profile:2005-09', # eo schema for caf |
|
265 |
} |
|
266 |
namespaces.update(get_cfg('misc', {}).get('namespaces', {})) |
|
267 |
return namespaces |
|
268 | ||
269 |
def get_queries(self, fields): |
|
270 |
queries = {} |
|
271 |
for field in fields: |
|
272 |
query = field.prefill.get('value') |
|
273 |
if query: |
|
274 |
queries['f%s' % field.id] = query |
|
275 |
return queries |
|
276 | ||
277 |
def prefill_form(self, form, results): |
|
278 |
for key, value in results.items(): |
|
279 |
widget = form.get_widget(key) |
|
280 |
if widget and value: |
|
281 |
encoded = get_publisher().utf82sitecharset(value) |
|
282 |
widget.set_value(encoded) |
|
283 | ||
284 |
def wsf_prefill(self, form): |
|
285 |
service_types = self.get_namespaces() |
|
286 |
session = get_session() |
|
287 |
if not session.lasso_session_dump: |
|
288 |
return False |
|
289 |
if str('DiscoveryResourceOffering') in session.lasso_session_dump: |
|
290 |
idwsf = 1 |
|
291 |
if str('urn:liberty:disco:2006-08:DiscoveryEPR') in session.lasso_session_dump: |
|
292 |
idwsf = 2 |
|
293 | ||
294 |
request = get_request() |
|
295 |
prefill_fields = [] |
|
296 |
if request.form.has_key('prefill') and type(request.form['prefill']) is list: |
|
297 |
prefill_fields = request.form['prefill'] |
|
298 | ||
299 |
prefixes = {} |
|
300 |
for f in self.formdef.fields: |
|
301 |
if not f.prefill: |
|
302 |
continue |
|
303 |
if f.prefill.get('type') != 'wsf': |
|
304 |
continue |
|
305 |
if prefill_fields and not f.id in prefill_fields: |
|
306 |
continue |
|
307 |
if f.wsf_prefill_explicit and not f.id in prefill_fields: |
|
308 |
continue |
|
309 |
wsf_prefill_expression = f.prefill.get('value') |
|
310 |
m = re.search('/*(\w+):', wsf_prefill_expression) |
|
311 |
prefix = m.group(1) |
|
312 |
if not service_types.has_key(prefix): |
|
313 |
get_logger().warn('Unknown prefix: %r' % prefix) |
|
314 |
continue |
|
315 |
if not prefixes.has_key(prefix): |
|
316 |
prefixes[prefix] = [] |
|
317 |
prefixes[prefix].append(f) |
|
318 | ||
319 |
has_prefilled = False |
|
320 |
if idwsf == 1: |
|
321 |
for prefix, fields in prefixes.items(): |
|
322 |
if service_types[prefix] not in ('pp', 'ep'): |
|
323 |
# needs lasso registration |
|
324 |
lasso.registerDstService(prefix, service_types[prefix]) |
|
325 |
disco = lasso.Discovery(misc.get_lasso_server()) |
|
326 |
disco.setSessionFromDump(get_session().lasso_session_dump) |
|
327 |
disco.initQuery() |
|
328 |
disco.addRequestedServiceType(service_types[prefix]) |
|
329 |
disco.buildRequestMsg() |
|
330 |
try: |
|
331 |
soap_answer = liberty.soap_call(disco.msgUrl, disco.msgBody) |
|
332 |
except liberty.SOAPException: |
|
333 |
continue |
|
334 |
disco.processQueryResponseMsg(soap_answer) |
|
335 |
service = disco.getService() |
|
336 |
if not service: |
|
337 |
continue |
|
338 |
service.initQuery() |
|
339 |
for f in fields: |
|
340 |
service.addQueryItem(f.prefill.get('value'), f.id) |
|
341 |
service.buildRequestMsg() |
|
342 |
try: |
|
343 |
soap_answer = liberty.soap_call(service.msgUrl, service.msgBody) |
|
344 |
except liberty.SOAPException: |
|
345 |
continue |
|
346 |
service.processQueryResponseMsg(soap_answer) |
|
347 |
for f in fields: |
|
348 |
answer = service.getAnswerForItemId(f.id) |
|
349 |
if not answer: |
|
350 |
continue |
|
351 |
answer = re.sub('<.*?>', '', answer) |
|
352 |
form._names['f%s' % f.id].set_value(get_publisher().utf82sitecharset(answer)) |
|
353 |
has_prefilled = True |
|
354 |
if idwsf == 2: |
|
355 |
for prefix, fields in prefixes.items(): |
|
356 |
try: |
|
357 |
lasso.registerIdwsf2DstService(prefix, service_types[prefix]) |
|
358 |
eprs = self.get_eprs(service_types[prefix]) |
|
359 |
queries = self.get_queries(fields) |
|
360 |
if eprs: |
|
361 |
# FIXME: if more than one epr |
|
362 |
results = self.do_queries(eprs[0], queries, service_types) |
|
363 |
self.prefill_form(form, results) |
|
364 |
has_prefilled = True |
|
365 |
except Exception, exception: |
|
366 |
raise |
|
367 |
get_logger().error("Got an exception when trying to prefill %s: %s " % (str(form), str(exception))) |
|
368 |
return has_prefilled |
|
369 | ||
370 | 219 |
def page [html] (self, page_no, page_change = True, log_detail = None, editing = None): |
371 | 220 |
if self.formdef.signing == "compulsory": |
372 | 221 |
'<noscript>' |
... | ... | |
383 | 232 | |
384 | 233 |
form = self.formdef.create_form(page_no, displayed_fields) |
385 | 234 | |
386 |
if True or [x for x in displayed_fields if x.prefill and |
|
387 |
x.prefill.get('type') == 'wsf'] and ( |
|
388 |
session.lasso_session_dump and |
|
389 |
( str('DiscoveryResourceOffering') in session.lasso_session_dump or |
|
390 |
str('urn:liberty:disco:2006-08:DiscoveryEPR') in session.lasso_session_dump)): |
|
391 |
form.add_submit('prefill', _('Prefill')) |
|
392 |
if form.get_submit() == 'prefill': |
|
393 |
form.clear_errors() |
|
394 |
if not self.wsf_prefill(form): |
|
395 |
form.info = N_('No data found for prefilling') |
|
396 |
request = get_request() |
|
397 |
if request.form.has_key('prefill') and not type(request.form['prefill']) is list: |
|
398 |
form.submit_widgets.remove(form._names['prefill']) |
|
399 |
del form._names['prefill'] |
|
400 |
if form._names.has_key('prefill') and not [x for x in displayed_fields if \ |
|
401 |
x.prefill and x.prefill.get('type') == 'wsf']: |
|
402 |
form.submit_widgets.remove(form._names['prefill']) |
|
403 |
del form._names['prefill'] |
|
404 | ||
405 | 235 |
if page_no == 0 and not get_request().form.has_key('magictoken'): |
406 | 236 |
magictoken = randbytes(8) |
407 | 237 |
else: |
wcs/qommon/form.py | ||
---|---|---|
594 | 594 |
if self.field and self.field.validation and not 'pattern' in self.attrs: |
595 | 595 |
self.attrs['pattern'] = self.field.validation |
596 | 596 |
s = StringWidget.render_content(self) |
597 |
if not self.value and self.field and self.field.wsf_prefill_explicit and \ |
|
598 |
get_session().lasso_session_dump: |
|
599 |
s += htmltext( |
|
600 |
'<input class="prefill-button" type="submit" name="f%s-prefill" value="%s">') % ( |
|
601 |
self.field.id, _('Prefill')) |
|
602 | 597 |
return s |
603 | 598 | |
604 | 599 |
def _parse(self, request): |
605 | 600 |
StringWidget._parse(self, request) |
606 |
if self.field and hasattr(self.field, 'prefill') and \ |
|
607 |
self.field.prefill and self.field.prefill.get('type') == 'wsf': |
|
608 |
self.prefill = (request.get_field('f%s-prefill' % self.field.id) is not None) |
|
609 |
if self.prefill: |
|
610 |
if not request.form.has_key('prefill'): |
|
611 |
request.form['prefill'] = [] |
|
612 |
request.form['prefill'].append(self.field.id) |
|
613 |
self.error = 'MUST PREFILL...' # won't be displayed |
|
614 |
elif self.field and self.field.validation and self.value is not None: |
|
601 |
if self.field and self.field.validation and self.value is not None: |
|
615 | 602 |
if not re.match(self.field.validation, self.value): |
616 | 603 |
self.error = _('wrong format') |
617 | 604 |
wcs/wf/form.py | ||
---|---|---|
37 | 37 | |
38 | 38 |
class WorkflowFormFieldDefPage(FieldDefPage): |
39 | 39 |
section = 'workflows' |
40 |
wsf_support = False |
|
41 | 40 | |
42 | 41 | |
43 | 42 |
class WorkflowFormFieldsDirectory(FieldsDirectory): |
44 |
- |