19 |
19 |
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 |
21 |
22 from datetime import datetime |
22 from datetime import datetime |
23 |
23 |
24 from cubicweb.selectors import is_instance |
24 from cubicweb.predicates import is_instance |
25 from cubicweb.server import hook |
25 from cubicweb.server import hook |
26 from cubicweb.server.edition import EditedEntity |
26 from cubicweb.server.edition import EditedEntity |
27 |
27 |
28 |
28 |
29 class MetaDataHook(hook.Hook): |
29 class MetaDataHook(hook.Hook): |
197 syssource = newsource.repo_source |
197 syssource = newsource.repo_source |
198 oldsource = self._cw.entity_from_eid(schange[self.eidfrom]) |
198 oldsource = self._cw.entity_from_eid(schange[self.eidfrom]) |
199 entity = self._cw.entity_from_eid(self.eidfrom) |
199 entity = self._cw.entity_from_eid(self.eidfrom) |
200 # copy entity if necessary |
200 # copy entity if necessary |
201 if not oldsource.repo_source.copy_based_source: |
201 if not oldsource.repo_source.copy_based_source: |
202 entity.complete(skip_bytes=False) |
202 entity.complete(skip_bytes=False, skip_pwd=False) |
203 if not entity.creation_date: |
203 if not entity.creation_date: |
204 entity.cw_attr_cache['creation_date'] = datetime.now() |
204 entity.cw_attr_cache['creation_date'] = datetime.now() |
205 if not entity.modification_date: |
205 if not entity.modification_date: |
206 entity.cw_attr_cache['modification_date'] = datetime.now() |
206 entity.cw_attr_cache['modification_date'] = datetime.now() |
207 entity.cw_attr_cache['cwuri'] = u'%s%s' % (self._cw.base_url(), entity.eid) |
207 entity.cw_attr_cache['cwuri'] = u'%s%s' % (self._cw.base_url(), entity.eid) |
208 for rschema, attrschema in entity.e_schema.attribute_definitions(): |
|
209 if attrschema == 'Password' and \ |
|
210 rschema.rdef(entity.e_schema, attrschema).cardinality[0] == '1': |
|
211 from logilab.common.shellutils import generate_password |
|
212 entity.cw_attr_cache[rschema.type] = generate_password() |
|
213 entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache) |
208 entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache) |
214 syssource.add_entity(self._cw, entity) |
209 syssource.add_entity(self._cw, entity) |
215 # we don't want the moved entity to be reimported later. To |
210 # we don't want the moved entity to be reimported later. To |
216 # distinguish this state, the trick is to change the associated |
211 # distinguish this state, the trick is to change the associated |
217 # record in the 'entities' system table with eid=-eid while leaving |
212 # record in the 'entities' system table with eid=-eid while leaving |