don't offer to create planner notes in teacher contexts

test plan:
 - be a student and a teacher in different courses
 - on the calendar, create a planner note ("My To Do" tab)
 - courses you teach should not appear in the list of courses
   the note can be associated with
 - hit the + button on the planner dashboard
 - the "Optional: Add Course" dropdown shouldn't list the
   course you teach

fixes ADMIN-1372

Change-Id: I0efbc659f19da98ced17376f60618cbf018b0a66
Reviewed-on: https://gerrit.instructure.com/165360
Tested-by: Jenkins
Reviewed-by: Jon Willesen <jonw+gerrit@instructure.com>
QA-Review: Jon Willesen <jonw+gerrit@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2018-09-21 09:07:01 -06:00
parent 46efeddd17
commit 4bb7a9c3ae
8 changed files with 46 additions and 19 deletions

View File

@ -42,7 +42,15 @@ export default class EditPlannerNoteDetails extends ValidatedFormView {
constructor(selector, event, contextChangeCB, closeCB) {
super({
title: event.title,
contexts: event.possibleContexts(),
contexts: event.possibleContexts().filter((context) =>
// to avoid confusion over the audience of the planner note,
// don't offer to create new planner notes linked to courses the user teaches
context && context.asset_string && (
context.asset_string === event.contextCode() ||
context.asset_string.startsWith('user_') ||
ENV.CALENDAR.MANAGE_CONTEXTS.indexOf(context.asset_string) < 0
)
),
date: event.startDate(),
details: htmlEscape(event.description)
})

View File

@ -38,6 +38,7 @@ class CourseForMenuPresenter
href: course_path(course, invitation: course.read_attribute(:invitation)),
term: term || nil,
subtitle: subtitle,
enrollmentType: course.primary_enrollment_type,
id: course.id,
image: course.feature_enabled?(:course_card_images) ? course.image : nil,
position: @context&.feature_enabled?(:dashcard_reordering) ? @user.dashboard_positions[course.asset_string] : nil,

View File

@ -2,7 +2,7 @@
<ul class="tab_list">
<li><a href="#edit_calendar_event_form_holder" class="edit_calendar_event_option">{{#t "tabs.event"}}Event{{/t}}</a></li>
<li><a href="#edit_assignment_form_holder" class="edit_assignment_option">{{#t "tabs.assignment"}}Assignment{{/t}}</a></li>
<li><a href="#edit_planner_note_form_holder" class="edit_planner_note_option">{{#t "tabs.todo"}}To Do{{/t}}</a></li>
<li><a href="#edit_planner_note_form_holder" class="edit_planner_note_option">{{#t "tabs.todo"}}My To Do{{/t}}</a></li>
<li><a href="#edit_todo_item_form_holder" class="edit_todo_item_option">--</a></li>
{{#if showAppointments}}
<li><a href="#edit_appointment_group_form_holder" class="edit_appointment_group_option">{{#t "tabs.appointment_group"}}Appointment Group{{/t}}</a></li>

View File

@ -36,7 +36,7 @@ it('renders some course grades', () => {
it('does not render caveat if no courses have grading periods', () => {
const mockCourses = [
{id: '1', shortName: 'Ticket to Ride 101', color: 'blue', href: '/courses/1',
score: null, grade: null, hasGradingPeriods: false},
score: null, grade: null, hasGradingPeriods: false, enrollmentType: 'StudentEnrollment'},
];
const wrapper = shallow(<GradesDisplay courses={mockCourses} />);
expect(wrapper).toMatchSnapshot();

View File

@ -46,7 +46,7 @@ it('renders the item to update if provided', () => {
const wrapper = shallow(
<UpdateItemTray {...defaultProps}
noteItem={noteItem}
courses={[{id: '1', longName: 'a course'}]} />
courses={[{id: '1', longName: 'a course', enrollmentType: 'StudentEnrollment'}, {id: '2', longName: 'a course I teach', enrollmentType: 'TeacherEnrollment'}]} />
);
expect(wrapper).toMatchSnapshot();
});
@ -206,8 +206,8 @@ it('updates state when new note is passed in', () => {
details: "You made this item to remind you of something, but you forgot what."
});
const wrapper = shallow(<UpdateItemTray {...defaultProps} noteItem={noteItem1} courses={[
{id: '1', longName: 'first course'},
{id: '2', longName: 'second course'},
{id: '1', longName: 'first course', enrollmentType: 'StudentEnrollment'},
{id: '2', longName: 'second course', enrollmentType: 'StudentEnrollment'},
]}/>);
expect(wrapper).toMatchSnapshot();
@ -257,8 +257,8 @@ it('renders just an optional option when no courses', () => {
it('renders course options plus an optional option when provided with courses', () => {
const wrapper = shallow(<UpdateItemTray {...defaultProps} courses={[
{id: '1', longName: 'first course'},
{id: '2', longName: 'second course'},
{id: '1', longName: 'first course', enrollmentType: 'StudentEnrollment'},
{id: '2', longName: 'second course', enrollmentType: 'StudentEnrollment'},
]} />);
expect(wrapper.find('option')).toHaveLength(3);
});
@ -269,7 +269,7 @@ it('invokes save callback with updated data', () => {
noteItem={{
uniqueId: "1", title: 'title', date: moment('2017-04-27T13:00:00Z'), courseId: '42', details: 'details',
}}
courses={[{id: '42', longName: 'first'}, {id: '43', longName: 'second'}]}
courses={[{id: '42', longName: 'first', enrollmentType: 'StudentEnrollment'}, {id: '43', longName: 'second', enrollmentType: 'StudentEnrollment'}]}
onSavePlannerItem={saveMock}
/>);
wrapper.instance().handleTitleChange({target: {value: 'new title'}});

View File

@ -224,10 +224,12 @@ export class UpdateItemTray extends Component {
value: "none",
label: formatMessage("Optional: Add Course")
}
const courseOptions = (this.props.courses || []).map(course => ({
value: course.id,
label: course.longName
}))
const courseOptions = (this.props.courses || []).
filter(course => course.enrollmentType === 'StudentEnrollment').
map(course => ({
value: course.id,
label: course.longName
}))
const courseId = this.findCurrentValue('courseId');
const selectedOption = courseId

View File

@ -34,6 +34,7 @@ export const badgeShape = {
export const courseShape = {
id: PropTypes.string,
longName: PropTypes.string,
enrollmentType: PropTypes.string
};
export const itemShape = {

View File

@ -53,7 +53,7 @@ describe "calendar2" do
get '/calendar2'
wait_for_ajax_requests
f('.fc-week td').click # click the first day of the month
f('li[aria-controls="edit_planner_note_form_holder"]').click # the To Do tab
f('li[aria-controls="edit_planner_note_form_holder"]').click # the My To Do tab
replace_content(f('#planner_note_date'), 0.days.from_now.to_date.iso8601)
replace_content(f('#planner_note_title'), title)
f('button.save_note').click
@ -215,12 +215,18 @@ describe "calendar2" do
end
context "with teacher and student enrollments" do
it "includes todo items from both" do
course1 = @course
course2 = course_with_student(user: @user, active_all: true).course
page1 = course1.wiki_pages.create!(title: 'Page1', todo_date: Date.today, workflow_state: 'unpublished')
page2 = course2.wiki_pages.create!(title: 'Page2', todo_date: Date.today, workflow_state: 'published')
before :once do
@course1 = @course
@course2 = course_with_student(user: @user, active_all: true).course
end
before :each do
user_session(@user)
end
it "includes todo items from both" do
page1 = @course1.wiki_pages.create!(title: 'Page1', todo_date: Date.today, workflow_state: 'unpublished')
page2 = @course2.wiki_pages.create!(title: 'Page2', todo_date: Date.today, workflow_state: 'published')
get '/calendar2'
wait_for_ajax_requests
fj('.fc-title:contains("Page1")').click
@ -228,5 +234,14 @@ describe "calendar2" do
fj('.fc-title:contains("Page2")').click
expect(f('.event-details')).not_to contain_css('.edit_event_link')
end
it "only offers user and student contexts for planner notes" do
get '/calendar2'
wait_for_ajax_requests
f('.fc-week td').click # click the first day of the month
f('li[aria-controls="edit_planner_note_form_holder"]').click # the My To Do tab
context_codes = ff('#planner_note_context option').map { |el| el['value'] }
expect(context_codes).to match_array([@user.asset_string, @course2.asset_string])
end
end
end