Merge pull request #4920 from edx/oleg/allow-one-group-in-configuration
Allow one group in a group configuration (BLD-1223)
This commit is contained in:
@@ -1134,8 +1134,8 @@ class GroupConfiguration(object):
|
||||
"""
|
||||
if not self.configuration.get("name"):
|
||||
raise GroupConfigurationsValidationError(_("must have name of the configuration"))
|
||||
if len(self.configuration.get('groups', [])) < 2:
|
||||
raise GroupConfigurationsValidationError(_("must have at least two groups"))
|
||||
if len(self.configuration.get('groups', [])) < 1:
|
||||
raise GroupConfigurationsValidationError(_("must have at least one group"))
|
||||
|
||||
def generate_id(self, used_ids):
|
||||
"""
|
||||
|
||||
@@ -121,13 +121,11 @@ class GroupConfigurationsBaseTestCase(object):
|
||||
{u'name': u'Group B'},
|
||||
],
|
||||
},
|
||||
# must have at least two groups
|
||||
# must have at least one group
|
||||
{
|
||||
u'name': u'Test name',
|
||||
u'description': u'Test description',
|
||||
u'groups': [
|
||||
{u'name': u'Group A'},
|
||||
],
|
||||
u'groups': [],
|
||||
},
|
||||
# an empty json
|
||||
{},
|
||||
|
||||
@@ -80,14 +80,14 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
|
||||
validate: function(attrs) {
|
||||
if (!_.str.trim(attrs.name)) {
|
||||
return {
|
||||
message: gettext('Group Configuration name is required'),
|
||||
message: gettext('Group Configuration name is required.'),
|
||||
attributes: {name: true}
|
||||
};
|
||||
}
|
||||
|
||||
if (attrs.groups.length < 2) {
|
||||
if (attrs.groups.length < 1) {
|
||||
return {
|
||||
message: gettext('There must be at least two groups'),
|
||||
message: gettext('There must be at least one group.'),
|
||||
attributes: { groups: true }
|
||||
};
|
||||
} else {
|
||||
@@ -100,7 +100,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
|
||||
});
|
||||
if (!_.isEmpty(invalidGroups)) {
|
||||
return {
|
||||
message: gettext('All groups must have a name'),
|
||||
message: gettext('All groups must have a name.'),
|
||||
attributes: { groups: invalidGroups }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -183,15 +183,14 @@ define([
|
||||
expect(model.isValid()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('requires at least two groups', function() {
|
||||
it('requires at least one group', function() {
|
||||
var group1 = new GroupModel({ name: 'Group A' }),
|
||||
group2 = new GroupModel({ name: 'Group B' }),
|
||||
model = new GroupConfigurationModel({ name: 'foo' });
|
||||
|
||||
model.get('groups').reset([group1]);
|
||||
model.get('groups').reset([]);
|
||||
expect(model.isValid()).toBeFalsy();
|
||||
|
||||
model.get('groups').add(group2);
|
||||
model.get('groups').add(group1);
|
||||
expect(model.isValid()).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user