Switch to unified view

a/scripts/migrations/010-fix-home-permissions.py b/scripts/migrations/010-fix-home-permissions.py
...
...
5
from pylons import c
5
from pylons import c
6
from ming.orm import session
6
from ming.orm import session
7
from bson import ObjectId
7
from bson import ObjectId
8
8
9
from allura import model as M
9
from allura import model as M
10
from allura.lib import utils
10
from forgewiki.wiki_main import ForgeWikiApp
11
from forgewiki.wiki_main import ForgeWikiApp
11
12
12
log = logging.getLogger('fix-home-permissions')
13
log = logging.getLogger('fix-home-permissions')
13
handler = logging.StreamHandler(sys.stdout)
14
handler = logging.StreamHandler(sys.stdout)
14
log.addHandler(handler)
15
log.addHandler(handler)
...
...
20
    if TEST:
21
    if TEST:
21
        log.info('Examining permissions for all Home Wikis')
22
        log.info('Examining permissions for all Home Wikis')
22
    else:
23
    else:
23
        log.info('Fixing permissions for all Home Wikis')
24
        log.info('Fixing permissions for all Home Wikis')
24
25
25
    for some_projects in chunked_project_iterator({'neighborhood_id': {'$nin': [ObjectId('4be2faf8898e33156f00003e'),       # /u
26
    for some_projects in utils.chunked_find(M.Project, {'neighborhood_id': {
26
                                                                                ObjectId('4dbf2563bfc09e6362000005')]}}):   # /motorola
27
                '$nin': [ObjectId('4be2faf8898e33156f00003e'),      # /u
28
                         ObjectId('4dbf2563bfc09e6362000005')]}}):  # /motorola
27
        for project in some_projects:
29
        for project in some_projects:
28
            c.project = project
30
            c.project = project
29
            home_app = project.app_instance('home')
31
            home_app = project.app_instance('home')
30
            if isinstance(home_app, ForgeWikiApp):
32
            if isinstance(home_app, ForgeWikiApp):
31
                log.info('Examining permissions in project "%s".' % project.shortname)
33
                log.info('Examining permissions in project "%s".' % project.shortname)
...
...
54
                else:
56
                else:
55
                    log.info('...updating acl for home app in project "%s".' % project.shortname)
57
                    log.info('...updating acl for home app in project "%s".' % project.shortname)
56
                    home_app.config.acl = map(dict, new_acl.values())
58
                    home_app.config.acl = map(dict, new_acl.values())
57
                    session(home_app.config).flush()
59
                    session(home_app.config).flush()
58
60
59
PAGESIZE=1024
60
61
def chunked_project_iterator(q_project):
62
    '''shamelessly copied from refresh-all-repos.py'''
63
    page = 0
64
    while True:
65
        results = (M.Project.query
66
                   .find(q_project)
67
                   .skip(PAGESIZE*page)
68
                   .limit(PAGESIZE)
69
                   .all())
70
        if not results: break
71
        yield results
72
        page += 1
73
74
def project_role(project, name):
61
def project_role(project, name):
75
    role = M.ProjectRole.query.get(project_id=project._id, name=name)
62
    role = M.ProjectRole.query.get(project_id=project._id, name=name)
76
    if role is None:
63
    if role is None:
77
        role = M.ProjectRole(project_id=project._id, name=name)
64
        role = M.ProjectRole(project_id=project._id, name=name)
78
    return role
65
    return role