Esempio n. 1
0
  def test_is_user_cloud_admin(self):
    # slip in some fake users
    self.setupUserInfoMocks()

    # mock out the App Engine Users API
    self.setupUsersAPIMocks()

    data1 = AppDashboardData()

    # First call, not logged in.
    self.assertFalse(data1.is_user_cloud_admin())

    # First user: [email protected], admin=True.
    self.assertTrue(data1.is_user_cloud_admin())

    # Second user: [email protected], admin=False.
    self.assertFalse(data1.is_user_cloud_admin())

    # Third user: [email protected], admin=False.
    self.assertFalse(data1.is_user_cloud_admin())
  def test_is_user_cloud_admin(self):
    # slip in some fake users
    self.setupUserInfoMocks()

    # mock out the App Engine Users API
    self.setupUsersAPIMocks()

    data1 = AppDashboardData()

    # First call, not logged in.
    self.assertFalse(data1.is_user_cloud_admin())

    # First user: [email protected], admin=True.
    self.assertTrue(data1.is_user_cloud_admin())

    # Second user: [email protected], admin=False.
    self.assertFalse(data1.is_user_cloud_admin())

    # Third user: [email protected], admin=False.
    self.assertFalse(data1.is_user_cloud_admin())
class AppDashboard(webapp2.RequestHandler):
  """ Class that all pages in the Dashboard must inherit from. """


  # Regular expression to capture the continue url.
  CONTINUE_URL_REGEX = 'continue=(.*)$'


  # Regular expression for updating user permissions.
  USER_PERMISSION_REGEX = '^user_permission_'


  # Regular expression that matches email addresses.
  USER_EMAIL_REGEX = '^\w[^@\s]*@[^@\s]{2,}$'


  # The frequency, in seconds, that defines how often Task Queue tasks are fired
  # to update the Dashboard's Datastore cache.
  REFRESH_WAIT_TIME = 10


  def __init__(self, request, response):
    """ Constructor.
    
    Args:
      request: The webapp2.Request object that contains information about the
        current web request.
      response: The webapp2.Response object that contains the response to be
        sent back to the browser.
    """
    self.initialize(request, response)
    self.helper = AppDashboardHelper()
    self.dstore = AppDashboardData(self.helper)


  def render_template(self, template_file, values=None):
    """ Renders a template file with all variables loaded.

    Args: 
      template_file: A str with the relative path to template file.
      values: A dict with key/value pairs used as variables in the jinja
        template files.
    Returns:
      A str with the rendered template.
    """
    if values is None:
      values = {}

    owned_apps = self.dstore.get_owned_apps()
    self.helper.update_cookie_app_list(owned_apps, self.request, self.response)

    template = jinja_environment.get_template(template_file)
    sub_vars = {
      'logged_in' : self.helper.is_user_logged_in(),
      'user_email' : self.helper.get_user_email(),
      'is_user_cloud_admin' : self.dstore.is_user_cloud_admin(),
      'can_upload_apps' : self.dstore.can_upload_apps(),
      'apps_user_is_admin_on' : owned_apps,
      'flower_url' : self.dstore.get_flower_url(),
    }
    for key in values.keys():
      sub_vars[key] = values[key]
    return template.render(sub_vars)


  def get_shared_navigation(self):
    """ Renders the shared navigation.

    Returns:
      A str with the navigation bar rendered.
    """
    return self.render_template(template_file='shared/navigation.html')

  def render_page(self, page, template_file, values=None ):
    """ Renders a template with the main layout and nav bar. """
    if values is None:
      values = {}
    self.response.headers['Content-Type'] = 'text/html'
    template = jinja_environment.get_template('layouts/main.html')
    self.response.out.write(template.render(
        page_name=page,
        page_body=self.render_template(template_file, values),
        shared_navigation=self.get_shared_navigation()
        ))
Esempio n. 4
0
class AppDashboard(webapp2.RequestHandler):
  """ Class that all pages in the Dashboard must inherit from. """

  # Regular expression to capture the continue url.
  CONTINUE_URL_REGEX = 'continue=(.*)$'

  # The dashboard's project ID.
  PROJECT_ID = 'appscaledashboard'

  # Regular expression for updating user permissions.
  USER_PERMISSION_REGEX = '^user_permission_'

  # Regular expression that matches email addresses.
  USER_EMAIL_REGEX = '^\w[^@\s]*@[^@\s]{2,}$'

  # The frequency, in seconds, that defines how often Task Queue tasks are fired
  # to update the Dashboard's Datastore cache.
  REFRESH_WAIT_TIME = 10

  def __init__(self, request, response):
    """ Constructor.

    Args:
      request: The webapp2.Request object that contains information about the
        current web request.
      response: The webapp2.Response object that contains the response to be
        sent back to the browser.
    """
    self.initialize(request, response)
    self.helper = AppDashboardHelper()
    self.dstore = AppDashboardData(self.helper)

  def render_template(self, template_file, values=None):
    """ Renders a template file with all variables loaded.

    Args:
      template_file: A str with the relative path to template file.
      values: A dict with key/value pairs used as variables in the jinja
        template files.
    Returns:
      A str with the rendered template.
    """
    if values is None:
      values = {}

    is_cloud_admin = self.helper.is_user_cloud_admin()
    all_versions = self.helper.get_version_info()

    if is_cloud_admin:
      apps_user_owns = list({version.split('_')[0]
                             for version in all_versions})
    else:
      apps_user_owns = self.helper.get_owned_apps()

    versions_user_is_admin_on = {
      version: all_versions[version] for version in all_versions
      if version.split('_')[0] in apps_user_owns}

    self.helper.update_cookie_app_list(apps_user_owns, self.request,
                                       self.response)
    template = jinja_environment.get_template(template_file)
    sub_vars = {
      'logged_in': self.helper.is_user_logged_in(),
      'user_email': self.helper.get_user_email(),
      'is_user_cloud_admin': self.dstore.is_user_cloud_admin(),
      'can_upload_apps': self.dstore.can_upload_apps(),
      'versions_user_is_admin_on': versions_user_is_admin_on,
      'user_layout_pref': self.dstore.get_dash_layout_settings(),
      'flower_url': self.dstore.get_flower_url(),
      'monit_url': self.dstore.get_monit_url()
    }
    for key in values.keys():
      sub_vars[key] = values[key]
    return template.render(sub_vars)

  def get_shared_navigation(self, page):
    """ Renders the shared navigation.

    Args:
      page: A string specifying the page ID.
    Returns:
      A str with the navigation bar rendered.
    """
    show_create_account = True
    if AppDashboardHelper.USE_SHIBBOLETH:
      show_create_account = False

    # These sections do not lend themselves well to having panels.
    panel_blacklist = ['monit', 'taskqueue', 'datastore_viewer']
    return self.render_template(template_file='shared/navigation.html',
                                values={'show_create_account':
                                        show_create_account,
                                        'page_name': page,
                                        'panel_blacklist': panel_blacklist})

  def render_page(self, page, template_file, values=None):
    """ Renders a template with the main layout and nav bar.

    Args:
      page: A string specifying the page ID.
      template_file: A string specifying the template to use.
      values: A dictionary containing template variables.
    """
    if values is None:
      values = {}
    self.response.headers['Content-Type'] = 'text/html'
    template = jinja_environment.get_template('layouts/main.html')
    self.response.out.write(template.render(
      page_name=page,
      page_body=self.render_template(template_file, values),
      shared_navigation=self.get_shared_navigation(page)
    ))

  def render_app_page(self, page, values=None):
    """ Render a typical page using the app_page template.

    Args:
      page: A string specifying the page ID.
      values: A dictionary containing template variables.
    """
    self.render_page(page=page, template_file="layouts/app_page.html",
                     values=values)
Esempio n. 5
0
class AppDashboard(webapp2.RequestHandler):
    """ Class that all pages in the Dashboard must inherit from. """

    # Regular expression to capture the continue url.
    CONTINUE_URL_REGEX = 'continue=(.*)$'

    # Regular expression for updating user permissions.
    USER_PERMISSION_REGEX = '^user_permission_'

    # Regular expression that matches email addresses.
    USER_EMAIL_REGEX = '^\w[^@\s]*@[^@\s]{2,}$'

    # The frequency, in seconds, that defines how often Task Queue tasks are fired
    # to update the Dashboard's Datastore cache.
    REFRESH_WAIT_TIME = 10

    def __init__(self, request, response):
        """ Constructor.
    
    Args:
      request: The webapp2.Request object that contains information about the
        current web request.
      response: The webapp2.Response object that contains the response to be
        sent back to the browser.
    """
        self.initialize(request, response)
        self.helper = AppDashboardHelper()
        self.dstore = AppDashboardData(self.helper)

    def render_template(self, template_file, values=None):
        """ Renders a template file with all variables loaded.

    Args: 
      template_file: A str with the relative path to template file.
      values: A dict with key/value pairs used as variables in the jinja
        template files.
    Returns:
      A str with the rendered template.
    """
        if values is None:
            values = {}

        owned_apps = self.dstore.get_owned_apps()
        self.helper.update_cookie_app_list(owned_apps, self.request,
                                           self.response)

        template = jinja_environment.get_template(template_file)
        sub_vars = {
            'logged_in': self.helper.is_user_logged_in(),
            'user_email': self.helper.get_user_email(),
            'is_user_cloud_admin': self.dstore.is_user_cloud_admin(),
            'can_upload_apps': self.dstore.can_upload_apps(),
            'apps_user_is_admin_on': owned_apps,
            'flower_url': self.dstore.get_flower_url(),
            'monit_url': self.dstore.get_monit_url()
        }
        for key in values.keys():
            sub_vars[key] = values[key]
        return template.render(sub_vars)

    def get_shared_navigation(self):
        """ Renders the shared navigation.

    Returns:
      A str with the navigation bar rendered.
    """
        show_create_account = True
        if AppDashboardHelper.USE_SHIBBOLETH:
            show_create_account = False
        return self.render_template(
            template_file='shared/navigation.html',
            values={'show_create_account': show_create_account})

    def render_page(self, page, template_file, values=None):
        """ Renders a template with the main layout and nav bar. """
        if values is None:
            values = {}
        self.response.headers['Content-Type'] = 'text/html'
        template = jinja_environment.get_template('layouts/main.html')
        self.response.out.write(
            template.render(page_name=page,
                            page_body=self.render_template(
                                template_file, values),
                            shared_navigation=self.get_shared_navigation()))
Esempio n. 6
0
class AppDashboard(webapp2.RequestHandler):
    """ Class that all pages in the Dashboard must inherit from. """

    # Regular expression to capture the continue url.
    CONTINUE_URL_REGEX = 'continue=(.*)$'

    # The dashboard's project ID.
    PROJECT_ID = 'appscaledashboard'

    # Regular expression for updating user permissions.
    USER_PERMISSION_REGEX = '^user_permission_'

    # Regular expression that matches email addresses.
    USER_EMAIL_REGEX = '^\w[^@\s]*@[^@\s]{2,}$'

    # The frequency, in seconds, that defines how often Task Queue tasks are fired
    # to update the Dashboard's Datastore cache.
    REFRESH_WAIT_TIME = 10

    def __init__(self, request, response):
        """ Constructor.

    Args:
      request: The webapp2.Request object that contains information about the
        current web request.
      response: The webapp2.Response object that contains the response to be
        sent back to the browser.
    """
        self.initialize(request, response)
        self.helper = AppDashboardHelper()
        self.dstore = AppDashboardData(self.helper)

    def render_template(self, template_file, values=None):
        """ Renders a template file with all variables loaded.

    Args:
      template_file: A str with the relative path to template file.
      values: A dict with key/value pairs used as variables in the jinja
        template files.
    Returns:
      A str with the rendered template.
    """
        if values is None:
            values = {}

        is_cloud_admin = self.helper.is_user_cloud_admin()
        all_versions = self.helper.get_version_info()

        if is_cloud_admin:
            apps_user_owns = list(
                {version.split('_')[0]
                 for version in all_versions})
        else:
            apps_user_owns = self.helper.get_owned_apps()

        versions_user_is_admin_on = {
            version: all_versions[version]
            for version in all_versions
            if version.split('_')[0] in apps_user_owns
        }

        self.helper.update_cookie_app_list(apps_user_owns, self.request,
                                           self.response)
        template = jinja_environment.get_template(template_file)
        sub_vars = {
            'logged_in': self.helper.is_user_logged_in(),
            'user_email': self.helper.get_user_email(),
            'is_user_cloud_admin': self.dstore.is_user_cloud_admin(),
            'can_upload_apps': self.dstore.can_upload_apps(),
            'versions_user_is_admin_on': versions_user_is_admin_on,
            'user_layout_pref': self.dstore.get_dash_layout_settings(),
            'flower_url': self.dstore.get_flower_url(),
            'monit_url': self.dstore.get_monit_url()
        }
        for key in values.keys():
            sub_vars[key] = values[key]
        return template.render(sub_vars)

    def get_shared_navigation(self, page):
        """ Renders the shared navigation.

    Args:
      page: A string specifying the page ID.
    Returns:
      A str with the navigation bar rendered.
    """
        show_create_account = True
        if AppDashboardHelper.USE_SHIBBOLETH:
            show_create_account = False

        # These sections do not lend themselves well to having panels.
        panel_blacklist = ['monit', 'taskqueue', 'datastore_viewer']
        return self.render_template(template_file='shared/navigation.html',
                                    values={
                                        'show_create_account':
                                        show_create_account,
                                        'page_name': page,
                                        'panel_blacklist': panel_blacklist
                                    })

    def render_page(self, page, template_file, values=None):
        """ Renders a template with the main layout and nav bar.

    Args:
      page: A string specifying the page ID.
      template_file: A string specifying the template to use.
      values: A dictionary containing template variables.
    """
        if values is None:
            values = {}
        self.response.headers['Content-Type'] = 'text/html'
        template = jinja_environment.get_template('layouts/main.html')
        self.response.out.write(
            template.render(
                page_name=page,
                page_body=self.render_template(template_file, values),
                shared_navigation=self.get_shared_navigation(page)))

    def render_app_page(self, page, values=None):
        """ Render a typical page using the app_page template.

    Args:
      page: A string specifying the page ID.
      values: A dictionary containing template variables.
    """
        self.render_page(page=page,
                         template_file="layouts/app_page.html",
                         values=values)