Switch to unified view

a/Allura/allura/model/project.py b/Allura/allura/model/project.py
...
...
15
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
15
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
16
16
17
from allura.lib import helpers as h
17
from allura.lib import helpers as h
18
from allura.lib import plugin
18
from allura.lib import plugin
19
from allura.lib import exceptions
19
from allura.lib import exceptions
20
from allura.lib import security
20
21
21
from .session import main_orm_session
22
from .session import main_orm_session
22
from .session import project_doc_session, project_orm_session
23
from .session import project_doc_session, project_orm_session
23
from .neighborhood import Neighborhood
24
from .neighborhood import Neighborhood
24
from .auth import ProjectRole
25
from .auth import ProjectRole
...
...
303
    @property
304
    @property
304
    def direct_subprojects(self):
305
    def direct_subprojects(self):
305
        return self.query.find(dict(parent_id=self._id))
306
        return self.query.find(dict(parent_id=self._id))
306
307
307
    @property
308
    @property
308
    def roles(self):
309
        from . import auth
310
        with h.push_config(c, project=self):
311
            root_roles = [
312
                role for role in auth.ProjectRole.query.find(dict(
313
                        project_id=self.root_project._id))
314
                if role.name ]
315
            roles = list(auth.ProjectRole.roles_that_reach(*root_roles))
316
            return sorted(roles, key=lambda r:r.display())
317
318
    @property
319
    def accolades(self):
309
    def accolades(self):
320
        from .artifact import AwardGrant
310
        from .artifact import AwardGrant
321
        return AwardGrant.query.find(dict(granted_to_project_id=self._id)).all()
311
        return AwardGrant.query.find(dict(granted_to_project_id=self._id)).all()
322
312
313
    @property
314
    def named_roles(self):
315
        roles = sorted(
316
            g.credentials.project_roles(self.root_project._id).named,
317
            key=lambda r:r.name.lower())
318
        return roles
319
323
    def install_app(self, ep_name, mount_point=None, mount_label=None, ordinal=0, **override_options):
320
    def install_app(self, ep_name, mount_point=None, mount_label=None, ordinal=0, **override_options):
324
        from allura import model as M
325
        for ep in pkg_resources.iter_entry_points('allura', ep_name):
321
        for ep in pkg_resources.iter_entry_points('allura', ep_name):
326
            App = ep.load()
322
            App = ep.load()
327
            break
323
            break
328
        else: 
324
        else: 
329
            # Try case-insensitive install
325
            # Try case-insensitive install
...
...
356
            acl=dict((p,[]) for p in App.permissions))
352
            acl=dict((p,[]) for p in App.permissions))
357
        app = App(self, cfg)
353
        app = App(self, cfg)
358
        with h.push_config(c, project=self, app=app):
354
        with h.push_config(c, project=self, app=app):
359
            session(cfg).flush()
355
            session(cfg).flush()
360
            app.install(self)
356
            app.install(self)
361
            admin_role = M.ProjectRole.by_name('Admin', project=self.root_project)
362
            if admin_role:
363
                for u in admin_role.users_with_role():
364
                    M.Mailbox.subscribe(
365
                        user_id=u._id,
366
                        project_id=self._id,
367
                        app_config_id=cfg._id,
368
                        artifact=None, topic=None,
369
                        type='direct', n=1, unit='day')
370
        return app
357
        return app
371
358
372
    def uninstall_app(self, mount_point):
359
    def uninstall_app(self, mount_point):
373
        app = self.app_instance(mount_point)
360
        app = self.app_instance(mount_point)
374
        if app is None: return
361
        if app is None: return
...
...
419
            return self.parent_project.breadcrumbs() + [ entry ]
406
            return self.parent_project.breadcrumbs() + [ entry ]
420
        else:
407
        else:
421
            return [ (self.neighborhood.name, self.neighborhood.url())] + [ entry ]
408
            return [ (self.neighborhood.name, self.neighborhood.url())] + [ entry ]
422
409
423
    def users(self):
410
    def users(self):
411
        '''Find all the users who have named roles for this project'''
412
        named_roles = security.RoleCache(
413
            g.credentials,
414
            g.credentials.project_roles(project_id=self.root_project._id).named)
424
        return [ r.user for r in self.roles if r.user_id is not None ]
415
        return [ r.user for r in named_roles.roles_that_reach if r.user_id is not None ]
425
416
426
    def user_in_project(self, username=None):
417
    def user_in_project(self, username):
427
        from .auth import User
418
        from .auth import User
428
        return User.query.find({'_id':{'$in':[role.user_id for role in c.project.roles]},'username':username}).first()
419
        u = User.by_username(username)
420
        named_roles = g.credentials.project_roles(project_id=self.root_project._id).named
421
        for r in named_roles.roles_that_reach:
422
            if r.user_id == u._id: return u
423
        return None
429
424
430
    def configure_project(
425
    def configure_project(
431
        self,
426
        self,
432
        users=None, apps=None, is_user_project=False):
427
        users=None, apps=None, is_user_project=False):
433
        from allura import model as M
428
        from allura import model as M