Skip to content

Commit 4e2af12

Browse files
authored
Merge pull request code-dot-org#10292 from code-dot-org/lockableAuthorized
[axof: 234] Lockable authorized
2 parents 57efe94 + 43f2d45 commit 4e2af12

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

apps/src/code-studio/components/progress/ScriptTeacherPanel.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const ScriptTeacherPanel = React.createClass({
6363
).isRequired,
6464
selectedSection: React.PropTypes.string,
6565
sectionsLoaded: React.PropTypes.bool.isRequired,
66-
scriptHasLockedStages: React.PropTypes.bool.isRequired,
66+
scriptHasLockableStages: React.PropTypes.bool.isRequired,
6767
unlockedStageNames: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
6868
setViewType: React.PropTypes.func.isRequired,
6969
selectSection: React.PropTypes.func.isRequired,
@@ -80,7 +80,7 @@ const ScriptTeacherPanel = React.createClass({
8080
selectedSection,
8181
sectionsLoaded,
8282
setViewType,
83-
scriptHasLockedStages,
83+
scriptHasLockableStages,
8484
unlockedStageNames
8585
} = this.props;
8686
const hasSections = Object.keys(sections).length > 0;
@@ -90,7 +90,7 @@ const ScriptTeacherPanel = React.createClass({
9090
<div className="content">
9191
<ViewAsToggle viewAs={viewAs} setViewType={setViewType}/>
9292
{!sectionsLoaded && <div style={styles.text}>{commonMsg.loading()}</div>}
93-
{scriptHasLockedStages && hasSections &&
93+
{scriptHasLockableStages && hasSections &&
9494
<select
9595
name="sections"
9696
style={styles.select}
@@ -104,7 +104,7 @@ const ScriptTeacherPanel = React.createClass({
104104
))}
105105
</select>
106106
}
107-
{scriptHasLockedStages && hasSections && this.props.viewAs === ViewType.Teacher &&
107+
{scriptHasLockableStages && hasSections && this.props.viewAs === ViewType.Teacher &&
108108
<div>
109109
<div style={styles.text}>
110110
{commonMsg.selectSection()}
@@ -134,7 +134,7 @@ const ScriptTeacherPanel = React.createClass({
134134
});
135135

136136
export default connect((state, ownProps) => {
137-
const { viewAs, sections, selectedSection, sectionsLoaded } = state.stageLock;
137+
const { viewAs, sections, selectedSection, sectionsLoaded, lockableAuthorized } = state.stageLock;
138138
const currentSection = sections[selectedSection];
139139
const stages = currentSection ? currentSection.stages : {};
140140

@@ -149,14 +149,16 @@ export default connect((state, ownProps) => {
149149
stageNames[stage.id] = stage.name;
150150
});
151151

152-
const scriptHasLockedStages = state.progress.stages.some(stage => stage.lockable);
152+
// Pretend we don't have lockable stages if we're not authorized to see them
153+
const scriptHasLockableStages = lockableAuthorized &&
154+
state.progress.stages.some(stage => stage.lockable);
153155

154156
return {
155157
viewAs,
156158
sections,
157159
selectedSection,
158160
sectionsLoaded,
159-
scriptHasLockedStages,
161+
scriptHasLockableStages,
160162
unlockedStageNames: unlockedStageIds.map(id => stageNames[id])
161163
};
162164
}, dispatch => ({

apps/src/code-studio/components/progress/course_progress_row.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ const CourseProgressRow = React.createClass({
130130
export default connect(state => ({
131131
showTeacherInfo: state.progress.showTeacherInfo &&
132132
state.stageLock.viewAs !== ViewType.Student,
133-
lockableAuthorized: state.progress.lockableAuthorized,
133+
lockableAuthorized: state.stageLock.lockableAuthorized,
134134
changeFocusAreaPath: state.progress.changeFocusAreaPath,
135135
}))(Radium(CourseProgressRow));

apps/src/code-studio/progress.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
initProgress,
2222
mergeProgress,
2323
updateFocusArea,
24-
showTeacherInfo,
25-
authorizeLockable
24+
showTeacherInfo
2625
} from './progressRedux';
26+
import { authorizeLockable } from './stageLockRedux';
2727

2828
var progress = module.exports;
2929

apps/src/code-studio/progressRedux.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const INIT_PROGRESS = 'progress/INIT_PROGRESS';
1515
const MERGE_PROGRESS = 'progress/MERGE_PROGRESS';
1616
const UPDATE_FOCUS_AREAS = 'progress/UPDATE_FOCUS_AREAS';
1717
const SHOW_TEACHER_INFO = 'progress/SHOW_TEACHER_INFO';
18-
const AUTHORIZE_LOCKABLE = 'progress/AUTHORIZE_LOCKABLE';
1918

2019
const initialState = {
2120
currentLevelId: null,
@@ -28,8 +27,6 @@ const initialState = {
2827
peerReviewsRequired: {},
2928
peerReviewsPerformed: [],
3029
showTeacherInfo: false,
31-
// whether user is allowed to see lockable stages
32-
lockableAuthorized: false
3330
};
3431

3532
/**
@@ -90,12 +87,6 @@ export default function reducer(state = initialState, action) {
9087
});
9188
}
9289

93-
if (action.type === AUTHORIZE_LOCKABLE) {
94-
return Object.assign({}, state, {
95-
lockableAuthorized: true
96-
});
97-
}
98-
9990
return state;
10091
}
10192

@@ -157,11 +148,6 @@ export const updateFocusArea = (changeFocusAreaPath, focusAreaPositions) => ({
157148

158149
export const showTeacherInfo = () => ({ type: SHOW_TEACHER_INFO });
159150

160-
/**
161-
* Authorizes the user to be able to see lockable stages
162-
*/
163-
export const authorizeLockable = () => ({ type: AUTHORIZE_LOCKABLE });
164-
165151
/* start-test-block */
166152
// export private function(s) to expose to unit testing
167153
export const __testonly__ = {

apps/src/code-studio/stageLockRedux.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const OPEN_LOCK_DIALOG = 'stageLock/OPEN_LOCK_DIALOG';
1717
export const CLOSE_LOCK_DIALOG = 'stageLock/CLOSE_LOCK_DIALOG';
1818
export const BEGIN_SAVE = 'stageLock/BEGIN_SAVE';
1919
export const FINISH_SAVE = 'stageLock/FINISH_SAVE';
20+
const AUTHORIZE_LOCKABLE = 'progress/AUTHORIZE_LOCKABLE';
2021

2122
export const initialState = {
2223
viewAs: ViewType.Teacher,
@@ -26,13 +27,21 @@ export const initialState = {
2627
lockDialogStageId: null,
2728
// The locking info for the currently selected section/stage
2829
lockStatus: [],
29-
saving: false
30+
saving: false,
31+
// whether user is allowed to see lockable stages
32+
lockableAuthorized: false
3033
};
3134

3235
/**
3336
* Stage lock reducer
3437
*/
3538
export default function reducer(state = initialState, action) {
39+
if (action.type === AUTHORIZE_LOCKABLE) {
40+
return Object.assign({}, state, {
41+
lockableAuthorized: true
42+
});
43+
}
44+
3645
if (action.type === SET_VIEW_TYPE) {
3746
return Object.assign({}, state, {
3847
viewAs: action.viewAs
@@ -110,6 +119,12 @@ export default function reducer(state = initialState, action) {
110119
}
111120

112121
// Action creators
122+
123+
/**
124+
* Authorizes the user to be able to see lockable stages
125+
*/
126+
export const authorizeLockable = () => ({ type: AUTHORIZE_LOCKABLE });
127+
113128
export const setViewType = viewType => {
114129
if (!ViewType[viewType]) {
115130
throw new Error('unknown ViewType: ' + viewType);

0 commit comments

Comments
 (0)