Switch to unified view

a/Allura/allura/model/project.py b/Allura/allura/model/project.py
...
...
117
    name=FieldProperty(str)
117
    name=FieldProperty(str)
118
    show_download_button=FieldProperty(bool, if_missing=True)
118
    show_download_button=FieldProperty(bool, if_missing=True)
119
    short_description=FieldProperty(str, if_missing='')
119
    short_description=FieldProperty(str, if_missing='')
120
    description=FieldProperty(str, if_missing='')
120
    description=FieldProperty(str, if_missing='')
121
    database=FieldProperty(str)
121
    database=FieldProperty(str)
122
    database_uri=FieldProperty(str)
122
    is_root=FieldProperty(bool)
123
    is_root=FieldProperty(bool)
123
    acl = FieldProperty({
124
    acl = FieldProperty({
124
            'create':[S.ObjectId],    # create subproject
125
            'create':[S.ObjectId],    # create subproject
125
            'read':[S.ObjectId],      # read project
126
            'read':[S.ObjectId],      # read project
126
            'update':[S.ObjectId],    # update project metadata
127
            'update':[S.ObjectId],    # update project metadata
...
...
287
288
288
    @property
289
    @property
289
    def roles(self):
290
    def roles(self):
290
        from . import auth
291
        from . import auth
291
        with h.push_config(c, project=self):
292
        with h.push_config(c, project=self):
292
            roles = auth.ProjectRole.query.find({'name':{'$in':['Admin','Developer','*anonymous','*authenticated']}}).all()
293
            root_roles = auth.ProjectRole.query.find(dict(
293
            roles = roles + auth.ProjectRole.query.find({'name':None,'roles':{'$in':[r._id for r in roles]}}).all()
294
                    project_id=self.root_project._id,
295
                    name={'$in':['Admin','Developer']})).all()
296
            roles = list(auth.ProjectRole.roles_that_reach(*root_roles))
294
            return sorted(roles, key=lambda r:r.display())
297
            return sorted(roles, key=lambda r:r.display())
295
298
296
    @property
299
    @property
297
    def accolades(self):
300
    def accolades(self):
298
        from .artifact import AwardGrant
301
        from .artifact import AwardGrant
...
...
329
            acl=dict((p,[]) for p in App.permissions))
332
            acl=dict((p,[]) for p in App.permissions))
330
        app = App(self, cfg)
333
        app = App(self, cfg)
331
        with h.push_config(c, project=self, app=app):
334
        with h.push_config(c, project=self, app=app):
332
            session(cfg).flush()
335
            session(cfg).flush()
333
            app.install(self)
336
            app.install(self)
334
            admin_role = M.ProjectRole.query.find({'name':'Admin'}).first()
337
            admin_role = M.ProjectRole.query.get(
338
                name='Admin', project_id=self._id)
335
            if admin_role:
339
            if admin_role:
336
                for u in admin_role.users_with_role():
340
                for u in admin_role.users_with_role():
337
                    M.Mailbox.subscribe(
341
                    M.Mailbox.subscribe(
338
                        user_id=c.user._id,
342
                        user_id=c.user._id,
339
                        project_id=self._id,
343
                        project_id=self._id,
...
...
392
            return self.parent_project.breadcrumbs() + [ entry ]
396
            return self.parent_project.breadcrumbs() + [ entry ]
393
        else:
397
        else:
394
            return [ (self.neighborhood.name, self.neighborhood.url())] + [ entry ]
398
            return [ (self.neighborhood.name, self.neighborhood.url())] + [ entry ]
395
399
396
    def users(self):
400
    def users(self):
397
        def uniq(users):
401
        return [ r.user for r in self.roles if r.user_id is not None ]
398
            t = {}
399
            for user in users:
400
                t[user.username] = user
401
            return t.values()
402
        project_users = uniq([r.user for r in self.roles if not r.user.username.startswith('*')])
403
        return project_users
404
402
405
    def user_in_project(self, username=None):
403
    def user_in_project(self, username=None):
406
        from .auth import User
404
        from .auth import User
407
        return User.query.find({'_id':{'$in':[role.user_id for role in c.project.roles]},'username':username}).first()
405
        return User.query.find({'_id':{'$in':[role.user_id for role in c.project.roles]},'username':username}).first()
408
406
409
    def configure_project_database(self,
407
    def configure_project(
408
        self,
410
                                   users=None, apps=None, is_user_project=False):
409
        users=None, apps=None, is_user_project=False):
411
        from allura import model as M
410
        from allura import model as M
412
        from flyway.model import MigrationInfo
413
        from flyway.migrate import Migration
414
        if users is None: users = [ c.user ]
411
        if users is None: users = [ c.user ]
415
        if apps is None:
412
        if apps is None:
416
            if is_user_project:
413
            if is_user_project:
417
                apps = [('profile', 'profile'),
414
                apps = [('profile', 'profile'),
418
                        ('admin', 'admin'),
415
                        ('admin', 'admin'),
...
...
420
            else:
417
            else:
421
                apps = [('home', 'home'),
418
                apps = [('home', 'home'),
422
                        ('admin', 'admin'),
419
                        ('admin', 'admin'),
423
                        ('search', 'search')]
420
                        ('search', 'search')]
424
        with h.push_config(c, project=self, user=users[0]):
421
        with h.push_config(c, project=self, user=users[0]):
425
            # Configure flyway migration info
426
            mi = project_doc_session.get(MigrationInfo)
427
            if mi is None:
428
                mi = MigrationInfo.make({})
429
            mi.versions.update(Migration.latest_versions())
430
            project_doc_session.save(mi)
431
            # Configure indexes
432
            for mc in MappedClass._registry.itervalues():
433
                if mc.__mongometa__.session == project_orm_session:
434
                    project_orm_session.ensure_indexes(mc)
435
            # Install default named roles (#78)
422
            # Install default named roles (#78)
436
            role_owner = M.ProjectRole.upsert(name='Admin')
423
            role_admin = M.ProjectRole.upsert(name='Admin', project_id=self._id)
437
            role_developer = M.ProjectRole.upsert(name='Developer')
424
            role_developer = M.ProjectRole.upsert(name='Developer', project_id=self._id)
438
            role_member = M.ProjectRole.upsert(name='Member')
425
            role_member = M.ProjectRole.upsert(name='Member', project_id=self._id)
439
            role_auth = M.ProjectRole.upsert(name='*authenticated')
426
            role_auth = M.ProjectRole.upsert(name='*authenticated', project_id=self._id)
440
            role_anon = M.ProjectRole.upsert(name='*anonymous')
427
            role_anon = M.ProjectRole.upsert(name='*anonymous', project_id=self._id)
441
            # Setup subroles
428
            # Setup subroles
442
            role_owner.roles = [ role_developer._id ]
429
            role_admin.roles = [ role_developer._id ]
443
            role_developer.roles = [ role_member._id ]
430
            role_developer.roles = [ role_member._id ]
444
            self.acl['create'] = [ role_owner._id ]
431
            self.acl['create'] = [ role_admin._id ]
445
            self.acl['read'] = [ role_owner._id, role_developer._id, role_member._id,
432
            self.acl['read'] = [ role_admin._id, role_developer._id, role_member._id,
446
                              role_anon._id ]
433
                              role_anon._id ]
447
            self.acl['update'] = [ role_owner._id ]
434
            self.acl['update'] = [ role_admin._id ]
448
            self.acl['delete'] = [ role_owner._id ]
435
            self.acl['delete'] = [ role_admin._id ]
449
            self.acl['tool'] = [ role_owner._id ]
436
            self.acl['tool'] = [ role_admin._id ]
450
            self.acl['security'] = [ role_owner._id ]
437
            self.acl['security'] = [ role_admin._id ]
451
            for user in users:
438
            for user in users:
452
                pr = user.project_role()
439
                pr = user.project_role()
453
                pr.roles = [ role_owner._id, role_developer._id, role_member._id ]
440
                pr.roles = [ role_admin._id, role_developer._id, role_member._id ]
454
            # Setup apps
441
            # Setup apps
455
            for ep_name, mount_point in apps:
442
            for ep_name, mount_point in apps:
456
                self.install_app(ep_name, mount_point)
443
                self.install_app(ep_name, mount_point)
457
            self.database_configured = True
444
            self.database_configured = True
458
            ThreadLocalORMSession.flush_all()
445
            ThreadLocalORMSession.flush_all()
446
447
    def ensure_project_indexes(self):
448
            for mc in MappedClass._registry.itervalues():
449
                if mc.__mongometa__.session == project_orm_session:
450
                    project_orm_session.ensure_indexes(mc)
459
451
460
class AppConfig(MappedClass):
452
class AppConfig(MappedClass):
461
    class __mongometa__:
453
    class __mongometa__:
462
        session = project_orm_session
454
        session = project_orm_session
463
        name='config'
455
        name='config'