Commit 14286a62 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou

astakos: Project modification validation improvements

- Always send limit on members number back to project modification api
  call (modified to unlimited otherwise)
- Validate that total limit is always equal or lower than members
  resource limit.
parent f1b34114
......@@ -845,6 +845,18 @@ class ProjectApplicationForm(forms.ModelForm):
raise forms.ValidationError("Resource %s does not exist" %
resource.name)
if is_project_limit:
member_limit = data.get(prefix + '_m_uplimit')
try:
pvalue = int(value)
mvalue = int(member_limit)
except:
raise forms.ValidationError("Invalid format")
if mvalue > pvalue:
msg = "%s per member limit exceeds total limit"
raise forms.ValidationError(msg % resource.name)
# keep only resource limits for selected resource groups
if data.get('is_selected_%s' % \
resource.group, "0") == "1":
......@@ -984,7 +996,8 @@ class ProjectApplicationForm(forms.ModelForm):
except AstakosUser.DoesNotExist:
pass
exclude_keys = ['owner', 'comments', 'project_id', 'start_date']
exclude_keys = ['owner', 'comments', 'project_id', 'start_date',
'limit_on_members_number']
# is_valid changes instance attributes
instance = self.instance
......
......@@ -893,6 +893,33 @@ class TestProjects(TestCase):
self.assertEqual(Project.objects.filter(is_base=False,
state=Project.O_ACTIVE).count(), 1)
# submit a modification
post_url = reverse('project_modify', args=(app1.chain.uuid,)) + '?verify=0&edit=1'
modification_data = {
'name': 'project.synnefo.org',
'homepage': 'https://www.synnefo.org',
'start_date': dfrom.strftime("%Y-%m-%d"),
'end_date': dto.strftime("%Y-%m-%d"),
'member_join_policy': 2,
'member_leave_policy': 1,
'limit_on_members_number_0': '5',
'service1.resource_m_uplimit': 300,
'service1.resource_p_uplimit': 100,
'is_selected_service1.resource': "1",
'user': self.user.pk
}
resp = self.user_client.post(post_url, modification_data)
self.assertEqual(resp.status_code, 200)
self.assertFalse(resp.context['form'].is_valid())
modification_data['service1.resource_m_uplimit'] = 3
post_url = reverse('project_modify', args=(app1.chain.uuid,)) + '?verify=0&edit=0'
resp = self.user_client.post(post_url, modification_data)
self.assertEqual(resp.status_code, 302)
app = ProjectApplication.objects.get(state=ProjectApplication.PENDING,
chain=app1.chain)
self.assertEqual(app.limit_on_members_number, 5)
# login
self.member_client.get(reverse("edit_profile"))
# cannot join project2 (not approved yet)
......
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