459 rdef = rschema.rdef(self.e_schema, targets[0]) |
459 rdef = rschema.rdef(self.e_schema, targets[0]) |
460 if matching_groups(rdef.get_groups('read')) and \ |
460 if matching_groups(rdef.get_groups('read')) and \ |
461 all(matching_groups(e.get_groups('read')) for e in targets): |
461 all(matching_groups(e.get_groups('read')) for e in targets): |
462 yield rschema, 'subject' |
462 yield rschema, 'subject' |
463 |
463 |
464 def to_complete_attributes(self, skip_bytes=True): |
464 def to_complete_attributes(self, skip_bytes=True, skip_pwd=True): |
465 for rschema, attrschema in self.e_schema.attribute_definitions(): |
465 for rschema, attrschema in self.e_schema.attribute_definitions(): |
466 # skip binary data by default |
466 # skip binary data by default |
467 if skip_bytes and attrschema.type == 'Bytes': |
467 if skip_bytes and attrschema.type == 'Bytes': |
468 continue |
468 continue |
469 attr = rschema.type |
469 attr = rschema.type |
470 if attr == 'eid': |
470 if attr == 'eid': |
471 continue |
471 continue |
472 # password retreival is blocked at the repository server level |
472 # password retreival is blocked at the repository server level |
473 rdef = rschema.rdef(self.e_schema, attrschema) |
473 rdef = rschema.rdef(self.e_schema, attrschema) |
474 if not self._cw.user.matching_groups(rdef.get_groups('read')) \ |
474 if not self._cw.user.matching_groups(rdef.get_groups('read')) \ |
475 or attrschema.type == 'Password': |
475 or (attrschema.type == 'Password' and skip_pwd): |
476 self[attr] = None |
476 self[attr] = None |
477 continue |
477 continue |
478 yield attr |
478 yield attr |
479 |
479 |
480 _cw_completed = False |
480 _cw_completed = False |
481 def complete(self, attributes=None, skip_bytes=True): |
481 def complete(self, attributes=None, skip_bytes=True, skip_pwd=True): |
482 """complete this entity by adding missing attributes (i.e. query the |
482 """complete this entity by adding missing attributes (i.e. query the |
483 repository to fill the entity) |
483 repository to fill the entity) |
484 |
484 |
485 :type skip_bytes: bool |
485 :type skip_bytes: bool |
486 :param skip_bytes: |
486 :param skip_bytes: |
493 self._cw_completed = True |
493 self._cw_completed = True |
494 varmaker = rqlvar_maker() |
494 varmaker = rqlvar_maker() |
495 V = varmaker.next() |
495 V = varmaker.next() |
496 rql = ['WHERE %s eid %%(x)s' % V] |
496 rql = ['WHERE %s eid %%(x)s' % V] |
497 selected = [] |
497 selected = [] |
498 for attr in (attributes or self.to_complete_attributes(skip_bytes)): |
498 for attr in (attributes or self.to_complete_attributes(skip_bytes, skip_pwd)): |
499 # if attribute already in entity, nothing to do |
499 # if attribute already in entity, nothing to do |
500 if self.has_key(attr): |
500 if self.has_key(attr): |
501 continue |
501 continue |
502 # case where attribute must be completed, but is not yet in entity |
502 # case where attribute must be completed, but is not yet in entity |
503 var = varmaker.next() |
503 var = varmaker.next() |