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

Respect user-specific quota when changing resource default

Do not update holding limit if there exist user-specific base quota
for the particular resource.
parent 357c3f0d
......@@ -35,6 +35,7 @@ from import (
Resource, AstakosUserQuota, AstakosUser,
Project, ProjectMembership, ProjectResourceGrant, ProjectApplication)
from astakos.quotaholder.callpoint import QuotaholderDjangoDBCallpoint
from django.db.models import Q
qh = QuotaholderDjangoDBCallpoint()
......@@ -248,18 +249,23 @@ def sync_all_users(sync=True):
def qh_add_resource_limit(resource, diff):
users = AstakosUser.forupdate.all().select_for_update()
qh.add_resource_limit(SYSTEM, resource, diff)
objs = AstakosUser.forupdate.filter(Q(email_verified=True) &
users = objs.select_for_update()
uuids = [u.uuid for u in users]
qh.add_resource_limit(holders=uuids, sources=[SYSTEM],
resources=[], diff=diff)
def qh_sync_new_resource(resource, limit):
users = AstakosUser.forupdate.filter(
resource_name =
data = []
for user in users:
uuid = user.uuid
key = uuid, SYSTEM, resource
key = uuid, SYSTEM, resource_name
data.append((key, limit))
......@@ -68,9 +68,9 @@ def add_resource(service, resource, uplimit):
if old_uplimit is not None:
diff = uplimit - old_uplimit
if diff != 0:
qh_add_resource_limit(name, diff)
qh_add_resource_limit(r, diff)
qh_sync_new_resource(name, uplimit)
qh_sync_new_resource(r, uplimit)
def update_resource(name, uplimit):
......@@ -82,4 +82,4 @@ def update_resource(name, uplimit):"Updated resource %s with limit %s." % (name, uplimit))
diff = uplimit - old_uplimit
if diff != 0:
qh_add_resource_limit(name, diff)
qh_add_resource_limit(r, diff)
......@@ -135,9 +135,20 @@ class QuotaholderDjangoDBCallpoint(object):
holdings[key] = h
def add_resource_limit(self, source, resource, diff):
objs = Holding.objects.filter(source=source, resource=resource)
def add_resource_limit(self, holders=None, sources=None, resources=None,
holdings = Holding.objects.all()
if holders is not None:
holdings = holdings.filter(holder__in=holders)
if sources is not None:
holdings = holdings.filter(source__in=sources)
if resources is not None:
holdings = holdings.filter(resource__in=resources)
def issue_commission(self,
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