Commit f005b537 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Handle quota for moderated users only

At some points, verified users where mistakenly assumed.
parent c6897b40
......@@ -113,7 +113,7 @@ class Command(SynnefoCommand):
if user_ident is not None:
users = [self.get_user(user_ident)]
else:
users = AstakosUser.objects.verified()
users = AstakosUser.objects.moderated()
if list_only:
qh_quotas, astakos_i = list_user_quotas(users)
......@@ -150,8 +150,8 @@ class Command(SynnefoCommand):
else:
raise CommandError('Please specify user by uuid or email')
if not user.email_verified:
raise CommandError('%s is not a verified user.\n' % user.uuid)
if not user.moderated:
raise CommandError('%s is not an accepted user.\n' % user.uuid)
return user
......
......@@ -82,7 +82,7 @@ class Command(BaseCommand):
qh_holdings = service_get_quotas(astakos, query)
if userid is None:
users = AstakosUser.objects.verified()
users = AstakosUser.objects.moderated()
else:
try:
users = [AstakosUser.objects.get(uuid=userid)]
......
......@@ -315,6 +315,9 @@ class AstakosUserManager(UserManager):
def verified(self):
return self.filter(email_verified=True)
def moderated(self):
return self.filter(moderated=True)
def uuid_catalog(self, l=None):
"""
Returns a uuid to username mapping for the uuids appearing in l.
......
......@@ -316,7 +316,7 @@ def qh_sync_project(project):
def qh_add_resource_limit(resource, diff):
objs = AstakosUser.forupdate.filter(Q(email_verified=True) &
objs = AstakosUser.forupdate.filter(Q(moderated=True) &
~Q(policy=resource))
users = objs.order_by('id').select_for_update()
uuids = [u.uuid for u in users]
......@@ -326,7 +326,7 @@ def qh_add_resource_limit(resource, diff):
def qh_sync_new_resource(resource, limit):
users = AstakosUser.forupdate.filter(
email_verified=True).order_by('id').select_for_update()
moderated=True).order_by('id').select_for_update()
resource_name = resource.name
data = []
......
......@@ -51,6 +51,7 @@ u = lambda url: ROOT + url
class QuotaAPITest(TestCase):
def test_0(self):
client = Client()
backend = activation_backends.get_backend()
component1 = Component.objects.create(name="comp1")
register.add_service(component1, "service1", "type1", [])
......@@ -72,7 +73,8 @@ class QuotaAPITest(TestCase):
# create user
user = get_local_user('test@grnet.gr')
quotas.qh_sync_user(user)
backend.accept_user(user)
non_moderated_user = get_local_user('nonmon@example.com')
component2 = Component.objects.create(name="comp2")
register.add_service(component2, "service2", "type2", [])
......@@ -108,6 +110,12 @@ class QuotaAPITest(TestCase):
for name in resource_names:
assertIn(name, system_quota)
nmheaders = {'HTTP_X_AUTH_TOKEN': non_moderated_user.auth_token}
r = client.get(u('quotas/'), **nmheaders)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
self.assertEqual(body, {})
r = client.get(u('service_quotas'))
self.assertEqual(r.status_code, 401)
......
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