Commit 62821c3e by Oleg Marshev

Merge pull request #4920 from edx/oleg/allow-one-group-in-configuration

Allow one group in a group configuration (BLD-1223)
parents c12535c5 7506a479
...@@ -1134,8 +1134,8 @@ class GroupConfiguration(object): ...@@ -1134,8 +1134,8 @@ class GroupConfiguration(object):
""" """
if not self.configuration.get("name"): if not self.configuration.get("name"):
raise GroupConfigurationsValidationError(_("must have name of the configuration")) raise GroupConfigurationsValidationError(_("must have name of the configuration"))
if len(self.configuration.get('groups', [])) < 2: if len(self.configuration.get('groups', [])) < 1:
raise GroupConfigurationsValidationError(_("must have at least two groups")) raise GroupConfigurationsValidationError(_("must have at least one group"))
def generate_id(self, used_ids): def generate_id(self, used_ids):
""" """
......
...@@ -121,13 +121,11 @@ class GroupConfigurationsBaseTestCase(object): ...@@ -121,13 +121,11 @@ class GroupConfigurationsBaseTestCase(object):
{u'name': u'Group B'}, {u'name': u'Group B'},
], ],
}, },
# must have at least two groups # must have at least one group
{ {
u'name': u'Test name', u'name': u'Test name',
u'description': u'Test description', u'description': u'Test description',
u'groups': [ u'groups': [],
{u'name': u'Group A'},
],
}, },
# an empty json # an empty json
{}, {},
......
...@@ -80,14 +80,14 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -80,14 +80,14 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
validate: function(attrs) { validate: function(attrs) {
if (!_.str.trim(attrs.name)) { if (!_.str.trim(attrs.name)) {
return { return {
message: gettext('Group Configuration name is required'), message: gettext('Group Configuration name is required.'),
attributes: {name: true} attributes: {name: true}
}; };
} }
if (attrs.groups.length < 2) { if (attrs.groups.length < 1) {
return { return {
message: gettext('There must be at least two groups'), message: gettext('There must be at least one group.'),
attributes: { groups: true } attributes: { groups: true }
}; };
} else { } else {
...@@ -100,7 +100,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -100,7 +100,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
}); });
if (!_.isEmpty(invalidGroups)) { if (!_.isEmpty(invalidGroups)) {
return { return {
message: gettext('All groups must have a name'), message: gettext('All groups must have a name.'),
attributes: { groups: invalidGroups } attributes: { groups: invalidGroups }
}; };
} }
......
...@@ -183,15 +183,14 @@ define([ ...@@ -183,15 +183,14 @@ define([
expect(model.isValid()).toBeTruthy(); 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' }), var group1 = new GroupModel({ name: 'Group A' }),
group2 = new GroupModel({ name: 'Group B' }),
model = new GroupConfigurationModel({ name: 'foo' }); model = new GroupConfigurationModel({ name: 'foo' });
model.get('groups').reset([group1]); model.get('groups').reset([]);
expect(model.isValid()).toBeFalsy(); expect(model.isValid()).toBeFalsy();
model.get('groups').add(group2); model.get('groups').add(group1);
expect(model.isValid()).toBeTruthy(); expect(model.isValid()).toBeTruthy();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment