Commit 5adb33d2 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Handle quota for accepted users

A user is accepted if moderated=True and is_rejected=False. Only
accepted users have entries in the quotaholder.
parent faa67998
......@@ -113,7 +113,7 @@ class Command(SynnefoCommand):
if user_ident is not None:
users = [self.get_user(user_ident)]
else:
users = AstakosUser.objects.moderated()
users = AstakosUser.objects.accepted()
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.moderated:
raise CommandError('%s is not an accepted user.\n' % user.uuid)
if not user.is_accepted():
raise CommandError('%s is not an accepted user.' % user.uuid)
return user
......
......@@ -82,12 +82,15 @@ class Command(BaseCommand):
qh_holdings = service_get_quotas(astakos, query)
if userid is None:
users = AstakosUser.objects.moderated()
users = AstakosUser.objects.accepted()
else:
try:
users = [AstakosUser.objects.get(uuid=userid)]
user = AstakosUser.objects.get(uuid=userid)
except AstakosUser.DoesNotExist:
raise CommandError("There is no user with uuid '%s'." % userid)
if not user.is_accepted():
raise CommandError("%s is not an accepted user." % userid)
users = [user]
db_holdings = count_pending_app(users)
......
......@@ -315,8 +315,8 @@ class AstakosUserManager(UserManager):
def verified(self):
return self.filter(email_verified=True)
def moderated(self):
return self.filter(moderated=True)
def accepted(self):
return self.filter(moderated=True, is_rejected=False)
def uuid_catalog(self, l=None):
"""
......@@ -482,6 +482,9 @@ class AstakosUser(User):
group, _ = Group.objects.get_or_create(name=gname)
self.groups.add(group)
def is_accepted(self):
return self.moderated and not self.is_rejected
def is_project_admin(self, application_id=None):
return self.uuid in astakos_settings.PROJECT_ADMINS
......
......@@ -316,8 +316,8 @@ def qh_sync_project(project):
def qh_add_resource_limit(resource, diff):
objs = AstakosUser.forupdate.filter(Q(moderated=True) &
~Q(policy=resource))
objs = AstakosUser.forupdate.filter(
Q(moderated=True, is_rejected=False) & ~Q(policy=resource))
users = objs.order_by('id').select_for_update()
uuids = [u.uuid for u in users]
qh.add_resource_limit(holders=uuids, sources=[SYSTEM],
......@@ -326,7 +326,7 @@ def qh_add_resource_limit(resource, diff):
def qh_sync_new_resource(resource, limit):
users = AstakosUser.forupdate.filter(
moderated=True).order_by('id').select_for_update()
moderated=True, is_rejected=False).order_by('id').select_for_update()
resource_name = resource.name
data = []
......
......@@ -74,7 +74,11 @@ class QuotaAPITest(TestCase):
# create user
user = get_local_user('test@grnet.gr')
backend.accept_user(user)
non_moderated_user = get_local_user('nonmon@example.com')
non_moderated_user = get_local_user('nonmon@example.com',
is_active=False)
r_user = get_local_user('rej@example.com',
is_active=False, email_verified=True)
backend.reject_user(r_user, "reason")
component2 = Component.objects.create(name="comp2")
register.add_service(component2, "service2", "type2", [])
......@@ -112,9 +116,13 @@ class QuotaAPITest(TestCase):
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, {})
self.assertEqual(r.status_code, 401)
q = quotas.get_user_quotas(non_moderated_user)
self.assertEqual(q, {})
q = quotas.get_user_quotas(r_user)
self.assertEqual(q, {})
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