File: kopano-search-upgrade-findroots.py

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (46 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-or-later

from MAPI.Util import *

import kopano

"""

as of Kopano-Core 8.2, PR_STORE_SUPPORT_MASK has STORE_SEARCH_OK enabled
for every store. this means that this script needs to run at upgrade time,
to create the findroots and ACLS so that cross-store searches will actually
work.

"""

FINDROOT_RIGHTS = ['folder_visible', 'read_items', 'create_subfolders', 'edit_own', 'delete_own']

def upgrade_findroot(store):
    findroot = store.root.get_folder('FINDER_ROOT')
    if not findroot:
        print('creating FINDER_ROOT for store %s' % store.guid)

        # create findroot
        findroot = store.root.folder('FINDER_ROOT', create=True)

        # set PR_FINDER_ENTRYID # XXX pyko: store.findroot = ..
        entryid = HrGetOneProp(findroot.mapiobj, PR_ENTRYID)
        store.mapiobj.SetProps([SPropValue(PR_FINDER_ENTRYID, entryid.Value)])
        store.mapiobj.SaveChanges(0)

    # add findroot ACL
    findroot.permission(kopano.Group('Everyone'), create=True).rights = FINDROOT_RIGHTS

    # we don't need to update PR_STORE_SUPPORT_MASK as it is hardcoded
    # whether it includes STORE_SEARCH_OK..


def main():
    for store in kopano.stores():
        upgrade_findroot(store)
        if store.archive_store:
            upgrade_findroot(store.archive_store)

if __name__ == '__main__':
    main()