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 astakos.im.models 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) &
~Q(policy=resource))
users = objs.select_for_update()
uuids = [u.uuid for u in users]
qh.add_resource_limit(holders=uuids, sources=[SYSTEM],
resources=[resource.name], diff=diff)
def qh_sync_new_resource(resource, limit):
users = AstakosUser.forupdate.filter(
email_verified=True).select_for_update()
resource_name = resource.name
data = []
for user in users:
uuid = user.uuid
key = uuid, SYSTEM, resource
key = uuid, SYSTEM, resource_name
data.append((key, limit))
qh.set_quota(data)
......@@ -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)
else:
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):
logger.info("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):
h.save()
holdings[key] = h
def add_resource_limit(self, source, resource, diff):
objs = Holding.objects.filter(source=source, resource=resource)
objs.update(limit=F('limit')+diff)
def add_resource_limit(self, holders=None, sources=None, resources=None,
diff=0):
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)
holdings.update(limit=F('limit')+diff)
def issue_commission(self,
context=None,
......
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