Parent: [96b8e4] (diff)

Child: [e920bc] (diff)

Download this file

027-change-ticket-write-permissions.py    36 lines (26 with data), 1.1 kB

 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
import logging
import re
from pylons import c
from ming.orm import ThreadLocalORMSession
from allura import model as M
from allura.lib import utils
from forgetracker import model as TM
from forgewiki.wiki_main import ForgeWikiApp
log = logging.getLogger(__name__)
# migration script for change write permission to create + update
def main():
query = {'tool_name': {'$regex': '^tickets$', '$options': 'i'}}
for chunk in utils.chunked_find(M.AppConfig, query):
for a in chunk:
# change 'deny write' and 'write' permission
role_ids = [(p.role_id, p.access) for p in a.acl if p.permission == 'write']
for role_id, access in role_ids:
if access == M.ACE.DENY:
a.acl.add(M.ACE.deny(role_id, 'create'))
a.acl.add(M.ACE.deny(role_id, 'update'))
else:
a.acl.add(M.ACE.allow(role_id, 'create'))
a.acl.add(M.ACE.allow(role_id, 'update'))
ThreadLocalORMSession.flush_all()
if __name__ == '__main__':
main()