Beispiel #1
0
 def testUsersInvolvedInHotlists_Normal(self):
     hotlist1 = features_pb2.Hotlist(owner_ids=[111L, 222L],
                                     editor_ids=[333L, 444L, 555L],
                                     follower_ids=[123L])
     hotlist2 = features_pb2.Hotlist(owner_ids=[111L],
                                     editor_ids=[222L, 123L])
     self.assertEqual(
         set([111L, 222L, 333L, 444L, 555L, 123L]),
         features_bizobj.UsersInvolvedInHotlists([hotlist1, hotlist2]))
Beispiel #2
0
    def GatherPageData(self, mr):
        viewed_users_hotlists = self.services.features.GetHotlistsByUserID(
            mr.cnxn, mr.viewed_user_auth.user_id)

        viewed_starred_hids = self.services.hotlist_star.LookupStarredItemIDs(
            mr.cnxn, mr.viewed_user_auth.user_id)
        viewed_users_starred_hotlists, _ = self.services.features.GetHotlistsByID(
            mr.cnxn, viewed_starred_hids)

        viewed_users_relevant_hotlists = viewed_users_hotlists + list(
            set(viewed_users_starred_hotlists.values()) -
            set(viewed_users_hotlists))

        users_by_id = framework_views.MakeAllUserViews(
            mr.cnxn, self.services.user,
            features_bizobj.UsersInvolvedInHotlists(
                viewed_users_relevant_hotlists))

        views = [
            hotlist_views.HotlistView(
                hotlist_pb, mr.auth, mr.viewed_user_auth.user_id, users_by_id,
                self.services.hotlist_star.IsItemStarredBy(
                    mr.cnxn, hotlist_pb.hotlist_id, mr.auth.user_id))
            for hotlist_pb in viewed_users_relevant_hotlists
        ]

        # visible to viewer, not viewed_user
        visible_hotlists = [view for view in views if view.visible]

        owner_of_hotlists = [
            hotlist_view for hotlist_view in visible_hotlists
            if hotlist_view.role_name == 'owner'
        ]
        editor_of_hotlists = [
            hotlist_view for hotlist_view in visible_hotlists
            if hotlist_view.role_name == 'editor'
        ]
        follower_of_hotlists = [
            hotlist_view for hotlist_view in visible_hotlists
            if hotlist_view.role_name == ''
        ]
        starred_hotlists = [
            hotlist_view for hotlist_view in visible_hotlists
            if hotlist_view.hotlist_id in viewed_starred_hids
        ]

        viewed_user_display_name = framework_views.GetViewedUserDisplayName(mr)

        return {
            'user_tab_mode': 'st6',
            'viewed_user_display_name': viewed_user_display_name,
            'owner_of_hotlists': owner_of_hotlists,
            'editor_of_hotlists': editor_of_hotlists,
            'follower_of_hotlists': follower_of_hotlists,
            'starred_hotlists': starred_hotlists,
            'viewing_user_page': ezt.boolean(True),
        }
Beispiel #3
0
 def testUsersInvolvedInHotlists_Normal(self):
   hotlist1 = features_pb2.Hotlist(
       owner_ids=[111, 222], editor_ids=[333, 444, 555],
       follower_ids=[123])
   hotlist2 = features_pb2.Hotlist(
       owner_ids=[111], editor_ids=[222, 123])
   self.assertEqual(set([111, 222, 333, 444, 555, 123]),
                    features_bizobj.UsersInvolvedInHotlists([hotlist1,
                                                             hotlist2]))
Beispiel #4
0
    def GetGridViewData(self, mr):
        """EZT template values to render a Table View of issues.

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

    Returns:
      Dictionary of page data for rendering of the Table View.
    """
        mr.ComputeColSpec(mr.hotlist)
        starred_iid_set = set(
            self.services.issue_star.LookupStarredItemIDs(
                mr.cnxn, mr.auth.user_id))
        issues_list = self.services.issue.GetIssues(
            mr.cnxn,
            [hotlist_issue.issue_id for hotlist_issue in mr.hotlist.items])
        allowed_issues = hotlist_helpers.FilterIssues(mr, issues_list,
                                                      self.services)
        issue_and_hotlist_users = tracker_bizobj.UsersInvolvedInIssues(
            allowed_issues
            or []).union(features_bizobj.UsersInvolvedInHotlists([mr.hotlist]))
        users_by_id = framework_views.MakeAllUserViews(
            mr.cnxn, self.services.user, issue_and_hotlist_users)
        hotlist_issues_project_ids = hotlist_helpers.GetAllProjectsOfIssues(
            [issue for issue in issues_list])
        config_list = hotlist_helpers.GetAllConfigsOfProjects(
            mr.cnxn, hotlist_issues_project_ids, self.services)
        harmonized_config = tracker_bizobj.HarmonizeConfigs(config_list)
        limit = settings.max_issues_in_grid
        grid_limited = len(allowed_issues) > limit
        lower_cols = mr.col_spec.lower().split()
        grid_x = (mr.x or harmonized_config.default_x_attr or '--').lower()
        grid_y = (mr.y or harmonized_config.default_y_attr or '--').lower()
        lower_cols.append(grid_x)
        lower_cols.append(grid_y)
        related_iids = set()
        for issue in allowed_issues:
            if 'blockedon' in lower_cols:
                related_iids.update(issue.blocked_on_iids)
            if 'blocking' in lower_cols:
                related_iids.update(issue.blocking_iids)
            if 'mergedinto' in lower_cols:
                related_iids.add(issue.merged_into)
        related_issues_list = self.services.issue.GetIssues(
            mr.cnxn, list(related_iids))
        related_issues = {
            issue.issue_id: issue
            for issue in related_issues_list
        }

        hotlist_context_dict = {
            hotlist_issue.issue_id: {
                'adder_id': hotlist_issue.adder_id,
                'date_added':
                timestr.FormatRelativeDate(hotlist_issue.date_added),
                'note': hotlist_issue.note
            }
            for hotlist_issue in mr.hotlist.items
        }

        grid_view_data = grid_view_helpers.GetGridViewData(
            mr,
            allowed_issues,
            harmonized_config,
            users_by_id,
            starred_iid_set,
            grid_limited,
            related_issues,
            hotlist_context_dict=hotlist_context_dict)

        url_params = [(name, mr.GetParam(name))
                      for name in framework_helpers.RECOGNIZED_PARAMS]
        # We are passing in None for the project_name in ArtifactPagination
        # because we are not operating under any project.
        grid_view_data.update({
            'pagination':
            paginate.ArtifactPagination(
                allowed_issues,
                mr.GetPositiveIntParam(
                    'num', features_constants.DEFAULT_RESULTS_PER_PAGE),
                mr.GetPositiveIntParam('start'),
                None,
                urls.HOTLIST_ISSUES,
                total_count=len(allowed_issues),
                url_params=url_params)
        })

        return grid_view_data
Beispiel #5
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

        with work_env.WorkEnv(mr, self.services) as we:
            is_project_starred = False
            project_view = None
            if mr.project:
                if permissions.UserCanViewProject(mr.auth.user_pb,
                                                  mr.auth.effective_ids,
                                                  mr.project):
                    is_project_starred = we.IsProjectStarred(mr.project_id)
                    # 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.perms, 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

        issue_entry_url = 'entry'
        config = None
        if mr.project_id and self.services.config:
            with mr.profiler.Phase('getting config'):
                config = self.services.config.GetProjectConfig(
                    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()
            issue_entry_url = _LoginOrIssueEntryURL(mr, config)

        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('/')
        version_base = _VersionBaseURL(mr.request)

        base_data = {
            # EZT does not have constants for True and False, so we pass them in.
            'True':
            ezt.boolean(True),
            'False':
            ezt.boolean(False),
            'local_mode':
            ezt.boolean(settings.local_mode),
            '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, mr.project)),
            '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,

            # Options for issuelist display
            'grid_x_attr':
            grid_x_attr,
            'grid_y_attr':
            grid_y_attr,
            'grid_cell_mode':
            mr.cells,
            'grid_mode':
            None,
            'list_mode':
            None,
            'chart_mode':
            None,
            'issue_entry_url':
            issue_entry_url,
            '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),
            'version_base':
            version_base,
            'app_version':
            app_version,
            'gapi_client_id':
            settings.gapi_client_id,
            'viewing_user_page':
            ezt.boolean(False),
            'old_ui_url':
            None,
            'is_member':
            ezt.boolean(False),
        }

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

        # Always add xhr-xsrf token because even anon users need some
        # pRPC methods, e.g., autocomplete, flipper, and charts.
        base_data['token_expires_sec'] = xsrf.TokenExpiresSec()
        base_data['xhr_token'] = xsrf.GenerateToken(mr.auth.user_id,
                                                    xsrf.XHR_SERVLET_PATH)
        # Always add other anti-xsrf tokens 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

        return base_data
Beispiel #6
0
 def testUsersInvolvedInHotlists_Empty(self):
     self.assertEqual(set(), features_bizobj.UsersInvolvedInHotlists([]))