예제 #1
0
  def testDoUserAuthWithAllDomainUsersOff(self):
    self.stubs.Set(auth.settings, 'ALLOW_ALL_DOMAIN_USERS_READ_ACCESS', False)
    self.stubs.Set(auth, 'users', self.mox.CreateMock(auth.users))
    self.mox.StubOutWithMock(auth, 'IsAdminUser')
    self.mox.StubOutWithMock(auth, 'IsSupportUser')
    self.mox.StubOutWithMock(auth, 'IsSecurityUser')
    self.mox.StubOutWithMock(auth, 'IsPhysicalSecurityUser')

    mock_user = self.mox.CreateMockAnything()
    email = '*****@*****.**'
    auth.users.get_current_user().AndReturn(mock_user)
    mock_user.email().AndReturn(email)

    auth.IsAdminUser(email).AndReturn(False)
    auth.IsSupportUser(email).AndReturn(False)
    auth.IsSecurityUser(email).AndReturn(False)
    auth.IsPhysicalSecurityUser(email).AndReturn(True)

    self.mox.ReplayAll()
    self.assertEqual(mock_user, auth.DoUserAuth())
    self.mox.VerifyAll()
예제 #2
0
    def _DisplayHost(self, uuid=None, computer=None):
        """Displays the report for a single host.

    Args:
      uuid: str uuid for host to display.
      computer: models.Computer object to display.
    """
        if not uuid and not computer:
            self.response.set_status(404)
            return
        elif not computer:
            computer = models.Computer.get_by_key_name(uuid)
        else:
            uuid = computer.uuid

        popup = self.request.get('format', None) == 'popup'
        if popup:
            limit = 1
        else:
            limit = SINGLE_HOST_DATA_FETCH_LIMIT
        client_log_files = models.ClientLogFile.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        msu_log = models.ComputerMSULog.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        applesus_installs = models.InstallLog.all().filter(
            'uuid =', uuid).filter('applesus =',
                                   True).order('-mtime').fetch(limit)
        installs = models.InstallLog.all().filter('uuid =', uuid).filter(
            'applesus =', False).order('-mtime').fetch(limit)
        exits = models.PreflightExitLog.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        install_problems = models.ClientLog.all().filter(
            'action =',
            'install_problem').filter('uuid =',
                                      uuid).order('-mtime').fetch(limit)

        tags = {}
        tags_list = []
        if computer:
            # Generate tags data.
            tags_list = models.Tag.GetAllTagNamesForEntity(computer)
            for tag in tags_list:
                tags[tag] = True
            for tag in models.Tag.GetAllTagNames():
                if tag not in tags:
                    tags[tag] = False
            tags = json.dumps(tags, sort_keys=True)

            admin.AddTimezoneToComputerDatetimes(computer)
            computer.connection_dates.reverse()
            computer.connection_datetimes.reverse()

        try:
            uuid_lookup_url = settings.UUID_LOOKUP_URL
        except AttributeError:
            uuid_lookup_url = None

        try:
            owner_lookup_url = settings.OWNER_LOOKUP_URL
        except AttributeError:
            owner_lookup_url = None

        values = {
            'uuid_lookup_url': uuid_lookup_url,
            'owner_lookup_url': owner_lookup_url,
            'computer': computer,
            'applesus_installs': applesus_installs,
            'installs': installs,
            'client_log_files': client_log_files,
            'msu_log': msu_log,
            'install_problems': install_problems,
            'preflight_exits': exits,
            'tags': tags,
            'tags_list': tags_list,
            'host_report': True,
            'limit': SINGLE_HOST_DATA_FETCH_LIMIT,
            'is_support_user': auth.IsSupportUser(),
            'is_security_user': auth.IsSecurityUser(),
            'is_physical_security_user': auth.IsPhysicalSecurityUser(),
        }

        if popup:
            self.Render('host_popup.html', values)
        else:
            self.Render('host.html', values)
예제 #3
0
파일: host.py 프로젝트: tristansgray/simian
    def _DisplayHost(self, computer, self_report):
        """Displays the report for a single host.

    Args:
      computer: models.Computer object to display.
      self_report: if True, display as self report.
    """

        uuid = computer.uuid

        popup = self.request.get('format', None) == 'popup'
        if popup:
            limit = 1
        else:
            limit = SINGLE_HOST_DATA_FETCH_LIMIT
        client_log_files = models.ClientLogFile.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        msu_log = models.ComputerMSULog.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        applesus_installs = models.InstallLog.all().filter(
            'uuid =', uuid).filter('applesus =',
                                   True).order('-mtime').fetch(limit)
        installs = models.InstallLog.all().filter('uuid =', uuid).filter(
            'applesus =', False).order('-mtime').fetch(limit)
        exits = models.PreflightExitLog.all().filter(
            'uuid =', uuid).order('-mtime').fetch(limit)
        install_problems = models.ClientLog.all().filter(
            'action =',
            'install_problem').filter('uuid =',
                                      uuid).order('-mtime').fetch(limit)

        tags = {}
        tags_list = []
        groups = {}
        groups_list = []
        duplicates = []
        if computer:
            # Generate tags data.
            tags_list = models.Tag.GetAllTagNamesForEntity(computer)
            for tag in tags_list:
                tags[tag] = True
            for tag in models.Tag.GetAllTagNames():
                if tag not in tags:
                    tags[tag] = False
            tags = json.dumps(tags, sort_keys=True)

            # Generate groups data.
            groups_list = models.Group.GetAllGroupNamesForUser(computer.owner)
            for group in groups_list:
                groups[group] = True
            for group in models.Group.GetAllGroupNames():
                if group not in groups:
                    groups[group] = False
            groups = json.dumps(groups, sort_keys=True)

            admin.AddTimezoneToComputerDatetimes(computer)
            computer.connection_dates.reverse()
            computer.connection_datetimes.reverse()
            duplicates = models.Computer.all().filter(
                'serial =', computer.serial).fetch(20)
            duplicates = [e for e in duplicates if e.uuid != computer.uuid]

        try:
            uuid_lookup_url = settings.UUID_LOOKUP_URL
        except AttributeError:
            uuid_lookup_url = None

        try:
            owner_lookup_url = settings.OWNER_LOOKUP_URL
        except AttributeError:
            owner_lookup_url = None

        values = {
            'report_type': 'host',
            'uuid_lookup_url': uuid_lookup_url,
            'owner_lookup_url': owner_lookup_url,
            'client_site_enabled': settings.CLIENT_SITE_ENABLED,
            'computer': computer,
            'applesus_installs': applesus_installs,
            'installs': installs,
            'client_log_files': client_log_files,
            'msu_log': msu_log,
            'install_problems': install_problems,
            'preflight_exits': exits,
            'tags': tags,
            'tags_list': tags_list,
            'groups': groups,
            'groups_list': groups_list,
            'host_report': True,
            'limit': SINGLE_HOST_DATA_FETCH_LIMIT,
            'is_support_user': auth.IsSupportUser(),
            'is_security_user': auth.IsSecurityUser(),
            'is_physical_security_user': auth.IsPhysicalSecurityUser(),
            'self_report': self_report,
            'duplicates': duplicates,
            'tags_xsrf_token': xsrf.XsrfTokenGenerate('tags'),
            'groups_xsrf_token': xsrf.XsrfTokenGenerate('groups'),
        }

        if popup:
            self.Render('host_popup.html', values)
        else:
            self.Render('host.html', values)