sql: add evo.who on evolution update (#31472)
This commit is contained in:
parent
4d72f6ca62
commit
447368ea95
|
@ -1786,3 +1786,48 @@ def test_view_performances():
|
|||
formdatas = sql.AnyFormData.select(criterias, order_by='receipt_time', limit=20, offset=0)
|
||||
print time.time() - t0
|
||||
assert (time.time() - t0) < 0.5
|
||||
|
||||
|
||||
@postgresql
|
||||
def test_migration_30_anonymize_evo_who():
|
||||
formdef = FormDef()
|
||||
formdef.name = 'tests migration 24'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
user = sql.SqlUser()
|
||||
user.name = 'JohnDoe'
|
||||
user.store()
|
||||
|
||||
klass = formdef.data_class()
|
||||
formdata = klass()
|
||||
formdata.evolution = []
|
||||
formdata.anonymised = datetime.datetime.now()
|
||||
evo = Evolution(formdata)
|
||||
evo.who = user.id
|
||||
evo.time = time.localtime()
|
||||
formdata.evolution.append(evo)
|
||||
formdata.store()
|
||||
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
cur.execute('UPDATE wcs_meta SET value = 29 WHERE key = %s', ('sql_level',))
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
cur.execute('SELECT COUNT(*) FROM %s_evolutions WHERE who IS NULL' % formdef.table_name)
|
||||
assert cur.fetchone() == (0,)
|
||||
cur.execute('SELECT COUNT(*) FROM wcs_meta WHERE key = %s AND value::integer > 29', ('sql_level',))
|
||||
assert cur.fetchone() == (0,)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
sql.migrate()
|
||||
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
cur.execute('SELECT COUNT(*) FROM %s_evolutions WHERE who IS NULL' % formdef.table_name)
|
||||
assert cur.fetchone() == (1,)
|
||||
cur.execute('SELECT COUNT(*) FROM wcs_meta WHERE key = %s AND value::integer > 29', ('sql_level',))
|
||||
assert cur.fetchone() == (1,)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
|
|
@ -675,7 +675,7 @@ def test_roles_idp(pub):
|
|||
item2.perform(formdata)
|
||||
assert pub.user_class.get(user.id).roles == []
|
||||
|
||||
def test_anonymise(pub):
|
||||
def test_anonymise(two_pubs):
|
||||
# build a backoffice field
|
||||
Workflow.wipe()
|
||||
wf = Workflow(name='wf with backoffice field')
|
||||
|
@ -718,6 +718,7 @@ def test_anonymise(pub):
|
|||
'bo1': None,
|
||||
'bo2': 'foo', 'bo2_display': 'foo'}
|
||||
assert formdef.data_class().get(formdata.id).workflow_data is None
|
||||
assert formdef.data_class().get(formdata.id).evolution[0].who is None
|
||||
|
||||
def test_remove(pub):
|
||||
formdef = FormDef()
|
||||
|
|
12
wcs/sql.py
12
wcs/sql.py
|
@ -1377,6 +1377,7 @@ class SqlFormData(SqlMixin, wcs.formdata.FormData):
|
|||
if hasattr(evo, '_sql_id'):
|
||||
sql_dict.update({'id': evo._sql_id})
|
||||
sql_statement = '''UPDATE %s_evolutions SET
|
||||
who = %%(who)s,
|
||||
time = %%(time)s,
|
||||
last_jump_datetime = %%(last_jump_datetime)s,
|
||||
status = %%(status)s,
|
||||
|
@ -2167,7 +2168,7 @@ def get_yearly_totals(period_start=None, period_end=None, criterias=None):
|
|||
return result
|
||||
|
||||
|
||||
SQL_LEVEL = 29
|
||||
SQL_LEVEL = 30
|
||||
|
||||
def migrate_global_views(conn, cur):
|
||||
cur.execute('''SELECT COUNT(*) FROM information_schema.tables
|
||||
|
@ -2284,6 +2285,15 @@ def migrate():
|
|||
do_formdef_indexes(formdef, created=False, conn=conn, cur=cur)
|
||||
if sql_level < 25:
|
||||
do_session_table()
|
||||
if sql_level < 30:
|
||||
# 30: actually remove evo.who on anonymised formdatas
|
||||
from wcs.formdef import FormDef
|
||||
for formdef in FormDef.select():
|
||||
for formdata in formdef.data_class().select_iterator(clause=[NotNull('anonymised')]):
|
||||
if formdata.evolution:
|
||||
for evo in formdata.evolution:
|
||||
evo.who = None
|
||||
formdata.store()
|
||||
|
||||
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', (
|
||||
str(SQL_LEVEL), 'sql_level'))
|
||||
|
|
Loading…
Reference in New Issue