feat: integrate cohort assignment filter definition to cohort model
This commit is contained in:
@@ -260,16 +260,17 @@
|
||||
|
||||
// Show error messages.
|
||||
this.undelegateViewEvents(this.errorNotifications);
|
||||
numErrors = modifiedUsers.unknown.length + modifiedUsers.invalid.length;
|
||||
numErrors = modifiedUsers.unknown.length + modifiedUsers.invalid.length + modifiedUsers.not_allowed.length;
|
||||
if (numErrors > 0) {
|
||||
createErrorDetails = function(unknownUsers, invalidEmails, showAllErrors) {
|
||||
createErrorDetails = function(unknownUsers, invalidEmails, notAllowed, showAllErrors) {
|
||||
var unknownErrorsShown = showAllErrors ? unknownUsers.length :
|
||||
Math.min(errorLimit, unknownUsers.length);
|
||||
var invalidErrorsShown = showAllErrors ? invalidEmails.length :
|
||||
Math.min(errorLimit - unknownUsers.length, invalidEmails.length);
|
||||
var notAllowedErrorsShown = showAllErrors ? notAllowed.length :
|
||||
Math.min(errorLimit - notAllowed.length, notAllowed.length);
|
||||
details = [];
|
||||
|
||||
|
||||
for (i = 0; i < unknownErrorsShown; i++) {
|
||||
details.push(interpolate_text(gettext('Unknown username: {user}'),
|
||||
{user: unknownUsers[i]}));
|
||||
@@ -278,6 +279,10 @@
|
||||
details.push(interpolate_text(gettext('Invalid email address: {email}'),
|
||||
{email: invalidEmails[i]}));
|
||||
}
|
||||
for (i = 0; i < notAllowedErrorsShown; i++) {
|
||||
details.push(interpolate_text(gettext('Cohort assignment not allowed: {email_or_username}'),
|
||||
{email_or_username: notAllowed[i]}));
|
||||
}
|
||||
return details;
|
||||
};
|
||||
|
||||
@@ -286,12 +291,12 @@
|
||||
'{numErrors} learners could not be added to this cohort:', numErrors),
|
||||
{numErrors: numErrors}
|
||||
);
|
||||
details = createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, false);
|
||||
details = createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, modifiedUsers.not_allowed, false);
|
||||
|
||||
errorActionCallback = function(view) {
|
||||
view.model.set('actionText', null);
|
||||
view.model.set('details',
|
||||
createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, true));
|
||||
createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, modifiedUsers.not_allowed, true));
|
||||
view.render();
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ define(['backbone', 'jquery', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers
|
||||
var catLoversInitialCount = 123,
|
||||
dogLoversInitialCount = 456,
|
||||
unknownUserMessage,
|
||||
notAllowedUserMessage,
|
||||
invalidEmailMessage, createMockCohort, createMockCohorts, createMockContentGroups,
|
||||
createMockCohortSettingsJson,
|
||||
createCohortsView, cohortsView, requests, respondToRefresh, verifyMessage, verifyNoMessage,
|
||||
@@ -210,6 +211,10 @@ define(['backbone', 'jquery', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers
|
||||
return 'Invalid email address: ' + name;
|
||||
};
|
||||
|
||||
notAllowedUserMessage = function(email) {
|
||||
return 'Cohort assignment not allowed: ' + email;
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
setFixtures('<ul class="instructor-nav">' +
|
||||
'<li class="nav-item"><button type="button" data-section="cohort_management" ' +
|
||||
@@ -602,7 +607,7 @@ define(['backbone', 'jquery', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers
|
||||
respondToAdd = function(result) {
|
||||
AjaxHelpers.respondWithJson(
|
||||
requests,
|
||||
_.extend({unknown: [], added: [], present: [], changed: [],
|
||||
_.extend({unknown: [], added: [], present: [], changed: [], not_allowed: [],
|
||||
success: true, preassigned: [], invalid: []}, result)
|
||||
);
|
||||
};
|
||||
@@ -670,6 +675,19 @@ define(['backbone', 'jquery', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers
|
||||
);
|
||||
});
|
||||
|
||||
it('shows an error when user assignment not allowed', function() {
|
||||
createCohortsView(this, {selectCohort: 1});
|
||||
addStudents('not_allowed');
|
||||
AjaxHelpers.expectRequest(
|
||||
requests, 'POST', '/mock_service/cohorts/1/add', 'users=not_allowed'
|
||||
);
|
||||
respondToAdd({not_allowed: ['not_allowed']});
|
||||
respondToRefresh(catLoversInitialCount, dogLoversInitialCount);
|
||||
verifyHeader(1, 'Cat Lovers', catLoversInitialCount);
|
||||
verifyDetailedMessage('There was an error when trying to add learners:', 'error',
|
||||
[notAllowedUserMessage('not_allowed')]
|
||||
);
|
||||
});
|
||||
|
||||
it('shows a "view all" button when more than 5 students do not exist', function() {
|
||||
var sixUsers = 'unknown1, unknown2, unknown3, unknown4, unknown5, unknown6';
|
||||
|
||||
Reference in New Issue
Block a user