Revision 44104cd3

b/snf-astakos-app/astakos/im/functions.py
71 71
    AstakosUser, Invitation, ProjectMembership, ProjectApplication, Project,
72 72
    UserSetting,
73 73
    get_resource_names, new_chain)
74
from astakos.im.quotas import users_quotas, set_user_quota
74
from astakos.im.quotas import qh_sync_user, qh_sync_users
75 75
from astakos.im.project_notif import (
76 76
    membership_change_notify, membership_enroll_notify,
77 77
    membership_request_notify, membership_leave_request_notify,
......
295 295
    if not user.activation_sent:
296 296
        user.activation_sent = datetime.now()
297 297
    user.save()
298
    qh_sync([user.id])
298
    qh_sync_user(user.id)
299 299
    send_helpdesk_notification(user, helpdesk_email_template_name)
300 300
    send_greeting(user, email_template_name)
301 301

  
......
519 519
        raise PermissionDenied(m)
520 520

  
521 521
    membership.accept()
522
    qh_sync([user])
522
    qh_sync_user(user)
523 523
    logger.info("User %s has been accepted in %s." %
524 524
                (membership.person.log_display, project))
525 525

  
......
579 579
        raise PermissionDenied(m)
580 580

  
581 581
    membership.remove()
582
    qh_sync([user])
582
    qh_sync_user(user)
583 583
    logger.info("User %s has been removed from %s." %
584 584
                (membership.person.log_display, project))
585 585

  
......
597 597
        raise PermissionDenied(m)
598 598

  
599 599
    membership.accept()
600
    qh_sync([user])
600
    qh_sync_user(user)
601 601
    logger.info("User %s has been enrolled in %s." %
602 602
                (membership.person.log_display, project))
603 603

  
......
635 635
    leave_policy = project.application.member_leave_policy
636 636
    if leave_policy == AUTO_ACCEPT_POLICY:
637 637
        membership.remove()
638
        qh_sync([user_id])
638
        qh_sync_user(user_id)
639 639
        logger.info("User %s has left %s." %
640 640
                    (membership.person.log_display, project))
641 641
        auto_accepted = True
......
672 672
    if (join_policy == AUTO_ACCEPT_POLICY and
673 673
        not project.violates_members_limit(adding=1)):
674 674
        membership.accept()
675
        qh_sync([user_id])
675
        qh_sync_user(user_id)
676 676
        logger.info("User %s joined %s." %
677 677
                    (membership.person.log_display, project))
678 678
        auto_accepted = True
......
912 912
    memberships = ProjectMembership.objects.filter(project__in=projects)
913 913
    user_ids = set(m.person_id for m in memberships)
914 914

  
915
    qh_sync(user_ids)
916

  
917

  
918
def qh_sync(user_ids):
919
    users = AstakosUser.forupdate.filter(id__in=user_ids).select_for_update()
920
    astakos_quotas = users_quotas(list(users))
921
    set_user_quota(astakos_quotas)
922

  
923

  
924
def qh_sync_all_users():
925
    users = AstakosUser.forupdate.filter(
926
        email_verified=True).select_for_update()
927
    astakos_quotas = users_quotas(list(users))
928
    set_user_quota(astakos_quotas)
915
    qh_sync_users(user_ids)
b/snf-astakos-app/astakos/im/management/commands/user-set-initial-quota.py
43 43

  
44 44
from snf_django.lib.db.transaction import commit_on_success_strict
45 45
from astakos.im.models import AstakosUser, AstakosUserQuota, Resource
46
from astakos.im.functions import qh_sync
46
from astakos.im.quotas import qh_sync_user
47 47

  
48 48
AddResourceArgs = namedtuple('AddQuotaArgs', ('resource',
49 49
                                              'capacity',
......
168 168
                user.add_resource_policy(*args)
169 169
            except Exception as e:
170 170
                raise CommandError("Failed to add policy: %s" % e)
171
        qh_sync([user.id])
171
        qh_sync_user(user.id)
172 172

  
173 173
    def import_from_file(self, location):
174 174
        try:
b/snf-astakos-app/astakos/im/quotas.py
253 253
        data.append((key, limit))
254 254

  
255 255
    qh.set_quota(data)
256

  
257

  
258
def qh_sync_users(user_ids):
259
    users = AstakosUser.forupdate.filter(id__in=user_ids).select_for_update()
260
    astakos_quotas = users_quotas(list(users))
261
    set_user_quota(astakos_quotas)
262

  
263

  
264
def qh_sync_user(user_id):
265
    qh_sync_users([user_id])
b/snf-astakos-app/astakos/im/resources.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from astakos.im.models import Service, Resource
35
from astakos.im.functions import qh_sync_all_users
36 35
from astakos.im.quotas import qh_add_resource_limit, qh_sync_new_resource
37 36
import logging
38 37

  

Also available in: Unified diff