Only show option to re-enable C4E dashboard if in a C4E account
refs LS-2121 flag = none Test plan: - Go to the dashboard of a teacher or admin associated with a C4E account - Click the menu in the upper-right and choose "Classic View" to disable the C4E dashbaord for this user - Expect the page to reload and the Classic dashboard to display - Click the menu in the upper-right and expect to see "Elementary View" as on option (but don't click it) - Disable the C4E account setting(s) so that C4E no longer applies to your user - Reload the page, and expect the "Elementary View" option to no longer be present in the upper-right menu Change-Id: I18b8a3554556ab46997e64b7969487904f99340b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/266748 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Eric Saupe <eric.saupe@instructure.com> QA-Review: Eric Saupe <eric.saupe@instructure.com> Product-Review: Peyton Craighill <pcraighill@instructure.com>
This commit is contained in:
parent
5136d5b171
commit
38b55f99e4
|
@ -2832,9 +2832,9 @@ class ApplicationController < ActionController::Base
|
|||
can_disable && @current_user.elementary_dashboard_disabled?
|
||||
end
|
||||
|
||||
def k5_user?
|
||||
def k5_user?(check_disabled = true)
|
||||
if @current_user
|
||||
return false if k5_disabled?
|
||||
return false if check_disabled && k5_disabled?
|
||||
# This key is also invalidated when the k5 setting is toggled at the account level or when enrollments change
|
||||
Rails.cache.fetch_with_batched_keys(["k5_user", Shard.current].cache_key, batch_object: @current_user, batched_keys: [:k5_user], expires_in: 1.hour) do
|
||||
uncached_k5_user?
|
||||
|
|
|
@ -484,15 +484,16 @@ class UsersController < ApplicationController
|
|||
|
||||
# Reload user settings so we don't get a stale value for K5_USER when switching dashboards
|
||||
@current_user.reload
|
||||
js_env({K5_USER: k5_user?}, true)
|
||||
k5_disabled = k5_disabled?
|
||||
k5_user = k5_user?(false)
|
||||
js_env({K5_USER: k5_user && !k5_disabled}, true)
|
||||
|
||||
js_env({
|
||||
:DASHBOARD_SIDEBAR_URL => dashboard_sidebar_url,
|
||||
:PREFERENCES => {
|
||||
:dashboard_view => @current_user.dashboard_view(@domain_root_account),
|
||||
:hide_dashcard_color_overlays => @current_user.preferences[:hide_dashcard_color_overlays],
|
||||
:custom_colors => @current_user.custom_colors,
|
||||
:elementary_dashboard_disabled => k5_disabled?
|
||||
:custom_colors => @current_user.custom_colors
|
||||
},
|
||||
:STUDENT_PLANNER_ENABLED => planner_enabled?,
|
||||
:STUDENT_PLANNER_COURSES => planner_enabled? && map_courses_for_menu(@current_user.courses_with_primary_enrollment),
|
||||
|
@ -502,6 +503,7 @@ class UsersController < ApplicationController
|
|||
:create_courses_as_admin => @current_user.roles(@domain_root_account).include?('admin'),
|
||||
:create_courses_as_teacher => @domain_root_account.grants_right?(@current_user, session, :create_courses)
|
||||
},
|
||||
:CAN_ENABLE_K5_DASHBOARD => k5_disabled && k5_user
|
||||
})
|
||||
|
||||
@announcements = AccountNotification.for_user_and_account(@current_user, @domain_root_account)
|
||||
|
|
|
@ -2087,6 +2087,14 @@ describe ApplicationController do
|
|||
expect(@controller.send(:k5_user?)).to be_falsey
|
||||
end
|
||||
|
||||
it "ignores the disabled preference if check_disabled = false" do
|
||||
@teacher.preferences[:elementary_dashboard_disabled] = true
|
||||
@teacher.save!
|
||||
user_session(@teacher)
|
||||
@controller.instance_variable_set(:@current_user, @teacher)
|
||||
expect(@controller.send(:k5_user?, false)).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true even if a student has opted-out of the k5 dashboard" do
|
||||
@student.preferences[:elementary_dashboard_disabled] = true
|
||||
@student.save!
|
||||
|
|
|
@ -24,7 +24,7 @@ import moxios from 'moxios'
|
|||
import {moxiosWait} from 'jest-moxios-utils'
|
||||
import sinon from 'sinon'
|
||||
import $ from 'jquery'
|
||||
import {DashboardHeader} from 'ui/features/dashboard/react/DashboardHeader.js'
|
||||
import {DashboardHeader} from 'ui/features/dashboard/react/DashboardHeader'
|
||||
import {resetPlanner} from '@instructure/canvas-planner'
|
||||
|
||||
const container = document.getElementById('fixtures')
|
||||
|
@ -309,7 +309,7 @@ test('it should allow switching back to the Elementary dashboard if it was disab
|
|||
dashboardHeader = c
|
||||
}}
|
||||
dashboard_view="activity"
|
||||
elementaryDashboardDisabled
|
||||
canEnableElementaryDashboard
|
||||
/>,
|
||||
container
|
||||
)
|
||||
|
|
|
@ -21,7 +21,7 @@ import PropTypes from 'prop-types'
|
|||
import ReactDOM from 'react-dom'
|
||||
import TestUtils from 'react-dom/test-utils'
|
||||
import {shallow, mount} from 'enzyme'
|
||||
import DashboardOptionsMenu from 'ui/features/dashboard/react/DashboardOptionsMenu.js'
|
||||
import DashboardOptionsMenu from 'ui/features/dashboard/react/DashboardOptionsMenu'
|
||||
import sinon from 'sinon'
|
||||
|
||||
const container = document.getElementById('fixtures')
|
||||
|
@ -122,7 +122,7 @@ test('it should include a List View menu item when Student Planner is enabled',
|
|||
|
||||
test('it should include an Elementary View option when the Elementary dashboard is disabled', () => {
|
||||
const wrapper = mount(
|
||||
<DashboardOptionsMenu elementaryDashboardDisabled onDashboardChange={() => {}} />
|
||||
<DashboardOptionsMenu canEnableElementaryDashboard onDashboardChange={() => {}} />
|
||||
)
|
||||
wrapper.find('button').simulate('click')
|
||||
const menuItems = Array.from(document.querySelectorAll('[role="menuitemradio"]'))
|
||||
|
|
|
@ -52,10 +52,10 @@ describe "admin k5 dashboard" do
|
|||
|
||||
options = dashboard_options
|
||||
expect(options.length).to be 2
|
||||
expect(options[0].text).to eq('Elementary View')
|
||||
expect(options[1].text).to eq('Classic View')
|
||||
expect(options[0].text).to eq('Classic View')
|
||||
expect(options[1].text).to eq('Elementary View')
|
||||
|
||||
options[1].click
|
||||
options[0].click
|
||||
wait_for_ajaximations
|
||||
|
||||
expect(classic_dashboard_header).to be_displayed
|
||||
|
|
|
@ -32,7 +32,8 @@ ready(() => {
|
|||
ReactDOM.render(
|
||||
<DashboardHeader
|
||||
dashboard_view={dashboard_view}
|
||||
elementaryDashboardDisabled={!!ENV.PREFERENCES?.elementary_dashboard_disabled}
|
||||
canEnableElementaryDashboard={!!ENV.CAN_ENABLE_K5_DASHBOARD}
|
||||
isElementaryUser={!!ENV.K5_USER}
|
||||
planner_enabled={ENV.STUDENT_PLANNER_ENABLED}
|
||||
flashError={$.flashError}
|
||||
flashMessage={$.flashMessage}
|
||||
|
|
|
@ -48,7 +48,7 @@ class DashboardHeader extends React.Component {
|
|||
dashboard_view: string,
|
||||
planner_enabled: bool.isRequired,
|
||||
screenReaderFlashMessage: func,
|
||||
elementaryDashboardDisabled: bool,
|
||||
canEnableElementaryDashboard: bool,
|
||||
env: object,
|
||||
showTodoList: func,
|
||||
responsiveSize: oneOf(['small', 'medium', 'large'])
|
||||
|
@ -232,7 +232,7 @@ class DashboardHeader extends React.Component {
|
|||
menuButtonRef={ref => {
|
||||
this.menuButtonFocusable = ref
|
||||
}}
|
||||
elementaryDashboardDisabled={this.props.elementaryDashboardDisabled}
|
||||
canEnableElementaryDashboard={this.props.canEnableElementaryDashboard}
|
||||
/>
|
||||
</div>
|
||||
{this.props.planner_enabled && <div id="dashboard-planner-header-aux" />}
|
||||
|
|
|
@ -32,14 +32,14 @@ export default class DashboardOptionsMenu extends React.Component {
|
|||
planner_enabled: PropTypes.bool,
|
||||
onDashboardChange: PropTypes.func.isRequired,
|
||||
menuButtonRef: PropTypes.func,
|
||||
elementaryDashboardDisabled: PropTypes.bool
|
||||
canEnableElementaryDashboard: PropTypes.bool
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
planner_enabled: false,
|
||||
view: 'cards',
|
||||
menuButtonRef: () => {},
|
||||
elementaryDashboardDisabled: false
|
||||
canEnableElementaryDashboard: false
|
||||
}
|
||||
|
||||
state = {
|
||||
|
@ -99,7 +99,7 @@ export default class DashboardOptionsMenu extends React.Component {
|
|||
<Menu.Item value="planner">{I18n.t('List View')}</Menu.Item>
|
||||
)}
|
||||
<Menu.Item value="activity">{I18n.t('Recent Activity')}</Menu.Item>
|
||||
{this.props.elementaryDashboardDisabled && (
|
||||
{this.props.canEnableElementaryDashboard && (
|
||||
<Menu.Item value="elementary">{I18n.t('Elementary View')}</Menu.Item>
|
||||
)}
|
||||
</Menu.Group>
|
||||
|
|
|
@ -99,8 +99,8 @@ const K5DashboardOptionsMenu = ({onDisableK5Dashboard}) => {
|
|||
onSelect={onDisableK5Dashboard}
|
||||
selected={['elementary']}
|
||||
>
|
||||
<Menu.Item value="elementary">{I18n.t('Elementary View')}</Menu.Item>
|
||||
<Menu.Item value="classic">{I18n.t('Classic View')}</Menu.Item>
|
||||
<Menu.Item value="elementary">{I18n.t('Elementary View')}</Menu.Item>
|
||||
</Menu.Group>
|
||||
</Menu>
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue