Project

General

Profile

0001-sql-add-evo.who-on-evolution-update-31472.patch

Thomas Noël, 19 Apr 2019 02:56 PM

Download (2.74 KB)

View differences:

Subject: [PATCH] sql: add evo.who on evolution update (#31472)

 tests/test_workflows.py |  3 ++-
 wcs/sql.py              | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/test_workflows.py
675 675
        item2.perform(formdata)
676 676
        assert pub.user_class.get(user.id).roles == []
677 677

  
678
def test_anonymise(pub):
678
def test_anonymise(two_pubs):
679 679
    # build a backoffice field
680 680
    Workflow.wipe()
681 681
    wf = Workflow(name='wf with backoffice field')
......
718 718
                                                          'bo1': None,
719 719
                                                          'bo2': 'foo', 'bo2_display': 'foo'}
720 720
    assert formdef.data_class().get(formdata.id).workflow_data is None
721
    assert formdef.data_class().get(formdata.id).evolution[0].who is None
721 722

  
722 723
def test_remove(pub):
723 724
    formdef = FormDef()
wcs/sql.py
1377 1377
                if hasattr(evo, '_sql_id'):
1378 1378
                    sql_dict.update({'id': evo._sql_id})
1379 1379
                    sql_statement = '''UPDATE %s_evolutions SET
1380
                                        who = %%(who)s,
1380 1381
                                        time = %%(time)s,
1381 1382
                                        last_jump_datetime = %%(last_jump_datetime)s,
1382 1383
                                        status = %%(status)s,
......
2167 2168
    return result
2168 2169

  
2169 2170

  
2170
SQL_LEVEL = 29
2171
SQL_LEVEL = 30
2171 2172

  
2172 2173
def migrate_global_views(conn, cur):
2173 2174
    cur.execute('''SELECT COUNT(*) FROM information_schema.tables
......
2284 2285
            do_formdef_indexes(formdef, created=False, conn=conn, cur=cur)
2285 2286
    if sql_level < 25:
2286 2287
        do_session_table()
2288
    if sql_level < 30:
2289
        # 30: actually remove evo.who on anonymised formdatas
2290
        from wcs.formdef import FormDef
2291
        for formdef in FormDef.select():
2292
            for formdata in formdef.data_class().select_iterator(clause=[NotNull('anonymised')]):
2293
                if formdata.evolution:
2294
                    for evo in formdata.evolution:
2295
                        evo.who = None
2296
                    formdata.store()
2287 2297

  
2288 2298
    cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', (
2289 2299
        str(SQL_LEVEL), 'sql_level'))
2290
-