Use proper url in emails sent to pending participants
[cds-indico.git] / indico / MaKaC / common / pendingQueues.py
blob2fc0329cf9b82dd17b968106e8dac36be6f4470e
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from persistent import Persistent
19 from MaKaC.common import indexes, mail
20 from MaKaC.common.info import HelperMaKaCInfo
21 from MaKaC.webinterface import urlHandlers
22 from MaKaC.webinterface.mail import GenericNotification
24 from indico.core import signals
25 from indico.core.config import Config
26 from indico.core.logger import Logger
27 from indico.modules.auth.util import url_for_register
30 logger = Logger.get('pending')
33 class PendingHolder(object):
34 """ This is an index that holds all the requests to add pending people to become
35 Indico users.
36 Those participants are not Avatars yet (do not have Indico account) and that's why
37 they are in this pending queue. So once they become Indico users they will be removed
38 from the index"""
40 def __init__(self):
41 """Index by email of all the request and all the tasks with the reminders"""
42 self._id = ""
43 self._idx = None # All the pending users
45 def getPendingByEmail(self, email):
46 return self._idx.matchPendingUser(email)
48 def removePending(self, sb):
49 """Remove the pendant from the queue"""
50 self._idx.unindexPendingUser(sb)
52 def addPending(self, sb, sendEmail=True):
53 """Add a new user to the index"""
54 self._idx.indexPendingUser(sb)
55 if sendEmail:
56 self._sendReminderEmail(sb)
58 def grantRights(self, av):
59 """We must implement this method in order to grant the specific rights to the new user"""
60 pass
62 def _sendReminderEmail(self, sb):
63 """We must implement this method in order to sent an email with the reminder for the specific pending users"""
64 pass
67 class _PendingNotification(GenericNotification):
69 def __init__(self, psList):
70 self._psList = psList
71 self._participationsByConf = self._calculateParticipationsByConf()
72 self._forceIndicoFromAddress = len(self._participationsByConf) > 1
73 data = {}
74 data["subject"] = "[Indico] User account creation required"
75 data["toList"] = [self._psList[0].getEmail()]
76 GenericNotification.__init__(self, data)
78 def getFromAddr(self):
79 # TODO: There will be on "from address" from a conference, but what if there are more different conferences
80 supEmail = self._psList[0].getConference().getSupportInfo().getEmail(returnNoReply=True)
81 if self._forceIndicoFromAddress or supEmail.strip() == "":
82 info = HelperMaKaCInfo.getMaKaCInfoInstance()
83 return "%s <%s>".format(info.getTitle(), Config.getInstance().getSupportEmail())
84 return supEmail
86 def getBody(self):
87 # We must implement the body of the email depending of the type of queue
88 pass
90 def _calculateParticipationsByConf(self):
91 d = {}
92 for ps in self._psList:
93 conf = ps.getConference()
94 if conf in d:
95 d[conf].append(ps)
96 else:
97 d[conf] = [ps]
98 return d
101 #---END GENERAL
104 #---SUBMITTERS----
106 class PendingConfSubmittersHolder(PendingHolder):
108 """ This is an index that holds all the requests to add Chairpersons or Speakers in the
109 list of avatars with rights to submit material.
110 Those participants are not Avatars yet (do not have Indico account) and that's why
111 they are in this pending queue. So once they become Indico users they will be removed
112 from the index"""
114 def __init__(self):
115 """Index by email of all the request to add Chairpersons or Speakers"""
116 self._id="ConfSubmitters"
117 self._idx = indexes.IndexesHolder().getById("pendingConfSubmitters") # All the Conference Chairpersons/Speakers
119 def grantRights(self, av):
120 l = self.getPendingByEmail(av.getEmail())
121 for e in l:
122 # We must grant the new avatar with submission rights
123 conf = e.getConference()
124 conf.getAccessController().grantSubmission(av)
126 # the Conference method "removePendingConfSubmitter" will remove the Submitter
127 # objects from the conference pending submitter
128 # list and from the this index (PendingConfSubmitterHolder).
129 e.getConference().getPendingQueuesMgr().removePendingConfSubmitter(e)
131 def _sendReminderEmail(self, sb):
132 if type(sb)==list:
133 notif = _PendingConfSubmitterNotification( sb )
134 mail.GenericMailer.send( notif )
135 else:
136 psList = self.getPendingByEmail(sb.getEmail())
137 if psList:
138 notif = _PendingConfSubmitterNotification( psList )
139 mail.GenericMailer.send( notif )
141 class _PendingConfSubmitterNotification(_PendingNotification):
143 def getBody(self):
144 # we go to the login page since local registration might be disabled
145 # in the future it would be nice to use a different messages depending
146 # if local identities are enabled or not
147 url = url_for_register()
148 return """
149 You have been granted with file submission rights for the following event:%s
150 Please create an account in Indico in order to use these rights. You can create your account at the following URL:
152 <%s>
154 *Note that you must use this email address %s when creating the account*
156 Best Regards.
159 Indico"""%( self._getParticipations(), url, self._psList[0].getEmail() )
161 def _getParticipations(self):
162 participations = "\n\n"
163 for conf in self._participationsByConf.keys():
164 participations += """\t\t\t- "Event" \"%s\":\n""" % conf.getTitle()
165 accessURL = urlHandlers.UHConferenceDisplay.getURL(conf)
166 participations += "\t\t\t\t - Access: %s\n" % accessURL
167 return participations
170 class PendingSubmittersHolder(PendingHolder):
172 """ This is an index that holds all the requests to add Authors and Speakers in the
173 list of avatars with rights to submit material.
174 Those participants are not Avatars yet (do not have Indico account) and that's why
175 they are in this pending queue. So once they become Indico users they will be removed
176 from the index"""
178 def __init__(self):
179 """Index by email of all the request to add Authors or Speakers"""
180 self._id="Submitters"
181 self._idx = indexes.IndexesHolder().getById("pendingSubmitters") # All the ContributionParticipants
183 def grantRights(self, av):
184 l = self.getPendingByEmail(av.getEmail())
185 for e in l:
186 # We must grant the new avatar with submission rights
187 contrib = e.getContribution()
188 contrib.grantSubmission(av)
190 for email in av.getEmails():
191 contrib.revokeSubmissionEmail(email.lower())
193 # the Conference method "removePendingSubmitter" will remove the Submitter
194 # (type-ContributionParticipation) objects from the conference pending submitter
195 # list and from the this index (PendingSubmitterHolder).
196 e.getConference().getPendingQueuesMgr().removePendingSubmitter(e)
198 def _sendReminderEmail(self, sb):
199 from MaKaC.conference import ContributionParticipation
200 if type(sb)==list:
201 # Sending email just about the contribution participations of the list "sb" (normally
202 # they are contributions from one event)
203 notif = _PendingSubmitterNotification( sb )
204 mail.GenericMailer.send( notif )
205 elif isinstance(sb, ContributionParticipation):
206 # The param "sb" is a ContributionParticipant, so we send an email with the info
207 # about all its participations
208 psList=self.getPendingByEmail(sb.getEmail())
209 if psList != [] and psList is not None:
210 notif = _PendingSubmitterNotification( psList )
211 mail.GenericMailer.send( notif )
214 class _PendingSubmitterNotification(_PendingNotification):
216 def getBody( self ):
217 # we go to the login page since local registration might be disabled
218 # in the future it would be nice to use a different messages depending
219 # if local identities are enabled or not
220 url = url_for_register()
221 return """
222 You have been added as author/speaker of the following contributions:%s
223 and material submission rights have been granted to you.
224 Please create an account in Indico in order to use these rights. You can create your account at the following URL:
226 <%s>
228 *Note that you must use this email address %s when creating the account*
230 Best Regards.
233 Indico"""%( self._getParticipations(), url, self._psList[0].getEmail() )
235 def _getParticipations(self):
236 participations="\n\n"
237 for conf in self._participationsByConf.keys():
238 participations+="""\t\t\t- "Event" \"%s\":\n"""%conf.getTitle()
239 for ps in self._participationsByConf[conf]:
240 contrib=ps.getContribution()
241 typeAuthor=""
242 if contrib.isPrimaryAuthor(ps):
243 typeAuthor="Primary Author"
244 elif contrib.isCoAuthor(ps):
245 typeAuthor="Co-author"
246 elif contrib.isSpeaker(ps):
247 typeAuthor="Speaker"
248 participations+="""\t\t\t\t - "Contribution" \"%s\" (%s)\n"""%(contrib.getTitle(), typeAuthor)
249 accessURL = urlHandlers.UHContributionDisplay.getURL(contrib)
250 participations+="\t\t\t\t - Access: %s\n" % accessURL
251 return participations
254 #---END SUBMITTERS
256 #---PENDING SESSION MANAGERS
257 class PendingManagersHolder(PendingHolder):
259 """ This is an index that holds all the requests to add non existing users in the
260 list of avatars with rights to manage.
261 Those participants are not Avatars yet (do not have Indico account) and that's why
262 they are in this pending queue. So once they become Indico users they will be removed
263 from the index"""
265 def __init__(self):
266 """Index by email of all the requests"""
267 self._id="Managers"
268 self._idx = indexes.IndexesHolder().getById("pendingManagers") # All the pending managers
270 def grantRights(self, av):
271 l=self.getPendingByEmail(av.getEmail())
272 for e in l:
273 # We must grant the new avatar with submission rights
274 session=e.getSession()
275 session.grantModification(av)
276 # the ConfPendingQueuesMgr method "removePendingManager" will remove the Manager
277 # (type-SessionChair) objects from the conference pending manager
278 # list and from the this index (PendingManagersHolder).
279 e.getConference().getPendingQueuesMgr().removePendingManager(e)
281 def _sendReminderEmail(self, sb):
282 from MaKaC.conference import SessionChair
283 if type(sb)==list:
284 # Sending email just about the participations of the list "sb" (normally
285 # they are sessions from one event)
286 notif = _PendingManagerNotification( sb )
287 mail.GenericMailer.send( notif )
288 elif isinstance(sb, SessionChair):
289 # The param "sb" is a SessionChair, so we send an email with the info
290 # about all its participations
291 psList=self.getPendingByEmail(sb.getEmail())
292 if psList != [] and psList is not None:
293 notif = _PendingManagerNotification( psList )
294 mail.GenericMailer.send( notif )
296 class _PendingManagerNotification(_PendingNotification):
298 def getBody( self ):
299 # we go to the login page since local registration might be disabled
300 # in the future it would be nice to use a different messages depending
301 # if local identities are enabled or not
302 url = url_for_register()
303 return """
304 You have been added as convener of the following sessions:%s
305 And session modification rights have been granted to you.
306 Please create an account in Indico in order to use these rights. You can create your account at the following URL:
308 <%s>
310 *Note that you must use this email address %s when creating the account*
312 Best Regards.
315 Indico"""%( self._getParticipations(), url, self._psList[0].getEmail() )
317 def _getParticipations(self):
318 participations="\n\n"
319 for conf in self._participationsByConf.keys():
320 participations+="""\t\t\t- "Event" \"%s\":\n"""%conf.getTitle()
321 for ps in self._participationsByConf[conf]:
322 session=ps.getSession()
323 participations+="""\t\t\t\t - "Session" \"%s\"\n"""%(session.getTitle())
324 accessURL = urlHandlers.UHSessionDisplay.getURL(session)
325 participations+="\t\t\t\t - Access: %s\n" % accessURL
326 return participations
329 #---END MANAGERS
332 #---PENDING CONFERENCE MANAGERS
333 class PendingConfManagersHolder(PendingHolder):
335 """ This is an index that holds all the requests to add non existing users in the
336 list of avatars with rights to manage.
337 Those participants are not Avatars yet (do not have Indico account) and that's why
338 they are in this pending queue. So once they become Indico users they will be removed
339 from the index"""
341 def __init__(self):
342 """Index by email of all the requests"""
343 self._id="ConfManagers"
344 self._idx = indexes.IndexesHolder().getById("pendingConfManagers") # All the pending managers
346 def grantRights(self, av):
347 l=self.getPendingByEmail(av.getEmail())
348 for e in l:
349 conf = e.getConference()
350 conf.grantModification(av)
351 # the ConfPendingQueuesMgr method "removePendingManager" will remove the Manager
352 # (type-ConferenceChair) objects from the conference pending manager
353 # list and from the this index (PendingManagersHolder).
354 conf.getPendingQueuesMgr().removePendingConfManager(e)
356 def _sendReminderEmail(self, sb):
357 from MaKaC.conference import ConferenceChair
358 if type(sb)==list:
359 # Sending email just about the participations of the list "sb" (normally
360 # they are sessions from one event)
361 notif = _PendingConfManagerNotification( sb )
362 mail.GenericMailer.send( notif )
363 elif isinstance(sb, ConferenceChair):
364 # The param "sb" is a SessionChair, so we send an email with the info
365 # about all its participations
366 psList=self.getPendingByEmail(sb.getEmail())
367 if psList != [] and psList is not None:
368 notif = _PendingConfManagerNotification( psList )
369 mail.GenericMailer.send( notif )
371 class _PendingConfManagerNotification(_PendingNotification):
372 def getBody( self ):
373 # we go to the login page since local registration might be disabled
374 # in the future it would be nice to use a different messages depending
375 # if local identities are enabled or not
376 url = url_for_register()
377 return """
378 You have been added as manager of the following Event:%s
379 And modification rights have been granted to you.
380 Please create an account in Indico in order to use these rights. You can create your account at the following URL:
382 <%s>
384 *Note that you must use this email address %s when creating the account*
386 Best Regards.
389 Indico"""%( self._getParticipations(), url, self._psList[0].getEmail() )
391 def _getParticipations(self):
392 participations="\n\n"
393 for conf in self._participationsByConf.keys():
394 participations+="""\t\t\t- "Event" \"%s\":\n"""%conf.getTitle()
395 accessURL = urlHandlers.UHConferenceDisplay.getURL(conf)
396 participations+="\t\t\t- Access: %s\n" % accessURL
397 return participations
400 #---END MANAGERS
402 #---PENDING COORDINATORS
403 class PendingCoordinatorsHolder(PendingHolder):
405 """ This is an index that holds all the requests to add non existing users in the
406 list of avatars with rights to coordinate.
407 Those participants are not Avatars yet (do not have Indico account) and that's why
408 they are in this pending queue. So once they become Indico users they will be removed
409 from the index"""
411 def __init__(self):
412 """Index by email of all the requests"""
413 self._id="Coordinators"
414 self._idx = indexes.IndexesHolder().getById("pendingCoordinators") # All the pending coordinators
416 def grantRights(self, av):
417 l=self.getPendingByEmail(av.getEmail())
418 for e in l:
419 # We must grant the new avatar with submission rights
420 session=e.getSession()
421 session.addCoordinator(av)
422 # the ConfPendingQueuesMgr method "removePendingCoordinator" will remove the Coordinator
423 # (type-SessionChair) objects from the conference pending coordinator
424 # list and from the this index (PendingCoordinatorsHolder).
425 e.getConference().getPendingQueuesMgr().removePendingCoordinator(e)
427 def _sendReminderEmail(self, sb):
428 from MaKaC.conference import SessionChair
429 if type(sb)==list:
430 # Sending email just about the participations of the list "sb" (normally
431 # they are sessions from one event)
432 notif = _PendingCoordinatorNotification( sb )
433 mail.GenericMailer.send( notif )
434 elif isinstance(sb, SessionChair):
435 # The param "sb" is a SessionChair, so we send an email with the info
436 # about all its participations
437 psList=self.getPendingByEmail(sb.getEmail())
438 if psList != [] and psList is not None:
439 notif = _PendingCoordinatorNotification( psList )
440 mail.GenericMailer.send( notif )
442 class _PendingCoordinatorNotification(_PendingNotification):
444 def getBody( self ):
445 # we go to the login page since local registration might be disabled
446 # in the future it would be nice to use a different messages depending
447 # if local identities are enabled or not
448 url = url_for_register()
449 return """
450 You have been added as convener of the following sessions:%s
451 And session coordination rights have been granted to you.
452 Please create an account in Indico in order to use these rights. You can create your account at the following URL:
454 <%s>
456 *Note that you must use this email address %s when creating your account*
458 Best Regards.
461 Indico"""%( self._getParticipations(), url, self._psList[0].getEmail() )
463 def _getParticipations(self):
464 participations="\n\n"
465 for conf in self._participationsByConf.keys():
466 participations+="""\t\t\t- "Event" \"%s\":\n"""%conf.getTitle()
467 for ps in self._participationsByConf[conf]:
468 session=ps.getSession()
469 participations+="""\t\t\t\t - "Session" \"%s\"\n"""%(session.getTitle())
470 accessURL = urlHandlers.UHSessionDisplay.getURL(session)
471 participations+="\t\t\t\t - Access: %s\n" % accessURL
472 return participations
476 #---END COORDINATORS
478 #--GENERAL---
479 class PendingQueuesHolder(object):
481 _pendingQueues=[PendingConfManagersHolder, \
482 PendingConfSubmittersHolder, \
483 PendingSubmittersHolder, \
484 PendingManagersHolder, \
485 PendingCoordinatorsHolder]
487 def _getAllPendingQueues(cls):
488 return cls._pendingQueues
489 _getAllPendingQueues=classmethod(_getAllPendingQueues)
491 def grantRights(cls, av):
492 for pq in cls._getAllPendingQueues():
493 pq().grantRights(av)
494 grantRights=classmethod(grantRights)
496 def getFirstPending(cls, email):
497 for pq in cls._getAllPendingQueues():
498 l=pq().getPendingByEmail(email)
499 if len(l)>0:
500 return l[0]
501 return None
502 getFirstPending=classmethod(getFirstPending)
504 ###---------------------------- Conference Pending Queues ---------------------------------
506 class ConfPendingQueuesMgr(Persistent):
508 def __init__(self, conf):
509 self._conf=conf
510 self._pendingConfManagers={}
511 self._pendingConfSubmitters={}
512 self._pendingSubmitters={}
513 self._pendingManagers={}
514 self._pendingCoordinators={}
516 def getConference(self):
517 return self._conf
519 def getPendingConfManagers(self):
520 try:
521 if self._pendingConfManagers:
522 pass
523 except AttributeError:
524 self._pendingConfManagers={}
525 return self._pendingConfManagers
527 def getPendingConfSubmitters(self):
528 try:
529 if self._pendingConfSubmitters:
530 pass
531 except AttributeError:
532 self._pendingConfSubmitters={}
533 return self._pendingConfSubmitters
535 def getPendingSubmitters(self):
536 return self._pendingSubmitters
538 def getPendingManagers(self):
539 try:
540 if self._pendingManagers:
541 pass
542 except AttributeError:
543 self._pendingManagers={}
544 return self._pendingManagers
546 def getPendingCoordinators(self):
547 try:
548 if self._pendingCoordinators:
549 pass
550 except AttributeError:
551 self._pendingCoordinators={}
552 return self._pendingCoordinators
554 def getPendingConfManagersKeys(self, sort=False):
555 if sort:
556 from MaKaC.conference import ConferenceChair
557 # return keys of contribution participants sorted by name
558 keys=[]
559 vl=[]
560 # flatten the list of lists
561 for v in self.getPendingConfManagers().values()[:]:
562 vl.extend(v)
563 # sort
564 vl.sort(ConferenceChair._cmpFamilyName)
565 for v in vl:
566 email=v.getEmail().lower().strip()
567 if email not in keys:
568 keys.append(email)
569 return keys
570 else:
571 keys=self.getPendingConfManagers().keys()
572 return keys
574 def getPendingConfManagersByEmail(self, email):
575 email=email.lower().strip()
576 if self.getPendingConfManagers().has_key(email):
577 return self._pendingConfManagers[email]
578 return []
580 def isPendingConfManager(self, cp):
581 email=cp.getEmail().lower().strip()
582 return cp in self.getPendingConfManagersByEmail(email)
584 #----Pending queue for conference submitters-----
586 def getPendingConfSubmittersKeys(self, sort=False):
587 if sort:
588 from MaKaC.conference import ConferenceChair
589 # return keys of contribution participants sorted by name
590 keys=[]
591 vl=[]
592 # flatten the list of lists
593 for v in self.getPendingConfSubmitters().values()[:]:
594 vl.extend(v)
595 # sort
596 vl.sort(ConferenceChair._cmpFamilyName)
597 for v in vl:
598 email=v.getEmail().lower().strip()
599 if email not in keys:
600 keys.append(email)
601 return keys
602 else:
603 keys=self.getPendingConfSubmitters().keys()
604 return keys
606 def addSubmitter(self, ps, owner, sendEmail=True):
607 from MaKaC.conference import Conference
608 if isinstance(owner, Conference):
609 self.addPendingConfSubmitter(ps, sendEmail=True)
610 mail.GenericMailer.sendAndLog(_PendingConfSubmitterNotification([ps]), owner, 'Submission')
612 def removeSubmitter(self, ps, owner):
613 from MaKaC.conference import Conference
614 if isinstance(owner, Conference):
615 self.removePendingConfSubmitter(ps)
617 def addPendingConfManager(self, ps, sendEmail=True):
618 email=ps.getEmail().lower().strip()
619 if self.getPendingConfManagers().has_key(email):
620 if not ps in self._pendingConfManagers[email]:
621 self._pendingConfManagers[email].append(ps)
622 else:
623 self._pendingConfManagers[email] = [ps]
624 pendings=PendingConfManagersHolder()
625 pendings.addPending(ps, sendEmail)
626 self.notifyModification()
628 def removePendingConfManager(self, ps):
629 email=ps.getEmail().lower().strip()
630 if self.getPendingConfManagers().has_key(email):
631 if ps in self._pendingConfManagers[email]:
632 self._pendingConfManagers[email].remove(ps)
633 pendings=PendingConfManagersHolder()
634 pendings.removePending(ps)
635 if self._pendingConfManagers[email] == []:
636 del self._pendingConfManagers[email]
637 self.notifyModification()
639 def addPendingConfSubmitter(self, ps, sendEmail=True):
640 email=ps.getEmail().lower().strip()
641 if self.getPendingConfSubmitters().has_key(email):
642 if not ps in self._pendingConfSubmitters[email]:
643 self._pendingConfSubmitters[email].append(ps)
644 else:
645 self._pendingConfSubmitters[email] = [ps]
646 pendings=PendingConfSubmittersHolder()
647 pendings.addPending(ps, sendEmail)
648 self.notifyModification()
650 def removePendingConfSubmitter(self, ps):
651 email=ps.getEmail().lower().strip()
652 if self.getPendingConfSubmitters().has_key(email):
653 if ps in self._pendingConfSubmitters[email]:
654 self._pendingConfSubmitters[email].remove(ps)
655 pendings=PendingConfSubmittersHolder()
656 pendings.removePending(ps)
657 if self._pendingConfSubmitters[email] == []:
658 del self._pendingConfSubmitters[email]
659 self.notifyModification()
661 def getPendingConfSubmittersByEmail(self, email):
662 email=email.lower().strip()
663 if self.getPendingConfSubmitters().has_key(email):
664 return self._pendingConfSubmitters[email]
665 return []
667 def isPendingConfSubmitter(self, cp):
668 email=cp.getEmail().lower().strip()
669 return cp in self.getPendingConfSubmittersByEmail(email)
671 #---End conference submitters-----
674 #----Pending queue for contribution submitters-----
676 def getPendingSubmittersKeys(self, sort=False):
677 if sort:
678 from MaKaC.conference import ContributionParticipation
679 # return keys of contribution participants sorted by name
680 keys=[]
681 vl=[]
682 # flatten the list of lists
683 for v in self.getPendingSubmitters().values()[:]:
684 vl.extend(v)
685 # sort
686 vl.sort(ContributionParticipation._cmpFamilyName)
687 for v in vl:
688 email=v.getEmail().lower().strip()
689 if email not in keys:
690 keys.append(email)
691 return keys
692 else:
693 keys=self.getPendingSubmitters().keys()
694 return keys
696 def removePendingSubmitter(self, ps):
697 # Used only from contributions.
698 # TODO: when refactoring, this method should be renamed and called only from self.removeSubmitter
699 email=ps.getEmail().lower().strip()
700 if self.getPendingSubmitters().has_key(email):
701 if ps in self._pendingSubmitters[email]:
702 self._pendingSubmitters[email].remove(ps)
703 pendings=PendingSubmittersHolder()
704 pendings.removePending(ps)
705 if self._pendingSubmitters[email] == []:
706 del self._pendingSubmitters[email]
707 self.notifyModification()
709 def addPendingSubmitter(self, ps, sendEmail=True):
710 # Used only from contributions.
711 # TODO: when refactoring, this method should be renamed and called only from self.addSubmitter
712 email=ps.getEmail().lower().strip()
713 if self.getPendingSubmitters().has_key(email):
714 if not ps in self._pendingSubmitters[email]:
715 self._pendingSubmitters[email].append(ps)
716 else:
717 self._pendingSubmitters[email] = [ps]
718 pendings=PendingSubmittersHolder()
719 pendings.addPending(ps, sendEmail)
720 self.notifyModification()
722 def getPendingSubmittersByEmail(self, email):
723 email=email.lower().strip()
724 if self.getPendingSubmitters().has_key(email):
725 return self._pendingSubmitters[email]
726 return []
728 def isPendingSubmitter(self, cp):
729 email=cp.getEmail().lower().strip()
730 return cp in self.getPendingSubmittersByEmail(email)
731 #---End submitters-----
733 #---Conveners to managers----
734 def getPendingManagersKeys(self, sort=False):
735 if sort:
736 from MaKaC.conference import SessionChair
737 # return keys of conveners sorted by name
738 keys=[]
739 vl=[]
740 # flatten the list of lists
741 for v in self.getPendingManagers().values()[:]:
742 vl.extend(v)
743 # sort
744 vl.sort(SessionChair._cmpFamilyName)
745 for v in vl:
746 email=v.getEmail().lower().strip()
747 if email not in keys:
748 keys.append(email)
749 return keys
750 else:
751 keys=self.getPendingManagers().keys()
752 return keys
754 def addPendingManager(self, ps, sendEmail=True):
755 email=ps.getEmail().lower().strip()
756 if self.getPendingManagers().has_key(email):
757 if not ps in self._pendingManagers[email]:
758 self._pendingManagers[email].append(ps)
759 else:
760 self._pendingManagers[email] = [ps]
761 pendings=PendingManagersHolder()
762 pendings.addPending(ps, sendEmail)
763 self.notifyModification()
765 def removePendingManager(self, ps):
766 email=ps.getEmail().lower().strip()
767 if self.getPendingManagers().has_key(email):
768 if ps in self._pendingManagers[email]:
769 self._pendingManagers[email].remove(ps)
770 pendings=PendingManagersHolder()
771 pendings.removePending(ps)
772 if self._pendingManagers[email] == []:
773 del self._pendingManagers[email]
774 self.notifyModification()
776 def getPendingManagersByEmail(self, email):
777 email=email.lower().strip()
778 if self.getPendingManagers().has_key(email):
779 return self._pendingManagers[email]
780 return []
782 def isPendingManager(self, cp):
783 email=cp.getEmail().lower().strip()
784 return cp in self.getPendingManagersByEmail(email)
786 #----End managers
788 #---Conveners to coordinators----
789 def getPendingCoordinatorsKeys(self, sort=False):
790 if sort:
791 from MaKaC.conference import SessionChair
792 # return keys of conveners sorted by name
793 keys=[]
794 vl=[]
795 # flatten the list of lists
796 for v in self.getPendingCoordinators().values()[:]:
797 vl.extend(v)
798 # sort
799 vl.sort(SessionChair._cmpFamilyName)
800 for v in vl:
801 email=v.getEmail().lower().strip()
802 if email not in keys:
803 keys.append(email)
804 return keys
805 else:
806 keys=self.getPendingCoordinators().keys()
807 return keys
809 def addPendingCoordinator(self, ps, sendEmail=True):
810 email=ps.getEmail().lower().strip()
811 if self.getPendingCoordinators().has_key(email):
812 if not ps in self._pendingCoordinators[email]:
813 self._pendingCoordinators[email].append(ps)
814 else:
815 self._pendingCoordinators[email] = [ps]
816 pendings=PendingCoordinatorsHolder()
817 pendings.addPending(ps, sendEmail)
818 self.notifyModification()
820 def removePendingCoordinator(self, ps):
821 email=ps.getEmail().lower().strip()
822 if self.getPendingCoordinators().has_key(email):
823 if ps in self._pendingCoordinators[email]:
824 self._pendingCoordinators[email].remove(ps)
825 pendings=PendingCoordinatorsHolder()
826 pendings.removePending(ps)
827 if self._pendingCoordinators[email] == []:
828 del self._pendingCoordinators[email]
829 self.notifyModification()
831 def getPendingCoordinatorsByEmail(self, email):
832 email=email.lower().strip()
833 if self.getPendingCoordinators().has_key(email):
834 return self._pendingCoordinators[email]
835 return []
837 def isPendingCoordinator(self, cp):
838 email=cp.getEmail().lower().strip()
839 return cp in self.getPendingCoordinatorsByEmail(email)
841 #----End coordinators
843 def notifyModification(self):
844 self._p_changed=1
847 @signals.users.registered.connect
848 def _on_user_register(user, **kwargs):
849 """Remove newly-added users from pending lists"""
850 pending_submitter = PendingSubmittersHolder().getPendingByEmail(user.email)
851 if pending_submitter:
852 principal = pending_submitter[0]
853 mgr = principal.getConference().getPendingQueuesMgr()
854 logger.info('Removed pending submitter {0} from {1}'.format(user, principal.getConference()))
855 mgr.removePendingSubmitter(principal)
857 pending_evt_submitter = PendingConfSubmittersHolder().getPendingByEmail(user.email)
858 if pending_evt_submitter:
859 principal = pending_evt_submitter[0]
860 mgr = principal.getConference().getPendingQueuesMgr()
861 logger.info('Removed pending event submitter {0} from {1}'.format(user, principal.getConference()))
862 mgr.removePendingConfSubmitter(principal)