コード例 #1
0
 def test_GetBinnedHotlistViews_Multiple(self):
     """Should correctly bin each hotlist view when passed in multiple views"""
     hotlist_h1 = fake.Hotlist(hotlist_name='h1',
                               hotlist_id=1,
                               owner_ids=[111L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h1_view = hotlist_views.HotlistView(hotlist_h1,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     hotlist_h2 = fake.Hotlist(hotlist_name='h2',
                               hotlist_id=2,
                               owner_ids=[222L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h2_view = hotlist_views.HotlistView(hotlist_h2,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     hotlist_h3 = fake.Hotlist(hotlist_name='h3',
                               hotlist_id=3,
                               owner_ids=[333L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h3_view = hotlist_views.HotlistView(hotlist_h3,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     self.assertEqual(
         ([h2_view], [h1_view], [h3_view]),
         issuedetail._GetBinnedHotlistViews([h1_view, h2_view, h3_view],
                                            involved_users=[111L]))
コード例 #2
0
ファイル: hotlist_views_test.py プロジェクト: xinghun61/infra
    def testFriendlyURL(self):
        # owner with obscure_email:false
        hotlist = fake.Hotlist('noObscureHotlist',
                               133,
                               owner_ids=[2],
                               editor_ids=[3])
        hotlist_view = hotlist_views.HotlistView(hotlist,
                                                 self.perms,
                                                 self.user_auth,
                                                 viewed_user_id=3,
                                                 users_by_id=self.users_by_id)
        self.assertEqual(hotlist_view.url,
                         '/u/user2/hotlists/noObscureHotlist')

        #owner with obscure_email:true
        hotlist = fake.Hotlist('ObscureHotlist',
                               133,
                               owner_ids=[1],
                               editor_ids=[3])
        hotlist_view = hotlist_views.HotlistView(hotlist,
                                                 self.perms,
                                                 self.user_auth,
                                                 viewed_user_id=1,
                                                 users_by_id=self.users_by_id)
        self.assertEqual(hotlist_view.url, '/u/1/hotlists/ObscureHotlist')
コード例 #3
0
    def testBanned(self):
        # With a banned user
        hotlist = fake.Hotlist('userBanned', 423, owner_ids=[4])
        hotlist_view = hotlist_views.HotlistView(hotlist, self.user_auth, 1,
                                                 self.users_by_id)
        self.assertFalse(hotlist_view.visible)

        # With a user not banned
        hotlist = fake.Hotlist('userNotBanned', 453, owner_ids=[1])
        hotlist_view = hotlist_views.HotlistView(hotlist, self.user_auth, 1,
                                                 self.users_by_id)
        self.assertTrue(hotlist_view.visible)
コード例 #4
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),
        }
コード例 #5
0
 def testNoPermissions(self):
     hotlist = fake.Hotlist('private',
                            333,
                            is_private=True,
                            owner_ids=[1],
                            editor_ids=[2])
     hotlist_view = hotlist_views.HotlistView(hotlist, self.user_auth, 1,
                                              self.users_by_id)
     self.assertFalse(hotlist_view.visible)
     self.assertEqual(hotlist_view.url, '/u/1/hotlists/private')
コード例 #6
0
 def test_GetBinnedHotlistViews_OtherUserHasAHotlist(self):
     """user uo1 owns h3; uo1 is an "other"; h3 should go into the "user" bin"""
     # Hotlist h3; user uo1 owns h3; uo3 is an *other* user.
     hotlist_h3 = fake.Hotlist(hotlist_name='h3',
                               hotlist_id=3,
                               owner_ids=[333L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h3_view = hotlist_views.HotlistView(hotlist_h3,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     self.assertEqual(
         ([], [], [h3_view]),
         issuedetail._GetBinnedHotlistViews([h3_view],
                                            involved_users=[111L]))
コード例 #7
0
 def test_GetBinnedHotlistViews_SignedInUserHasAHotlist(self):
     """user ul1 owns h2 and is logged in; h2 should go into the "user" bin"""
     # Hotlist h2; user ul1 owns h2; ul1 is a *logged in* user.
     hotlist_h2 = fake.Hotlist(hotlist_name='h2',
                               hotlist_id=2,
                               owner_ids=[222L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h2_view = hotlist_views.HotlistView(hotlist_h2,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     self.assertEqual(
         ([h2_view], [], []),
         issuedetail._GetBinnedHotlistViews([h2_view],
                                            involved_users=[111L]))
コード例 #8
0
 def test_GetBinnedHotlistViews_IssueOwnerHasAHotlist(self):
     """user u1 owns h1 and the issue; h1 should go into the "involved" bin."""
     # Hotlist h1; user u1 owns h1; u1 is the issue reporter and owner, and so
     # is an *involved* user.
     hotlist_h1 = fake.Hotlist(hotlist_name='h1',
                               hotlist_id=1,
                               owner_ids=[111L],
                               hotlist_item_fields=self.hotlist_item_fields)
     h1_view = hotlist_views.HotlistView(hotlist_h1,
                                         viewed_user_id=222L,
                                         user_auth=self.user_auth,
                                         users_by_id=self.userviews_by_id)
     self.assertEqual(
         ([], [h1_view], []),
         issuedetail._GetBinnedHotlistViews([h1_view],
                                            involved_users=[111L]))
コード例 #9
0
 def testOtherAttributes(self):
     hotlist = fake.Hotlist('hotlistName',
                            123,
                            hotlist_item_fields=[(2, 0, None, None, ''),
                                                 (1, 0, None, None, ''),
                                                 (5, 0, None, None, '')],
                            is_private=False,
                            owner_ids=[1],
                            editor_ids=[2, 3])
     hotlist_view = hotlist_views.HotlistView(hotlist,
                                              self.user_auth,
                                              viewed_user_id=2,
                                              users_by_id=self.users_by_id,
                                              is_starred=True)
     self.assertTrue(hotlist_view.visible, True)
     self.assertEqual(hotlist_view.role_name, 'editor')
     self.assertEqual(hotlist_view.owners, [self.user1_view])
     self.assertEqual(hotlist_view.editors,
                      [self.user2_view, self.user3_view])
     self.assertEqual(hotlist_view.num_issues, 3)
     self.assertTrue(hotlist_view.is_starred)
コード例 #10
0
ファイル: servlet.py プロジェクト: xinghun61/infra
    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
コード例 #11
0
ファイル: hotlist_views_test.py プロジェクト: xinghun61/infra
 def testNoOwner(self):
     hotlist = fake.Hotlist('unowned', 500, owner_ids=[])
     view = hotlist_views.HotlistView(hotlist, self.perms, self.user_auth,
                                      1, self.users_by_id)
     self.assertFalse(view.url)