Beispiel #1
0
    def isauthorized(self, openid_identity, openid_trust_root):
        if identity.current.anonymous:
            return False

        username = identity.current.user.username
        person = People.by_username(username)

        if build_url(id_base_url + '/' + identity.current.user_name) != openid_identity:
            return False

        key = (openid_identity, openid_trust_root)

        return session.get(key)
Beispiel #2
0
    def isauthorized(self, openid_identity, openid_trust_root):
        if identity.current.anonymous:
            return False

        username = identity.current.user.username
        person = People.by_username(username)
        if not cla_done(person):
            return False

        if build_url(id_base_url + '/' +
                     identity.current.user_name) != openid_identity:
            return False

        key = (openid_identity, openid_trust_root)

        return session.get(key)
Beispiel #3
0
 def resolve(self, meta, name):
   if name == '~hand':  # I don't like this
     return session.get('hand', None)
   return super(CapRoot, self).resolve(meta, name)
Beispiel #4
0
 def updateCrumbTrail(self, path): 
   trail = session.get('path', ())
   if not trail or not '/'.join(trail).startswith('/'.join((path))):
     logging.getLogger('root.controller.http').debug("Updating crumb trail: %s %s", trail, path)
     session['path'] = path
    def renderMenu(self, main_nav, sub_nav=''):
        children = []
        main_menu = []
        sub_menu = []

        user = identity.current.user
        customer = identity.current.user.customer
        brand = customer.brand

        # See if we have a cached copy available to use
        last_config_change = masterdb.Customer._connection.queryOne("select last_config_change from Customer where id=%s" % customer.id)[0]
        if not last_config_change: 
            last_config_change = datetime.now()
            customer.last_config_change = last_config_change
        if 'menu-user' in session and 'menu-content' in session and session['menu-user'] == user and \
              session.get('menu-timestamp', datetime(2014,1,1)) > last_config_change:
            return (session['menu-content'], [])

        # If we get a customer that hasn't picked a package, set it to the Brand's highlight_package
        if customer.brand and not customer.package:
            customer.package = customer.brand.highlight_package


        menu_items = self.main_nav
        extra_items = []
        excluded_items = []

        #if customer.package.isFreeTrial():
	    #excluded_items.append('menu.billing')
        # Exclude some items that aren't included in some brands

        if brand:
            if not brand.show_billing and not user.isSuperuser(): excluded_items.append('menu.billing')
            if not brand.show_support and not user.isSuperuser(): excluded_items.append('menu.support')
            if not brand.show_public_reports: excluded_items.append('menu.reports.public')
            if not brand.show_email_templates: excluded_items.append('menu.settings.email_templates')
            if not customer.hasSnmpPolling(): excluded_items.append('menu.settings.snmp_credential')
            #print "="*80 + user.server_group_access + "*"*80
            if brand.isWhiteLabel() and brand.textkey != 'panopta':
                excluded_items.append('menu.downloads')

            # Special template for FireHost doesn't need Dashboard menu
            if brand.textkey == 'partner.firehost': 
                excluded_items.append('menu.dashboard')
                
        if not customer.public_reports_v1: excluded_items.append('menu.reports.public')

        if user.server_group_access == 'selected': excluded_items.append('menu.settings.apikey')

        # Exclude the user/contacts menu if the user only has a partial view of the account
        if user.server_group_access == 'selected': excluded_items.append('menu.contacts')

        if not customer.canAddServer(): excluded_items.append('menu.server.add_server')

        # Show the global menu for install-level and brand-level admins
        if not user.hasModeratePermission(): excluded_items.append('menu.global')
        
        if not user.isRelatedToAdmin() and not user.customer.brand.hasHeatmap(): 
            excluded_items.append('menu.global.unified_heatmap')

        if not user.isRelatedToAdmin(): 
            # Hide the global items that only apply to install-level admins
            excluded_items.append('menu.global.outage_history')
            excluded_items.append('menu.global.account_history')

        if not user.isRelatedToSuperuser(): excluded_items.append('menu.reports.reseller_summary')

        if not user.isRelatedToAdmin(): excluded_items.append('menu.settings.dashboard')
        
        if user.isDashboardOnlyAccess():
            excluded_items.append('menu.outages')
            excluded_items.append('menu.config')
            excluded_items.append('menu.reports')
            excluded_items.append('menu.billing')
            excluded_items.append('menu.downloads')
            excluded_items.append('menu.global')
            for item in menu_items:
                if item["id"] == "menu.settings":   
                    item.update({
                        'id': 'menu.settings.my_account',
                        'label': 'My Account',
                        'name': _('My Account'), 
                        'data-toggle': 'modal',
                        'link': '/userconfig/EditUser?user_id=-1',
                        'children': []
                    })
                    
#        # Show billing if not restricted by branding
#        if not brand or (brand and brand.show_billing):
#            extra_items.append({'name': 'billing',
#                                'label': _('Billing'),
#                                'link': '/billing',
#                                'children': [],
#                                'perm': 'perm.billing',
#                               })
#        if not brand or (brand and brand.show_support):
#            extra_items.append({'name': 'support',
#                               'label': _('Support'),
#                               'link': '/support',
#                               'children': []
#                               })


        for item in menu_items:
            css_class = ''

 
            if main_nav == item['name']: 
                # We found the menu item that is currently active - set the correct
                # CSS class so that it is rendered properly, plus grab any children that we 
                # need to handle
                css_class = 'active'
                children = item['children']

            # Skip this item if they don't have permission to access or it should be shielded for the brand
            if item['id'] in excluded_items: continue
            if item.has_key('perm') and not identity.has_permission(item['perm']): continue
            
            children = []
            for child in item['children']:
                if child['id'] in excluded_items: continue
                if child.has_key('perm') and not identity.has_permission(child['perm']): continue
                children.append(child)

            link = item['link']
            if len(children) == 1:
                link = children[0]['link']
                children = []

            main_menu.append({'name': item['label'], 
                              'link': link, 
                              'link_class': item.get('link_class', ''),
                              'css_class': css_class,
                              'target': item.get('target', '_self'),
                              'data-toggle': item.get('data-toggle', ''),
                              'children': children})

        # Add custom dashboard links
        main_menu[0]['children'].append({'id': 'menu.dashboard.panopta',
                                         'name': '%s Home' % brand.name,
                                         'label': '%s Home' % brand.name,
                                         'link': '/dashboard',
                                         'children': []})

        dashboards = masterdb.Dashboard.selectBy(customer=customer, deleted=False).orderBy("rank")
        dashboard_list = []
        for d in dashboards:
            if d.created_by != user:
                if d.access_level == 'only_for_me': continue
                elif d.access_level == 'limited_by_tag' and not any([t in user.tags for t in d.tags]): continue
            dashboard_list.append({
                'name': d.name,                
                'rank': d.rank,
                'id': d.id,
                'link': '/dashboard/render_dashboard?dashboard_id=%s' % d.id
            })
        customer_heatmap = customer.getAttribute("heatmap_config")
        try:
            config = json.loads(customer_heatmap)
            d = config['dashboard']
            dashboard_list.append({
                'name': d['name'],
                'rank': d['rank'],
                'id': 'heatmap',
                'link': '/dashboard/Heatmap'
            })
        except:
            pass
        dashboard_list.sort(key=lambda d: d['rank'])        
        for d in dashboard_list:
            main_menu[0]['children'].append({'id': 'menu.dashboard.%s' % d['id'],
                                             'name': d['name'],
                                             'label': d['name'],
                                             'link': d['link'],
                                             'children': [],
                                             })

        if user.inGroup("customer.config") or user.inGroup('brand.superuser') or user.inGroup('customer.admin') or user.inGroup('admin'):
            main_menu[0]['children'].append({'id': 'menu.dashboard.add_dashboard',
                                             'name': 'Add Dashboard',
                                             'label': 'Add Dashboard',  
                                             'data-toggle': 'modal',
                                             'data-divider': 'true',
                                             'link': '/dashboard/EditDashboard',
                                             'children': []})

        # Store the rendered menu in the session so it can be reused on the next pageload
        session['menu-user'] = user
        session['menu-content'] = main_menu
        session['menu-timestamp'] = datetime.now()

        return (main_menu, sub_menu)