Exemple #1
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dict of values used by EZT for rendering the page.
    """
        page_data = super(AdminViews, self).GatherPageData(mr)
        with mr.profiler.Phase('getting canned queries'):
            canned_queries = self.services.features.GetCannedQueriesByProjectID(
                mr.cnxn, mr.project_id)
            canned_query_views = [
                savedqueries_helpers.SavedQueryView(sq, idx + 1, None, None)
                for idx, sq in enumerate(canned_queries)
            ]

        page_data.update({
            'canned_queries':
            canned_query_views,
            'new_query_indexes':
            list(
                range(
                    len(canned_queries) + 1,
                    savedqueries_helpers.MAX_QUERIES + 1)),
            'issue_notify':
            mr.project.issue_notify_address,
            'max_queries':
            savedqueries_helpers.MAX_QUERIES,
        })
        return page_data
Exemple #2
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page."""
        saved_queries = self.services.features.GetSavedQueriesByUserID(
            mr.cnxn, mr.viewed_user_auth.user_id)
        saved_query_views = [
            savedqueries_helpers.SavedQueryView(sq, idx + 1, mr.cnxn,
                                                self.services.project)
            for idx, sq in enumerate(saved_queries)
        ]

        page_data = {
            'canned_queries':
            saved_query_views,
            'new_query_indexes': (list(
                range(
                    len(saved_queries) + 1,
                    savedqueries_helpers.MAX_QUERIES + 1))),
            'max_queries':
            savedqueries_helpers.MAX_QUERIES,
            'user_tab_mode':
            'st4',
            'viewing_user_page':
            ezt.boolean(True),
        }
        return page_data
Exemple #3
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dict of values used by EZT for rendering the page.
    """
        # TODO(jrobbins): Allow deep-linking into this page.
        canned_query_views = []
        if mr.project_id:
            with mr.profiler.Phase('getting canned queries'):
                canned_queries = self.services.features.GetCannedQueriesByProjectID(
                    mr.cnxn, mr.project_id)
            canned_query_views = [
                savedqueries_helpers.SavedQueryView(sq, idx + 1, None, None)
                for idx, sq in enumerate(canned_queries)
            ]

        saved_query_views = []
        if mr.auth.user_id and self.services.features:
            with mr.profiler.Phase('getting saved queries'):
                saved_queries = self.services.features.GetSavedQueriesByUserID(
                    mr.cnxn, mr.me_user_id)
                saved_query_views = [
                    savedqueries_helpers.SavedQueryView(
                        sq, idx + 1, None, None)
                    for idx, sq in enumerate(saved_queries)
                    if (mr.project_id in sq.executes_in_project_ids
                        or not mr.project_id)
                ]

        return {
            'issue_tab_mode': 'issueAdvSearch',
            'page_perms': self.MakePagePerms(mr, None,
                                             permissions.CREATE_ISSUE),
            'canned_queries': canned_query_views,
            'saved_queries': saved_query_views,
        }
Exemple #4
0
    def GatherBaseData(self, mr, nonce):
        """Return a dict of info used on almost all pages."""
        project = mr.project

        project_summary = ''
        project_alert = None
        project_read_only = False
        project_home_page = ''
        project_thumbnail_url = ''
        if project:
            project_summary = project.summary
            project_alert = _CalcProjectAlert(project)
            project_read_only = project.read_only_reason
            project_home_page = project.home_page
            project_thumbnail_url = tracker_views.LogoView(
                project).thumbnail_url

        # If we have both a project and a logged in user, we need to check if the
        # user has starred that project.
        with self.profiler.Phase('project star'):
            is_project_starred = False
            if mr.project and mr.auth.user_id:
                is_project_starred = self.services.project_star.IsItemStarredBy(
                    mr.cnxn, mr.project_id, mr.auth.user_id)

        project_view = None
        if mr.project:
            # TODO(jrobbins): should this be a ProjectView?
            project_view = template_helpers.PBProxy(mr.project)

        grid_x_attr = None
        grid_y_attr = None
        hotlist_view = None
        if mr.hotlist:
            users_by_id = framework_views.MakeAllUserViews(
                mr.cnxn, self.services.user,
                features_bizobj.UsersInvolvedInHotlists([mr.hotlist]))
            hotlist_view = hotlist_views.HotlistView(
                mr.hotlist, mr.auth, mr.viewed_user_auth.user_id, users_by_id,
                self.services.hotlist_star.IsItemStarredBy(
                    mr.cnxn, mr.hotlist.hotlist_id, mr.auth.user_id))
            grid_x_attr = mr.x.lower()
            grid_y_attr = mr.y.lower()

        app_version = os.environ.get('CURRENT_VERSION_ID')

        viewed_username = None
        if mr.viewed_user_auth.user_view:
            viewed_username = mr.viewed_user_auth.user_view.username

        canned_query_views = []
        issue_entry_url = 'entry'
        config = None
        if mr.project_id and self.services.config:
            with self.profiler.Phase('getting config'):
                config = self.services.config.GetProjectConfig(
                    mr.cnxn, mr.project_id)
                canned_queries = self.services.features.GetCannedQueriesByProjectID(
                    mr.cnxn, mr.project_id)
            grid_x_attr = (mr.x or config.default_x_attr).lower()
            grid_y_attr = (mr.y or config.default_y_attr).lower()
            canned_query_views = [
                savedqueries_helpers.SavedQueryView(sq, idx + 1, None, None)
                for idx, sq in enumerate(canned_queries)
            ]
            issue_entry_url = _LoginOrIssueEntryURL(mr, config)

        if mr.auth.user_id and self.services.features:
            with self.profiler.Phase('getting saved queries'):
                saved_queries = self.services.features.GetSavedQueriesByUserID(
                    mr.cnxn, mr.me_user_id)
                saved_query_views = [
                    savedqueries_helpers.SavedQueryView(
                        sq, idx + 1, None, None)
                    for idx, sq in enumerate(saved_queries)
                    if (mr.project_id in sq.executes_in_project_ids
                        or not mr.project_id)
                ]
        else:
            saved_query_views = []

        viewing_self = mr.auth.user_id == mr.viewed_user_auth.user_id
        offer_saved_queries_subtab = (viewing_self or mr.auth.user_pb
                                      and mr.auth.user_pb.is_site_admin)

        login_url = _SafeCreateLoginURL(mr)
        logout_url = _SafeCreateLogoutURL(mr)
        logout_url_goto_home = users.create_logout_url('/')

        base_data = {
            # EZT does not have constants for True and False, so we pass them in.
            'True':
            ezt.boolean(True),
            'False':
            ezt.boolean(False),
            'site_name':
            settings.site_name,
            'show_search_metadata':
            ezt.boolean(False),
            'page_template':
            self._PAGE_TEMPLATE,
            'main_tab_mode':
            self._MAIN_TAB_MODE,
            'project_summary':
            project_summary,
            'project_home_page':
            project_home_page,
            'project_thumbnail_url':
            project_thumbnail_url,
            'hotlist_id':
            mr.hotlist_id,
            'hotlist':
            hotlist_view,
            'hostport':
            mr.request.host,
            'absolute_base_url':
            '%s://%s' % (mr.request.scheme, mr.request.host),
            'project_home_url':
            None,
            'link_rel_canonical':
            None,  # For specifying <link rel="canonical">
            'projectname':
            mr.project_name,
            'project':
            project_view,
            'project_is_restricted':
            ezt.boolean(_ProjectIsRestricted(mr)),
            'offer_contributor_list':
            ezt.boolean(permissions.CanViewContributorList(mr)),
            'logged_in_user':
            mr.auth.user_view,
            'form_token':
            None,  # Set to a value below iff the user is logged in.
            'form_token_path':
            None,
            'token_expires_sec':
            None,
            'xhr_token':
            None,  # Set to a value below iff the user is logged in.
            'flag_spam_token':
            None,
            'nonce':
            nonce,
            'perms':
            mr.perms,
            'warnings':
            mr.warnings,
            'errors':
            mr.errors,
            'viewed_username':
            viewed_username,
            'viewed_user':
            mr.viewed_user_auth.user_view,
            'viewed_user_pb':
            template_helpers.PBProxy(mr.viewed_user_auth.user_pb),
            'viewing_self':
            ezt.boolean(viewing_self),
            'viewed_user_id':
            mr.viewed_user_auth.user_id,
            'offer_saved_queries_subtab':
            ezt.boolean(offer_saved_queries_subtab),
            'currentPageURL':
            mr.current_page_url,
            'currentPageURLEncoded':
            mr.current_page_url_encoded,
            'login_url':
            login_url,
            'logout_url':
            logout_url,
            'logout_url_goto_home':
            logout_url_goto_home,
            'continue_issue_id':
            mr.continue_issue_id,
            'feedback_email':
            settings.feedback_email,
            'category_css':
            None,  # Used to specify a category of stylesheet
            'category2_css':
            None,  # specify a 2nd category of stylesheet if needed.
            'page_css':
            None,  # Used to add a stylesheet to a specific page.
            'can':
            mr.can,
            'query':
            mr.query,
            'colspec':
            None,
            'sortspec':
            mr.sort_spec,
            'grid_x_attr':
            grid_x_attr,
            'grid_y_attr':
            grid_y_attr,
            'grid_cell_mode':
            mr.cells,
            'grid_mode':
            None,
            'issue_entry_url':
            issue_entry_url,
            'canned_queries':
            canned_query_views,
            'saved_queries':
            saved_query_views,
            'is_cross_project':
            ezt.boolean(False),

            # for project search (some also used in issue search)
            'start':
            mr.start,
            'num':
            mr.num,
            'groupby':
            mr.group_by_spec,
            'q_field_size': (min(
                framework_constants.MAX_ARTIFACT_SEARCH_FIELD_SIZE,
                max(framework_constants.MIN_ARTIFACT_SEARCH_FIELD_SIZE,
                    len(mr.query) + framework_constants.AUTOSIZE_STEP))),
            'mode':
            None,  # Display mode, e.g., grid mode.
            'ajah':
            mr.ajah,
            'table_title':
            mr.table_title,
            'alerts':
            alerts.AlertsView(mr),  # For alert.ezt
            'project_alert':
            project_alert,
            'title':
            None,  # First part of page title
            'title_summary':
            None,  # Appended to title on artifact detail pages

            # TODO(jrobbins): make sure that the templates use
            # project_read_only for project-mutative actions and if any
            # uses of read_only remain.
            'project_read_only':
            ezt.boolean(project_read_only),
            'site_read_only':
            ezt.boolean(settings.read_only),
            'banner_time':
            servlet_helpers.GetBannerTime(settings.banner_time),
            'read_only':
            ezt.boolean(settings.read_only or project_read_only),
            'site_banner_message':
            settings.banner_message,
            'robots_no_index':
            None,
            'analytics_id':
            settings.analytics_id,
            'is_project_starred':
            ezt.boolean(is_project_starred),
            'app_version':
            app_version,
            'viewing_user_page':
            ezt.boolean(False),
        }

        if mr.project:
            base_data['project_home_url'] = '/p/%s' % mr.project_name

        # Always add an anti-xsrf token when the user is logged in.
        if mr.auth.user_id:
            form_token_path = self._FormHandlerURL(mr.request.path)
            base_data['form_token'] = xsrf.GenerateToken(
                mr.auth.user_id, form_token_path)
            base_data['form_token_path'] = form_token_path
            base_data['token_expires_sec'] = xsrf.TokenExpiresSec()
            base_data['xhr_token'] = xsrf.GenerateToken(
                mr.auth.user_id, xsrf.XHR_SERVLET_PATH)
            base_data['flag_spam_token'] = xsrf.GenerateToken(
                mr.auth.user_id,
                '/p/%s%s.do' % (mr.project_name, urls.ISSUE_FLAGSPAM_JSON))

        return base_data