server/sources/native.py
changeset 9098 5467fb901931
parent 8947 3bbd416b09ec
child 9402 2c48c091b6a2
equal deleted inserted replaced
9097:39be1e548270 9098:5467fb901931
   975     _handle_insert_entity_sql = doexec
   975     _handle_insert_entity_sql = doexec
   976     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   976     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   977 
   977 
   978     def add_info(self, session, entity, source, extid, complete):
   978     def add_info(self, session, entity, source, extid, complete):
   979         """add type and source info for an eid into the system table"""
   979         """add type and source info for an eid into the system table"""
   980         # begin by inserting eid/type/source/extid into the entities table
   980         with session.ensure_cnx_set:
   981         if extid is not None:
   981             # begin by inserting eid/type/source/extid into the entities table
   982             assert isinstance(extid, str)
   982             if extid is not None:
   983             extid = b64encode(extid)
   983                 assert isinstance(extid, str)
   984         uri = 'system' if source.copy_based_source else source.uri
   984                 extid = b64encode(extid)
   985         attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   985             uri = 'system' if source.copy_based_source else source.uri
   986                  'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
   986             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   987         self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs)
   987                      'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
   988         # insert core relations: is, is_instance_of and cw_source
   988             self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs)
   989         try:
   989             # insert core relations: is, is_instance_of and cw_source
   990             self._handle_is_relation_sql(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   990             try:
   991                                          (entity.eid, eschema_eid(session, entity.e_schema)))
   991                 self._handle_is_relation_sql(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   992         except IndexError:
   992                                              (entity.eid, eschema_eid(session, entity.e_schema)))
   993             # during schema serialization, skip
   993             except IndexError:
   994             pass
   994                 # during schema serialization, skip
   995         else:
   995                 pass
   996             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   996             else:
   997                 self._handle_is_relation_sql(session,
   997                 for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   998                                              'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
   998                     self._handle_is_relation_sql(session,
   999                                              (entity.eid, eschema_eid(session, eschema)))
   999                                                  'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
  1000         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
  1000                                                  (entity.eid, eschema_eid(session, eschema)))
  1001             self._handle_is_relation_sql(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
  1001             if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
  1002                                          (entity.eid, source.eid))
  1002                 self._handle_is_relation_sql(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
  1003         # now we can update the full text index
  1003                                              (entity.eid, source.eid))
  1004         if self.do_fti and self.need_fti_indexation(entity.cw_etype):
  1004             # now we can update the full text index
  1005             if complete:
  1005             if self.do_fti and self.need_fti_indexation(entity.cw_etype):
  1006                 entity.complete(entity.e_schema.indexable_attributes())
  1006                 if complete:
  1007             self.index_entity(session, entity=entity)
  1007                     entity.complete(entity.e_schema.indexable_attributes())
       
  1008                 self.index_entity(session, entity=entity)
  1008 
  1009 
  1009     def update_info(self, session, entity, need_fti_update):
  1010     def update_info(self, session, entity, need_fti_update):
  1010         """mark entity as being modified, fulltext reindex if needed"""
  1011         """mark entity as being modified, fulltext reindex if needed"""
  1011         if self.do_fti and need_fti_update:
  1012         if self.do_fti and need_fti_update:
  1012             # reindex the entity only if this query is updating at least
  1013             # reindex the entity only if this query is updating at least
  1225         """return transaction's time and user of the transaction with the given uuid.
  1226         """return transaction's time and user of the transaction with the given uuid.
  1226 
  1227 
  1227         raise `NoSuchTransaction` if there is no such transaction of if the
  1228         raise `NoSuchTransaction` if there is no such transaction of if the
  1228         session's user isn't allowed to see it.
  1229         session's user isn't allowed to see it.
  1229         """
  1230         """
  1230         restr = {'tx_uuid': txuuid}
  1231         with session.ensure_cnx_set:
  1231         sql = self.sqlgen.select('transactions', restr, ('tx_time', 'tx_user'))
  1232             restr = {'tx_uuid': txuuid}
  1232         cu = self.doexec(session, sql, restr)
  1233             sql = self.sqlgen.select('transactions', restr,
  1233         try:
  1234                                      ('tx_time', 'tx_user'))
  1234             time, ueid = cu.fetchone()
  1235             cu = self.doexec(session, sql, restr)
  1235         except TypeError:
  1236             try:
  1236             raise tx.NoSuchTransaction(txuuid)
  1237                 time, ueid = cu.fetchone()
  1237         if not (session.user.is_in_group('managers')
  1238             except TypeError:
  1238                 or session.user.eid == ueid):
  1239                 raise tx.NoSuchTransaction(txuuid)
  1239             raise tx.NoSuchTransaction(txuuid)
  1240             if not (session.user.is_in_group('managers')
  1240         return time, ueid
  1241                     or session.user.eid == ueid):
       
  1242                 raise tx.NoSuchTransaction(txuuid)
       
  1243             return time, ueid
  1241 
  1244 
  1242     def _reedit_entity(self, entity, changes, err):
  1245     def _reedit_entity(self, entity, changes, err):
  1243         session = entity._cw
  1246         session = entity._cw
  1244         eid = entity.eid
  1247         eid = entity.eid
  1245         entity.cw_edited = edited = EditedEntity(entity)
  1248         entity.cw_edited = edited = EditedEntity(entity)