Commit 9435f7c3 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: accept commission immediately after issue

Unify these operations when registering a pending application,
in order to make sure no commission can be left pending.
parent 1eb7f139
......@@ -69,7 +69,7 @@ from astakos.im.models import (
UserSetting,
get_resource_names, new_chain)
from astakos.im.quotas import (qh_sync_user, qh_sync_users,
register_pending_apps, resolve_pending_serial)
register_pending_apps)
from astakos.im.project_notif import (
membership_change_notify, membership_enroll_notify,
membership_request_notify, membership_leave_request_notify,
......@@ -78,7 +78,6 @@ from astakos.im.project_notif import (
project_termination_notify, project_suspension_notify)
from astakos.im import settings
import astakos.im.messages as astakos_messages
from astakos.quotaholder_app.exception import NoCapacityError
logger = logging.getLogger(__name__)
......@@ -940,21 +939,11 @@ def qh_add_pending_app(user, precursor=None, force=False, dry_run=False):
count = q.count()
diff = 1 - count
try:
name = "DRYRUN" if dry_run else ""
serial = register_pending_apps(user, diff, force, name=name)
except NoCapacityError as e:
limit = e.data['limit']
return False, limit
else:
accept = not dry_run
resolve_pending_serial(serial, accept=accept)
return True, None
return register_pending_apps(user, diff, force, dry_run)
def qh_release_pending_app(user):
serial = register_pending_apps(user, -1)
resolve_pending_serial(serial)
register_pending_apps(user, -1)
def qh_sync_projects(projects):
......
......@@ -35,6 +35,7 @@ from astakos.im.models import (
Resource, AstakosUserQuota, AstakosUser,
Project, ProjectMembership, ProjectResourceGrant, ProjectApplication)
import astakos.quotaholder_app.callpoint as qh
from astakos.quotaholder_app.exception import QuotaholderError, NoCapacityError
from django.db.models import Q
......@@ -133,14 +134,22 @@ def resolve_pending_serial(serial, accept=True):
return qh.resolve_pending_commission('astakos', serial, accept)
def register_pending_apps(user, quantity, force=False, name=""):
def register_pending_apps(user, quantity, force=False, dry_run=False):
provision = (user.uuid, SYSTEM, 'astakos.pending_app'), quantity
s = qh.issue_commission(clientkey='astakos',
force=force,
name=name,
provisions=[provision])
return s
name = "DRYRUN" if dry_run else ""
try:
s = qh.issue_commission(clientkey='astakos',
force=force,
name=name,
provisions=[provision])
except NoCapacityError as e:
limit = e.data['limit']
return False, limit
except QuotaholderError:
return False, None
accept = not dry_run
qh.resolve_pending_commission('astakos', s, accept)
return True, None
def initial_quotas(users):
......
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