コード例 #1
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        # pylint: disable=W0212
        self.old_nav_mappings = DashboardHandler._custom_nav_mappings
        # pylint: disable=W0212
        DashboardHandler._custom_nav_mappings = {self.ACTION: 'outline'}
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()
コード例 #2
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        # pylint: disable=W0212
        self.old_nav_mappings = DashboardHandler._nav_mappings
        # pylint: disable=W0212
        DashboardHandler._nav_mappings = {self.ACTION: 'outline'}
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()
コード例 #3
0
 def test_dashboard_access_method(self):
     with Namespace(self.course_with_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_with_access.app_context))
     with Namespace(self.course_without_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_without_access.app_context))
     actions.login(self.USER_EMAIL, is_admin=False)
     with Namespace(self.course_with_access.app_context.namespace):
         self.assertTrue(DashboardHandler.current_user_has_access(
             self.course_with_access.app_context))
     with Namespace(self.course_without_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_without_access.app_context))
     actions.logout()
コード例 #4
0
 def test_dashboard_access_method(self):
     with Namespace(self.course_with_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_with_access.app_context))
     with Namespace(self.course_without_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_without_access.app_context))
     actions.login(self.USER_EMAIL, is_admin=False)
     with Namespace(self.course_with_access.app_context.namespace):
         self.assertTrue(DashboardHandler.current_user_has_access(
             self.course_with_access.app_context))
     with Namespace(self.course_without_access.app_context.namespace):
         self.assertFalse(DashboardHandler.current_user_has_access(
             self.course_without_access.app_context))
     actions.logout()
コード例 #5
0
ファイル: analytics.py プロジェクト: UniMOOC/gcb-new-module
def add_actions():
    def cluster_prepare_template(dashboard_instance):
        key = dashboard_instance.request.get('key')
        template_values = {}
        template_values['page_title'] = dashboard_instance.format_title(
            'Edit Cluster')
        template_values['main_content'] = dashboard_instance.get_form(
            clustering.ClusterRESTHandler, key,
            '/dashboard?action=analytics&tab=clustering',
            auto_return=True, app_context=dashboard_instance.app_context)
        dashboard_instance.render_page(template_values, 'clusters')

    DashboardHandler.add_custom_get_action('add_cluster',
                                           cluster_prepare_template)
    DashboardHandler.add_custom_get_action('edit_cluster',
                                           cluster_prepare_template)
コード例 #6
0
def add_actions():
    def cluster_prepare_template(dashboard_instance):
        key = dashboard_instance.request.get('key')
        template_values = {}
        template_values['page_title'] = dashboard_instance.format_title(
            'Edit Cluster')
        template_values['main_content'] = dashboard_instance.get_form(
            clustering.ClusterRESTHandler,
            key,
            '/dashboard?action=analytics&tab=clustering',
            auto_return=True,
            app_context=dashboard_instance.app_context)
        dashboard_instance.render_page(template_values, 'clusters')

    DashboardHandler.add_custom_get_action('add_cluster',
                                           cluster_prepare_template)
    DashboardHandler.add_custom_get_action('edit_cluster',
                                           cluster_prepare_template)
コード例 #7
0
    def test_custom_top_nav(self):
        # Add a new top level navigation action
        DashboardHandler.add_nav_mapping(self.ACTION, 'CUSTOM_MOD')

        class CustomNavHandler(object):
            @classmethod
            def show_page(cls, dashboard_handler):
                dashboard_handler.render_page({
                    'page_title':
                    dashboard_handler.format_title('CustomNav'),
                    'main_content':
                    'MainContent'
                })

        DashboardHandler.add_custom_get_action(self.ACTION,
                                               CustomNavHandler.show_page)

        dom = self.parse_html_string(self.get('dashboard').body)
        selected_nav_path = ('.//tr[@class="gcb-nav-bar-level-1"]'
                             '//a[@class="selected"]')
        self.assertEquals('Outline', dom.find(selected_nav_path).text)
        dom = self.parse_html_string(self.get(self.URL).body)

        self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text)
        self.assertEquals('MainContent',
                          dom.find(self.CONTENT_PATH).text.strip())

        DashboardHandler.remove_custom_get_action(self.ACTION)

        # Add a new tab under the new navigation action
        class CustomTabHandler(object):
            @classmethod
            def display_html(cls, unused_dashboard_handler):
                return 'MainTabContent'

        tabs.Registry.register(self.ACTION, 'cu_tab', 'CustomTab',
                               CustomTabHandler)
        DashboardHandler.add_custom_get_action(self.ACTION, None)
        dom = self.parse_html_string(self.get(self.URL).body)
        self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text)
        self.assertEquals('MainTabContent',
                          dom.find(self.CONTENT_PATH).text.strip())

        selected_tab_path = ('.//*[@class="gcb-nav-bar-level-2"]'
                             '//a[@class="selected"]')
        self.assertEquals('CustomTab', dom.find(selected_tab_path).text)
コード例 #8
0
    def test_custom_top_nav(self):
        # Add a new top level navigation action
        DashboardHandler.add_nav_mapping(self.ACTION, 'CUSTOM_MOD')

        class CustomNavHandler(object):

            @classmethod
            def show_page(cls, dashboard_handler):
                dashboard_handler.render_page({
                    'page_title': dashboard_handler.format_title('CustomNav'),
                    'main_content': 'MainContent'})
        DashboardHandler.add_custom_get_action(
            self.ACTION, CustomNavHandler.show_page)

        dom = self.parse_html_string(self.get('dashboard').body)
        selected_nav_path = ('.//tr[@class="gcb-nav-bar-level-1"]'
                             '//a[@class="selected"]')
        self.assertEquals('Outline', dom.find(selected_nav_path).text)
        dom = self.parse_html_string(self.get(self.URL).body)

        self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text)
        self.assertEquals(
            'MainContent', dom.find(self.CONTENT_PATH).text.strip())

        DashboardHandler.remove_custom_get_action(self.ACTION)

        # Add a new tab under the new navigation action
        class CustomTabHandler(object):

            @classmethod
            def display_html(cls, unused_dashboard_handler):
                return 'MainTabContent'

        tabs.Registry.register(
            self.ACTION, 'cu_tab', 'CustomTab', CustomTabHandler)
        DashboardHandler.add_custom_get_action(self.ACTION, None)
        dom = self.parse_html_string(self.get(self.URL).body)
        self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text)
        self.assertEquals(
            'MainTabContent', dom.find(self.CONTENT_PATH).text.strip())

        selected_tab_path = ('.//*[@class="gcb-nav-bar-level-2"]'
                             '//a[@class="selected"]')
        self.assertEquals('CustomTab', dom.find(selected_tab_path).text)
コード例 #9
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(self.ACCESS_COURSE_NAME,
                                            self.ADMIN_EMAIL,
                                            'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(
                None, {
                    'name': self.ROLE,
                    'users': [self.USER_EMAIL],
                    'permissions': {
                        dashboard.custom_module.name: [self.PERMISSION]
                    }
                })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(self.NO_ACCESS_COURSE_NAME,
                                            self.ADMIN_EMAIL,
                                            'Course with no access')

        self.course_without_access = courses.Course(None, context)

        def test_content(self):
            return self.render_page({
                'main_content': 'test',
                'page_title': 'test'
            })

        # save properties
        self.old_menu_group = DashboardHandler.root_menu_group
        # pylint: disable=W0212
        self.old_get_acitons = DashboardHandler._custom_get_actions
        # pylint: enable=W0212

        # put a dummy method in
        menu_group = menus.MenuGroup('test', 'Test Dashboard')
        DashboardHandler.root_menu_group = menu_group
        DashboardHandler.default_action = self.ACTION
        DashboardHandler.add_nav_mapping(self.ACTION, self.ACTION)
        DashboardHandler.add_sub_nav_mapping(self.ACTION,
                                             self.ACTION,
                                             self.ACTION,
                                             action=self.ACTION,
                                             contents=test_content)
        DashboardHandler.map_action_to_permission('get_%s' % self.ACTION,
                                                  self.PERMISSION)
        actions.logout()
コード例 #10
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        def test_content(self):
            return self.render_page(
                {'main_content': 'test', 'page_title': 'test'})

        # save properties
        self.old_menu_group = DashboardHandler.root_menu_group
        # pylint: disable=W0212
        self.old_get_acitons = DashboardHandler._custom_get_actions
        # pylint: enable=W0212

        # put a dummy method in
        menu_group = menus.MenuGroup('test', 'Test Dashboard')
        DashboardHandler.root_menu_group = menu_group
        DashboardHandler.default_action = self.ACTION
        DashboardHandler.add_nav_mapping(self.ACTION, self.ACTION)
        DashboardHandler.add_sub_nav_mapping(self.ACTION, self.ACTION,
            self.ACTION, action=self.ACTION, contents=test_content)
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()