Revision 8cbea11d
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 |
|
74 |
from astakos.im.quotas import users_quotas, set_user_quota
|
|
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, |
... | ... | |
297 | 297 |
if not user.activation_sent: |
298 | 298 |
user.activation_sent = datetime.now() |
299 | 299 |
user.save() |
300 |
register_user_quotas(user)
|
|
300 |
qh_sync([user.id])
|
|
301 | 301 |
send_helpdesk_notification(user, helpdesk_email_template_name) |
302 | 302 |
send_greeting(user, email_template_name) |
303 | 303 |
|
... | ... | |
375 | 375 |
super(SendNotificationError, self).__init__() |
376 | 376 |
|
377 | 377 |
|
378 |
def register_user_quotas(user): |
|
379 |
quotas = users_quotas([user]) |
|
380 |
register_quotas(quotas) |
|
381 |
|
|
382 |
|
|
383 | 378 |
def get_quota(users): |
384 | 379 |
resources = get_resource_names() |
385 | 380 |
return qh_get_quota(users, resources) |
... | ... | |
527 | 522 |
raise PermissionDenied(m) |
528 | 523 |
|
529 | 524 |
membership.accept() |
530 |
qh_sync([membership])
|
|
525 |
qh_sync([user])
|
|
531 | 526 |
logger.info("User %s has been accepted in %s." % |
532 | 527 |
(membership.person.log_display, project)) |
533 | 528 |
|
... | ... | |
587 | 582 |
raise PermissionDenied(m) |
588 | 583 |
|
589 | 584 |
membership.remove() |
590 |
qh_sync([membership])
|
|
585 |
qh_sync([user])
|
|
591 | 586 |
logger.info("User %s has been removed from %s." % |
592 | 587 |
(membership.person.log_display, project)) |
593 | 588 |
|
... | ... | |
605 | 600 |
raise PermissionDenied(m) |
606 | 601 |
|
607 | 602 |
membership.accept() |
608 |
qh_sync([membership])
|
|
603 |
qh_sync([user])
|
|
609 | 604 |
logger.info("User %s has been enrolled in %s." % |
610 | 605 |
(membership.person.log_display, project)) |
611 | 606 |
|
... | ... | |
643 | 638 |
leave_policy = project.application.member_leave_policy |
644 | 639 |
if leave_policy == AUTO_ACCEPT_POLICY: |
645 | 640 |
membership.remove() |
646 |
qh_sync([membership])
|
|
641 |
qh_sync([user_id])
|
|
647 | 642 |
logger.info("User %s has left %s." % |
648 | 643 |
(membership.person.log_display, project)) |
649 | 644 |
auto_accepted = True |
... | ... | |
680 | 675 |
if (join_policy == AUTO_ACCEPT_POLICY and |
681 | 676 |
not project.violates_members_limit(adding=1)): |
682 | 677 |
membership.accept() |
683 |
qh_sync([membership])
|
|
678 |
qh_sync([user_id])
|
|
684 | 679 |
logger.info("User %s joined %s." % |
685 | 680 |
(membership.person.log_display, project)) |
686 | 681 |
auto_accepted = True |
... | ... | |
916 | 911 |
|
917 | 912 |
|
918 | 913 |
def qh_sync_projects(projects): |
919 |
memberships = [] |
|
920 |
append = memberships.append |
|
921 |
for project in projects: |
|
922 |
ms = project.projectmembership_set.all().select_for_update() |
|
923 |
memberships += list(ms) |
|
924 |
|
|
925 |
qh_sync(memberships) |
|
926 |
|
|
927 |
|
|
928 |
def qh_sync(memberships): |
|
929 |
sub_quota, add_quota = [], [] |
|
930 |
for membership in memberships: |
|
931 |
pending_application = membership.get_pending_application() |
|
932 |
membership.get_diff_quotas(sub_quota, add_quota, pending_application) |
|
933 |
if membership.state == membership.REMOVED: |
|
934 |
membership.delete() |
|
935 |
else: |
|
936 |
membership.application = pending_application |
|
937 |
membership.save() |
|
938 |
qh_add_quota(sub_quota, add_quota) |
|
914 |
|
|
915 |
memberships = ProjectMembership.objects.filter(project__in=projects) |
|
916 |
user_ids = set(m.person_id for m in memberships) |
|
917 |
|
|
918 |
qh_sync(user_ids) |
|
919 |
|
|
920 |
|
|
921 |
def qh_sync(user_ids): |
|
922 |
users = AstakosUser.forupdate.filter(id__in=user_ids).select_for_update() |
|
923 |
astakos_quotas = users_quotas(users) |
|
924 |
set_user_quota(astakos_quotas) |
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
380 | 380 |
|
381 | 381 |
objects = AstakosUserManager() |
382 | 382 |
|
383 |
forupdate = ForUpdateManager() |
|
384 |
|
|
383 | 385 |
def __init__(self, *args, **kwargs): |
384 | 386 |
super(AstakosUser, self).__init__(*args, **kwargs) |
385 | 387 |
self.__has_signed_terms = self.has_signed_terms |
... | ... | |
2153 | 2155 |
raise AssertionError(m) |
2154 | 2156 |
|
2155 | 2157 |
self._set_history_item(reason='REMOVE') |
2156 |
self.state = self.REMOVED |
|
2157 |
self.save() |
|
2158 |
self.delete() |
|
2158 | 2159 |
|
2159 | 2160 |
def can_reject(self): |
2160 | 2161 |
return self.state == self.REQUESTED |
... | ... | |
2182 | 2183 |
self._set_history_item(reason='CANCEL') |
2183 | 2184 |
self.delete() |
2184 | 2185 |
|
2185 |
def get_diff_quotas(self, sub_list=None, add_list=None, |
|
2186 |
pending_application=None): |
|
2187 |
if sub_list is None: |
|
2188 |
sub_list = [] |
|
2189 |
|
|
2190 |
if add_list is None: |
|
2191 |
add_list = [] |
|
2192 |
|
|
2193 |
sub_append = sub_list.append |
|
2194 |
add_append = add_list.append |
|
2195 |
holder = self.person.uuid |
|
2196 |
|
|
2197 |
synced_application = self.application |
|
2198 |
if synced_application is not None: |
|
2199 |
cur_grants = synced_application.projectresourcegrant_set.all() |
|
2200 |
for grant in cur_grants: |
|
2201 |
sub_append(QuotaLimits( |
|
2202 |
holder = holder, |
|
2203 |
resource = str(grant.resource), |
|
2204 |
capacity = grant.member_capacity, |
|
2205 |
)) |
|
2206 |
|
|
2207 |
if pending_application is not None: |
|
2208 |
new_grants = pending_application.projectresourcegrant_set.all() |
|
2209 |
for new_grant in new_grants: |
|
2210 |
add_append(QuotaLimits( |
|
2211 |
holder = holder, |
|
2212 |
resource = str(new_grant.resource), |
|
2213 |
capacity = new_grant.member_capacity, |
|
2214 |
)) |
|
2215 |
|
|
2216 |
return (sub_list, add_list) |
|
2217 |
|
|
2218 |
def get_pending_application(self): |
|
2219 |
project = self.project |
|
2220 |
if project.is_deactivated(): |
|
2221 |
return None |
|
2222 |
if self.state not in self.ACTUALLY_ACCEPTED: |
|
2223 |
return None |
|
2224 |
return project.application |
|
2225 |
|
|
2226 | 2186 |
|
2227 | 2187 |
class Serial(models.Model): |
2228 | 2188 |
serial = models.AutoField(primary_key=True) |
Also available in: Unified diff