Allura/allura/controllers/auth.py
def index(self, **kw):
        """ The subscription selection page in user preferences.

        Builds up a list of dictionaries, each containing subscription
        information about a tool.
        """
        c.form = F.subscription_form
        c.revoke_access = F.oauth_revocation_form

        subscriptions = []
        mailboxes = list(M.Mailbox.query.find(
            dict(user_id=c.user._id, is_flash=False)))
        projects = dict(
            (p._id, p) for p in M.Project.query.find(dict(
                _id={'$in': [mb.project_id for mb in mailboxes]})))
        app_index = dict(
            (ac._id, ac) for ac in M.AppConfig.query.find(dict(
                _id={'$in': [mb.app_config_id for mb in mailboxes]})))

        # Add the tools that are already subscribed to by the user.
        for mb in mailboxes:
            project = projects.get(mb.project_id, None)
            app_config = app_index.get(mb.app_config_id, None)
            if project is None:
                mb.query.delete()
                continue
            if app_config is None:
                continue
            app = app_config.load()
            if not app.has_notifications:
                continue

            subscriptions.append(dict(
                subscription_id=mb._id,
                project_id=project._id,
                app_config_id=mb.app_config_id,
                project_name=project.name,
                tool=app_config.options['mount_label'],
                artifact_title=dict(
                    text='Everything' if mb.artifact_title == 'All artifacts' else mb.artifact_title,
                    href=mb.artifact_url),
                topic=mb.topic,
                type=mb.type,
                frequency=mb.frequency.unit,
                artifact=mb.artifact_index_id,
                subscribed=True))

        # Dictionary of all projects projects accessible based on a users credentials (user_roles).
        my_projects = dict((p._id, p) for p in c.user.my_projects())

        # Dictionary containing all tools (subscribed and un-subscribed).
        my_tools = M.AppConfig.query.find(dict(
            project_id={'$in': my_projects.keys()}))

        # Dictionary containing all the currently subscribed tools for a given user.
        my_tools_subscriptions = dict(
            (mb.app_config_id, mb) for mb in M.Mailbox.query.find(dict(
                user_id=c.user._id,
                project_id={'$in': projects.keys()},
                app_config_id={'$in': app_index.keys()},
                artifact_index_id=None)))

        # Add the remaining tools that are eligible for subscription.
        for tool in my_tools:
            if tool['_id'] in my_tools_subscriptions:
                continue  # We have already subscribed to this tool.
            app = tool.load()
            if not app.has_notifications:
                continue

            subscriptions.append(
                dict(tool_id=tool._id,
                     user_id=c.user._id,
                     project_id=tool.project_id,
                     project_name=my_projects[tool.project_id].name,
                     tool=tool.options['mount_label'],
                     artifact_title='Everything',
                     topic=None,
                     type=None,
                     frequency=None,
                     artifact=None))

        subscriptions.sort(key=lambda d: (d['project_name'], d['tool']))
        provider = plugin.AuthenticationProvider.get(request)
        menu = provider.account_navigation()
        return dict(
            subscriptions=subscriptions,
            menu=menu)
 The subscription selection page in user preferences.

        Builds up a list of dictionaries, each containing subscription
        information about a tool.
        
The subscription selection page in user preferences.
Builds up a list of dictionaries, each containing subscription
information about a tool.
The subscription selection page in user preferences . Builds up a list of dictionaries each containing subscription information about a tool .
def index(self, **kw):
        c.form = F.subscription_form
        c.revoke_access = F.oauth_revocation_form
        subscriptions = []
        mailboxes = list(M.Mailbox.query.find(
            dict(user_id=c.user._id, is_flash=False)))
        projects = dict(
            (p._id, p) for p in M.Project.query.find(dict(
                _id={'$in': [mb.project_id for mb in mailboxes]})))
        app_index = dict(
            (ac._id, ac) for ac in M.AppConfig.query.find(dict(
                _id={'$in': [mb.app_config_id for mb in mailboxes]})))
        for mb in mailboxes:
            project = projects.get(mb.project_id, None)
            app_config = app_index.get(mb.app_config_id, None)
            if project is None:
                mb.query.delete()
                continue
            if app_config is None:
                continue
            app = app_config.load()
            if not app.has_notifications:
                continue
            subscriptions.append(dict(
                subscription_id=mb._id,
                project_id=project._id,
                app_config_id=mb.app_config_id,
                project_name=project.name,
                tool=app_config.options['mount_label'],
                artifact_title=dict(
                    text='Everything' if mb.artifact_title == 'All artifacts' else mb.artifact_title,
                    href=mb.artifact_url),
                topic=mb.topic,
                type=mb.type,
                frequency=mb.frequency.unit,
                artifact=mb.artifact_index_id,
                subscribed=True))
        my_projects = dict((p._id, p) for p in c.user.my_projects())
        my_tools = M.AppConfig.query.find(dict(
            project_id={'$in': my_projects.keys()}))
        my_tools_subscriptions = dict(
            (mb.app_config_id, mb) for mb in M.Mailbox.query.find(dict(
                user_id=c.user._id,
                project_id={'$in': projects.keys()},
                app_config_id={'$in': app_index.keys()},
                artifact_index_id=None)))
        for tool in my_tools:
            if tool['_id'] in my_tools_subscriptions:
                continue  
            app = tool.load()
            if not app.has_notifications:
                continue
            subscriptions.append(
                dict(tool_id=tool._id,
                     user_id=c.user._id,
                     project_id=tool.project_id,
                     project_name=my_projects[tool.project_id].name,
                     tool=tool.options['mount_label'],
                     artifact_title='Everything',
                     topic=None,
                     type=None,
                     frequency=None,
                     artifact=None))
        subscriptions.sort(key=lambda d: (d['project_name'], d['tool']))
        provider = plugin.AuthenticationProvider.get(request)
        menu = provider.account_navigation()
        return dict(
            subscriptions=subscriptions,
            menu=menu)
def index ( self , ** kw ) : c . form = F . subscription_form c . revoke_access = F . oauth_revocation_form subscriptions = [ ] mailboxes = list ( M . Mailbox . query . find ( dict ( user_id = c . user . _id , is_flash = False ) ) ) projects = dict ( ( p . _id , p ) for p in M . Project . query . find ( dict ( _id = { '$in' : [ mb . project_id for mb in mailboxes ] } ) ) ) app_index = dict ( ( ac . _id , ac ) for ac in M . AppConfig . query . find ( dict ( _id = { '$in' : [ mb . app_config_id for mb in mailboxes ] } ) ) ) for mb in mailboxes : project = projects . get ( mb . project_id , None ) app_config = app_index . get ( mb . app_config_id , None ) if project is None : mb . query . delete ( ) continue if app_config is None : continue app = app_config . load ( ) if not app . has_notifications : continue subscriptions . append ( dict ( subscription_id = mb . _id , project_id = project . _id , app_config_id = mb . app_config_id , project_name = project . name , tool = app_config . options [ 'mount_label' ] , artifact_title = dict ( text = 'Everything' if mb . artifact_title == 'All artifacts' else mb . artifact_title , href = mb . artifact_url ) , topic = mb . topic , type = mb . type , frequency = mb . frequency . unit , artifact = mb . artifact_index_id , subscribed = True ) ) my_projects = dict ( ( p . _id , p ) for p in c . user . my_projects ( ) ) my_tools = M . AppConfig . query . find ( dict ( project_id = { '$in' : my_projects . keys ( ) } ) ) my_tools_subscriptions = dict ( ( mb . app_config_id , mb ) for mb in M . Mailbox . query . find ( dict ( user_id = c . user . _id , project_id = { '$in' : projects . keys ( ) } , app_config_id = { '$in' : app_index . keys ( ) } , artifact_index_id = None ) ) ) for tool in my_tools : if tool [ '_id' ] in my_tools_subscriptions : continue app = tool . load ( ) if not app . has_notifications : continue subscriptions . append ( dict ( tool_id = tool . _id , user_id = c . user . _id , project_id = tool . project_id , project_name = my_projects [ tool . project_id ] . name , tool = tool . options [ 'mount_label' ] , artifact_title = 'Everything' , topic = None , type = None , frequency = None , artifact = None ) ) subscriptions . sort ( key = lambda d : ( d [ 'project_name' ] , d [ 'tool' ] ) ) provider = plugin . AuthenticationProvider . get ( request ) menu = provider . account_navigation ( ) return dict ( subscriptions = subscriptions , menu = menu )
The subscription selection page in user preferences.
The subscription selection page in user preferences .
""" The subscription selection page in user preferences.

        Builds up a list of dictionaries, each containing subscription
        information about a tool.
        """ # Add the tools that are already subscribed to by the user. # Dictionary of all projects projects accessible based on a users credentials (user_roles). # Dictionary containing all tools (subscribed and un-subscribed). # Dictionary containing all the currently subscribed tools for a given user. # Add the remaining tools that are eligible for subscription. # We have already subscribed to this tool.
self