Project

General

Profile

0001-user-add-a-deleted-flag-24430.patch

Benjamin Dauvergne, 14 Oct 2018 07:15 PM

Download (4.05 KB)

View differences:

Subject: [PATCH 1/4] user: add a deleted flag (#24430)

 wcs/sql.py   | 17 ++++++++++++-----
 wcs/users.py |  1 +
 2 files changed, 13 insertions(+), 5 deletions(-)
wcs/sql.py
540 540
                                    verified_fields text[],
541 541
                                    name_identifiers text[],
542 542
                                    lasso_dump text,
543
                                    last_seen timestamp)''' % table_name)
543
                                    last_seen timestamp,
544
                                    deleted boolean DEFAULT(FALSE))''' % table_name)
544 545
    cur.execute('''SELECT column_name FROM information_schema.columns
545 546
                    WHERE table_schema = 'public'
546 547
                      AND table_name = %s''', (table_name,))
......
548 549

  
549 550
    needed_fields = set(['id', 'name', 'email', 'roles', 'is_admin',
550 551
        'anonymous', 'name_identifiers', 'verified_fields',
551
        'lasso_dump', 'last_seen', 'fts', 'ascii_name'])
552
        'lasso_dump', 'last_seen', 'fts', 'ascii_name', 'deleted'])
552 553

  
553 554
    from admin.settings import UserFieldsFormDef
554 555
    formdef = UserFieldsFormDef()
......
587 588
    if not 'ascii_name' in existing_fields:
588 589
        cur.execute('ALTER TABLE %s ADD COLUMN ascii_name varchar' % table_name)
589 590

  
591
    if not 'deleted' in existing_fields:
592
        cur.execute('ALTER TABLE %s ADD COLUMN deleted DEFAULT(FALSE)' % table_name)
593

  
590 594
    # delete obsolete fields
591 595
    for field in (existing_fields - needed_fields):
592 596
        cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field))
......
1605 1609
        ('lasso_dump', 'text'),
1606 1610
        ('last_seen', 'timestamp'),
1607 1611
        ('ascii_name', 'varchar'),
1612
        ('deleted', 'boolean'),
1608 1613
    ]
1609 1614

  
1610 1615
    id = None
......
1629 1634
                'verified_fields': self.verified_fields,
1630 1635
                'lasso_dump': self.lasso_dump,
1631 1636
                'last_seen': None,
1637
                'deleted': self.deleted,
1632 1638
        }
1633 1639
        if self.last_seen:
1634 1640
            sql_dict['last_seen'] = datetime.datetime.fromtimestamp(self.last_seen),
......
1696 1702
        o = cls()
1697 1703
        (o.id, o.name, o.email, o.roles, o.is_admin, o.anonymous,
1698 1704
         o.name_identifiers, o.verified_fields, o.lasso_dump,
1699
         o.last_seen, ascii_name) = [str_encode(x) for x in tuple(row[:11])]
1705
         o.last_seen, ascii_name, o.deleted) = [str_encode(x) for x in tuple(row[:12])]
1700 1706
        if o.last_seen:
1701 1707
            o.last_seen = time.mktime(o.last_seen.timetuple())
1702 1708
        if o.roles:
......
2146 2152
    return result
2147 2153

  
2148 2154

  
2149
SQL_LEVEL = 28
2155
SQL_LEVEL = 29
2150 2156

  
2151 2157
def migrate_global_views(conn, cur):
2152 2158
    cur.execute('''SELECT COUNT(*) FROM information_schema.tables
......
2230 2236
        # 26: add digest to formdata
2231 2237
        # 27: add last_jump_datetime in evolutions tables
2232 2238
        migrate_views(conn, cur)
2233
    if sql_level < 21:
2239
    if sql_level < 29:
2234 2240
        # 3: introduction of _structured for user fields
2235 2241
        # 4: removal of identification_token
2236 2242
        # 12: (first part) add fts to users
2237 2243
        # 16: add verified_fields to users
2238 2244
        # 21: (first part) add ascii_name to users
2245
        # 29: add deleted
2239 2246
        do_user_table()
2240 2247
    if sql_level < 6:
2241 2248
        # 6: add actions_roles_array to tables and views
wcs/users.py
35 35
    verified_fields = None
36 36
    name_identifiers = None
37 37
    lasso_dump = None
38
    deleted = False
38 39

  
39 40
    last_seen = None
40 41

  
41
-