Example #1
0
    def invokeMethod(self, method, params, req):

        MAX_RETRIES = 10

        # clear the context
        ContextManager.destroy()

        DBMgr.getInstance().startRequest()

        # room booking database
        _startRequestSpecific2RH()

        # notify components that the request has started
        self._notify('requestStarted', req)

        forcedConflicts = Config.getInstance().getForceConflicts()
        retry = MAX_RETRIES
        try:
            while retry > 0:
                if retry < MAX_RETRIES:
                    # notify components that the request is being retried
                    self._notify('requestRetry', req, MAX_RETRIES - retry)

                try:
                    # delete all queued emails
                    GenericMailer.flushQueue(False)

                    DBMgr.getInstance().sync()

                    try:
                        result = processRequest(method, copy.deepcopy(params), req)
                    except MaKaC.errors.NoReportError, e:
                        raise NoReportError(e.getMsg())
                    rh = ContextManager.get('currentRH')

                    # notify components that the request has ended
                    self._notify('requestFinished', req)
                    # Raise a conflict error if enabled. This allows detecting conflict-related issues easily.
                    if retry > (MAX_RETRIES - forcedConflicts):
                        raise ConflictError
                    _endRequestSpecific2RH( True )
                    DBMgr.getInstance().endRequest(True)
                    GenericMailer.flushQueue(True) # send emails
                    if rh._redisPipeline:
                        try:
                            rh._redisPipeline.execute()
                        except RedisError:
                            Logger.get('redis').exception('Could not execute pipeline')
                    break
                except ConflictError:
                    _abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    continue
                except ClientDisconnected:
                    _abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    time.sleep(MAX_RETRIES - retry)
                    continue
Example #2
0
 def _doValidate(self):
     # First, one must validate that the information is fine
     errors = self._abstractData.check()
     if errors:
         p = abstracts.WPAbstractSubmission(self, self._target)
         pars = self._abstractData.toDict()
         pars["action"] = self._action
         pars["attachments"] = []
         return p.display(**pars)
     # Then, we create the abstract object and set its data to the one
     #   received
     cfaMgr = self._target.getAbstractMgr()
     abstract = cfaMgr.newAbstract(self._getUser())
     self._abstractData.setAbstractData(abstract)
     # The commit must be forced before sending the confirmation
     DBMgr.getInstance().commit()
     # Email confirmation about the submission
     mail.Mailer.send(
         _AbstractSubmissionNotification(abstract), self._conf.getSupportInfo().getEmail(returnNoReply=True)
     )
     # Email confirmation about the submission to coordinators
     if cfaMgr.getSubmissionNotification().hasDestination():
         asn = _AbstractSubmissionNotification(abstract)
         asn.setSubject(_("[Indico] New abstract submission: %s") % asn.getDestination().getFullName())
         mail.GenericMailer.send(asn)
     # We must perform some actions: email warning to the authors
     # Finally, we display a confirmation form
     self._redirect(urlHandlers.UHAbstractSubmissionConfirmation.getURL(abstract))
Example #3
0
def main(argv):
    category = -1
    meeting = -1
    show = 0

    try:
        opts, args = getopt.getopt(argv, "hm:c:s", ["help", "meeting=", "category=", "show"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-s", "--show"):
            show = 1
        elif opt in ("-m", "--meeting"):
            meeting = arg
        elif opt in ("-c", "--category"):
            category = arg

    # Create database instance and open trashcan manager object
    DBMgr.getInstance().startRequest()
    t = TrashCanManager()
    conf = None
    if show:
        for i in t.getList():
            if isinstance(i, Conference):
                if meeting != -1 and i.getId() == meeting:
                    print "[%s]%s" % (i.getId(), i.getTitle())
                elif meeting == -1:
                    print "[%s]%s" % (i.getId(), i.getTitle())
        sys.exit()
    if meeting != -1 and category != -1:
        print "Meeting:%s" % meeting
        print "Category:%s" % category
        for i in t.getList():
            if isinstance(i, Conference):
                if i.getId() == meeting:
                    conf = i
                    break

        if conf:
            # Remove the meeting from conference
            t.remove(conf)
            # Attach meeting to desired category
            cat = CategoryManager().getById(category)
            ConferenceHolder().add(conf)
            cat._addConference(conf)

            # Add Evaluation
            c = ConferenceHolder().getById(meeting)
            from MaKaC.evaluation import Evaluation

            c.setEvaluations([Evaluation(c)])

            DBMgr.getInstance().endRequest()
def getConfIds():
    DBMgr.getInstance().startRequest()
    l = ConferenceHolder().getValuesToList()
    ids = []
    for conf in l:
        ids.append(conf.getId())

    DBMgr.getInstance().endRequest()
    return ids
Example #5
0
 def _doValidate( self ):
     #First, one must validate that the information is fine
     errors = self._abstractData.check()
     if errors:
         p = abstracts.WPAbstractSubmission( self, self._target )
         pars = self._abstractData.toDict()
         pars["errors"] = errors
         pars["action"] = self._action
         return p.display( **pars )
     #Then, we create the abstract object and set its data to the one
     #   received
     cfaMgr = self._target.getAbstractMgr()
     afm = cfaMgr.getAbstractFieldsMgr()
     a = cfaMgr.newAbstract( self._getUser() )
     a.setTitle( self._abstractData.title )
     for f in afm.getFields():
         id = f.getId()
         a.setField(id, self._abstractData.getFieldValue(id))
     for authData in self._abstractData.authors.getPrimaryList():
         auth=a.newPrimaryAuthor(title = authData["auth_title"], \
                             firstName = authData["auth_firstName"], \
                             surName = authData["auth_surName"], \
                             email = authData["auth_email"], \
                             affiliation = authData["auth_affiliation"], \
                             address = authData["auth_address"], \
                             telephone = authData["auth_phone"] )
         if authData["auth_speaker"]:
             a.addSpeaker( auth )
     for authData in self._abstractData.authors.getSecondaryList():
         auth=a.newCoAuthor(title = authData["auth_title"], \
                             firstName = authData["auth_firstName"], \
                             surName = authData["auth_surName"], \
                             email = authData["auth_email"], \
                             affiliation = authData["auth_affiliation"], \
                             address = authData["auth_address"], \
                             telephone = authData["auth_phone"] )
         if authData["auth_speaker"]:
             a.addSpeaker( auth )
     a.setContribType( self._abstractData.type )
     for trackId in self._abstractData.tracks:
         track = self._conf.getTrackById( trackId )
         a.addTrack( track )
     a.setComments(self._abstractData.comments)
     #The commit must be forced before sending the confirmation
     DBMgr.getInstance().commit()
     #Email confirmation about the submission
     mail.Mailer.send( _AbstractSubmissionNotification( a ) )
     #Email confirmation about the submission to coordinators
     if cfaMgr.getSubmissionNotification().hasDestination():
         asn=_AbstractSubmissionNotification( a )
         asn.setSubject(_("[Indico] New abstract submission: %s")%asn.getDestination().getFullName())
         mail.GenericMailer.send( asn )
     #We must perform some actions: email warning to the authors
     #Finally, we display a confirmation form
     self._redirect( urlHandlers.UHAbstractSubmissionConfirmation.getURL( a ) )
def main():
    DBMgr.getInstance().startRequest()
    ch = ConferenceHolder()
    ids = []
    print "Getting conference IDs..."
    for conf in ch.getList():
        ids.append(conf.getId())
    totalNumberConfs = len(ids)
    DBMgr.getInstance().endRequest()
    print "Updating conferences..."
    i = 0
    N_CONF = 10
    cErrorList = []
    while ids:
        if len(ids) >= N_CONF:
            lids = ids[:N_CONF]
            del ids[:N_CONF]
        else:
            lids = ids
            ids = None
        for j in range(10):
            conf = None
            try:
                DBMgr.getInstance().startRequest()
                for id in lids:
                    conf = ch.getById(id)
                    log("check for conference %s: %s/%s" % (conf.getId(), i, totalNumberConfs))
                    for cont in conf.getContributionList():
                        # if not isinstance(cont, AcceptedContribution):
                        if "content" in cont.getFields().keys():
                            if cont.getFields()["content"]:
                                if cont.getFields()["content"] != cont.description:
                                    log(
                                        "  contribution %s : content field no empty and diffrent from description"
                                        % cont.getId()
                                    )
                            else:
                                # cont.setField("content",cont.description)
                                cont.getFields()["content"] = cont.description
                                cont._p_changed = 1
                        else:
                            # cont.setField("content",cont.description)
                            cont.getFields()["content"] = cont.description
                            cont._p_changed = 1
                    i += 1
                DBMgr.getInstance().endRequest()
                print "wait 0.5s..."
                sleep(0.5)
                break
            except Exception, e:
                cErrorList.append(conf)
                i -= N_CONF
                log("error %s, retry %d time(s)" % (e, int(10 - j)))
                sleep(int(j))
                DBMgr.getInstance().abort()
Example #7
0
 def _sendReminderEmail(self, sb):
     from MaKaC.conference import SessionChair
     DBMgr.getInstance().commit()
     if type(sb)==list:
         # Sending email just about the participations of the list "sb" (normally
         # they are sessions from one event)
         notif = _PendingCoordinatorNotification( sb )
         mail.GenericMailer.send( notif )
     elif isinstance(sb, SessionChair):
         # The param "sb" is a SessionChair, so we send an email with the info
         # about all its participations
         psList=self.getPendingByEmail(sb.getEmail())
         if psList != [] and psList is not None:
             notif = _PendingCoordinatorNotification( psList )
             mail.GenericMailer.send( notif )
def buildCache(ids):
    i = 1
    for id in ids:
        DBMgr.getInstance().startRequest()
        try:
            conf = ConferenceHolder().getById(id)
        except:
            print "conf %s not found"
            continue
        print i, ":", conf.getId()
        og = outputGenerator(AccessWrapper())
        x = og.confToXML(conf, 1, 1, 1, overrideCache=True)
        y = og.confToXMLMarc21(conf, 1, 1, 1, overrideCache=True)
        i += 1
        DBMgr.getInstance().endRequest()
Example #9
0
    def run(self):
        sm = SyncManager.getDBInstance()

        logger = self.getLogger()

        # go over all the agents
        for agtName, agent in sm.getAllAgents().iteritems():

            # skip agents if they're not active
            if not agent.isActive():
                logger.warning("Agent '%s' is not active - skipping" % agtName)
                continue

            logger.info("Starting agent '%s'" % agtName)
            try:
                dbi = DBMgr.getInstance()
                # pass the current time and a logger
                result = agent.run(int_timestamp(nowutc()), logger=logger, dbi=dbi)
            except:
                logger.exception("Problem running agent '%s'" % agtName)
                return

            if result:
                logger.info("Acknowledged successful operation")
                agent.acknowledge()
                dbi.commit()
            else:
                logger.info("'Acknowledge' not done - no records?")
            logger.info("Agent '%s' finished" % agtName)
Example #10
0
def main():
    """
    This script deletes existing category indexes and recreates them.
    """

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    im = indexes.IndexesHolder()
    im.removeById('categoryDate')
    catIdx = im.getIndex('categoryDate')

    cm = CategoryManager()
    num_categs = len(cm._getIdx())
    cur_num = cur_percent = 0

    for cat in cm._getIdx().itervalues():
        for conf in cat.conferences.itervalues():
            catIdx.indexConf(conf)
        dbi.commit()

        cur_num += 1
        percent = int(float(cur_num) / num_categs * 100)
        if percent != cur_percent:
            cur_percent = percent
            print "{0}%".format(percent)
    dbi.endRequest()
Example #11
0
def _event_or_shorturl(confId, shorturl_namespace=False, ovw=False):
    from MaKaC.conference import ConferenceHolder
    from MaKaC.common.url import ShortURLMapper

    with DBMgr.getInstance().global_connection():
        ch = ConferenceHolder()
        su = ShortURLMapper()
        if ch.hasKey(confId):
            # For obvious reasons an event id always comes first.
            # If it's used within the short url namespace we redirect to the event namespace, otherwise
            # we call the RH to display the event
            if shorturl_namespace:
                url = UHConferenceDisplay.getURL(ch.getById(confId))
                func = lambda: redirect(url)
            else:
                params = request.args.to_dict()
                params['confId'] = confId
                if ovw:
                    params['ovw'] = 'True'
                func = lambda: conferenceDisplay.RHConferenceDisplay(None).process(params)
        elif (shorturl_namespace or app.config['INDICO_COMPAT_ROUTES']) and su.hasKey(confId):
            if shorturl_namespace:
                # Correct namespace => redirect to the event
                url = UHConferenceDisplay.getURL(su.getById(confId))
                func = lambda: redirect(url)
            else:
                # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it
                url = url_for('.shorturl', confId=confId)
                func = lambda: redirect(url, 301)
        else:
            raise NotFound(
                _('The specified event with id or tag "%s" does not exist or has been deleted') % confId)

    return func()
Example #12
0
def _show(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.field == "status":
        status = c.getStatus()

        print "Scheduler is currently %s" % \
              ("running" if status['state'] else "NOT running")
        print """
Spooled commands: %(spooled)s

Tasks:
  - Waiting:  %(waiting)s
  - Running:  %(running)s
  - Failed:   %(failed)s
  - Finished: %(finished)s
""" % status
    elif args.field == "spool":

        for op, obj in c.getSpool():
            if op in ['add', 'del']:
                print "%s %s" % (op, obj)
            else:
                print op

    dbi.endRequest()
def getToList():
    toList = []
    DBMgr.getInstance().startRequest()
    ch = conference.ConferenceHolder()
    c = ch.getById("0")
    toList = []
    for contrib in c.getContributionList():
        if not isinstance(contrib.getCurrentStatus(), conference.ContribStatusWithdrawn):
            for pa in contrib.getPrimaryAuthorList():
                if pa.getEmail().strip() != "" and (not pa.getEmail() in toList):
                        toList.append(pa.getEmail())
            for spk in contrib.getSpeakerList():
                if spk.getEmail().strip() != "" and (not spk.getEmail() in toList):
                        toList.append(spk.getEmail())
    DBMgr.getInstance().endRequest()
    return toList
Example #14
0
def cacheDay(dest, day):
    """
    Cache a day, by calling wget in "mirror" mode
    """

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    index = {}

    calIdx = IndexesHolder().getIndex('calendar')

    objs = calIdx.getObjectsInDay(day)

    for confId in objs:

	if confId == '': continue

        obj = ConferenceHolder().getById(confId)
        url = str(urlHandlers.UHConferenceDisplay.getURL(obj))

        savedDirs = re.match(r'http:\/\/(.*)', url).group(1).split('/')

        print "Calling wget for %s..." % url
        os.system(WGET_COMMAND % (confId, url,
                                  os.path.join(dest, confId),
                                  savedDirs[0]))

        print "done!"

        index[confId] = (os.path.join(confId,*savedDirs)+'.html', obj.getTitle())

    dbi.endRequest(False)

    return index
Example #15
0
def _run(args):
    _setup(args)

    formatter = logging.Formatter("%(asctime)s %(name)s - %(levelname)s %(filename)s:%(lineno)s: %(message)s")

    root = logging.getLogger('')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    root.addHandler(handler)

    dbi = DBMgr.getInstance(max_disconnect_poll=40)
    dbi.startRequest()

    info = HelperMaKaCInfo.getMaKaCInfoInstance()
    useRBDB = info.getRoomBookingModuleActive()

    if useRBDB:
        DALManager.connect()

    sm = SchedulerModule.getDBInstance()
    t = sm.getTaskById(args.taskid)

    t.plugLogger(logging.getLogger('console.run/%s' % args.taskid))
    t.run()

    if useRBDB:
        DALManager.commit()
        DALManager.disconnect()
    dbi.endRequest()
Example #16
0
def _stop(args):

    _setup(args)

    running = _check_running()

    if not args.force and not running:
        raise Exception("The daemon doesn't seem to be running (consider -f?)")

    dbi = DBMgr.getInstance()
    dbi.startRequest()
    c = Client()
    c.shutdown(msg = "Daemon script")
    dbi.commit()

    print "Waiting for death confirmation... "
    for i in range(0, 20):
        if not c.getStatus()['state']:
            break
        else:
            time.sleep(1)
            dbi.sync()
    else:
        print "FAILED!"

    print "DONE!"
    dbi.endRequest()
Example #17
0
 def getInstance( self ):
     dbroot = DBMgr.getInstance().getDBConnection().root()
     if dbroot.has_key("adminlist"):
         return dbroot["adminlist"]
     al = _AdminList()
     dbroot["adminlist"] = al
     return al
Example #18
0
def getSessionManager(debug=0):
    root = DBMgr.getInstance().getDBConnection().root()
    try:
        sm = root["SessionManagers"]["main"]
    except KeyError, e:
        sm = PSessionManager()
        root["SessionManagers"] = OOBTree.OOBTree()
        root["SessionManagers"]["main"] = sm
Example #19
0
    def getIdx(cls, indexName, db=None):
        if not db:
            db = DBMgr.getInstance().getDBConnection()

        if 'catalog' not in db.root():
            cls.initialize(db=db)

        return db.root()['catalog'].get(indexName)
Example #20
0
def getRepository():
        dbRoot = DBMgr.getInstance().getDBConnection().root()
        try:
            fr = dbRoot["local_repositories"]["main"]
        except KeyError, e:
            fr = fileRepository.MaterialLocalRepository()
            dbRoot["local_repositories"] = OOBTree.OOBTree()
            dbRoot["local_repositories"]["main"] = fr
Example #21
0
    def updateStatistics(cls, cat, logger=None):
        dbi = DBMgr.getInstance()

        cls._updateStatistics(cat, dbi, 0, logger)
        if logger:
            logger.info("Statistics calculation finished")

        dbi.commit()
Example #22
0
 def _getConfRegistry( self ):
     if not self._confRegistry:
         db_root = DBMgr.getInstance().getDBConnection().root()
         if db_root.has_key( "webfactoryregistry" ):
             self._confRegistry = db_root["webfactoryregistry"]
         else:
             self._confRegistry = OOBTree.OOBTree()
             db_root["webfactoryregistry"] = self._confRegistry
     return self._confRegistry
Example #23
0
 def getDBInstance(cls):
     """
     Returns the instance of SyncManager currently in the DB
     """
     storage = getPluginType().getStorage()
     if 'agent_manager' in storage:
         return storage['agent_manager']
     else:
         root = DBMgr.getInstance().getDBConnection()
         updateDBStructures(root)
Example #24
0
def _check_running():

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()
    running = c.getStatus()['state']
    dbi.endRequest()

    return running
Example #25
0
 def _process( self ):
     ih = AuthenticatorMgr()
     #first, check if login is free
     if not ih.isLoginFree(self._login):
         self._redirect(self._fromURL + "&msg=Login not avaible")
         return
     #then, check if password is OK
     if self._pwd != self._pwdBis:
         self._redirect(self._fromURL + "&msg=You must enter the same password twice")
         return
     #create the indentity
     li = user.LoginInfo( self._login, self._pwd )
     id = ih.createIdentity( li, self._avatar, self._system )
     ih.add( id )
     #commit and if OK, send activation mail
     DBMgr.getInstance().commit()
     scr = mail.sendConfirmationRequest(self._avatar)
     scr.send()
     self._redirect( urlHandlers.UHUserDetails.getURL( self._avatar ) ) #to set to the returnURL
Example #26
0
 def _getInternalPagesMgrRegistery( self ):
     #DBMgr.getInstance().commit()
     if not self._pagesMgrRegistery:
         db_root = DBMgr.getInstance().getDBConnection().root()
         if db_root.has_key( "internalPagesRegistery" ):
             self._pagesMgrRegistery = db_root["internalPagesRegistery"]
         else:
             self._pagesMgrRegistery = OOBTree.OOBTree()
             db_root["internalPagesRegistery"] = self._pagesMgrRegistery
     return self._pagesMgrRegistery
Example #27
0
    def _prepareDB(self):
        # since the DBMgr instance will be replicated across objects,
        # we just set it as None for this one.

        # first, store the server address - this wouldn't normally be needed,
        # but the tests won't work otherwise (as the DB is _not_ the default one)
        hostname, port = DBMgr._instance._db.storage._addr

        DBMgr.setInstance(DBMgr(hostname, port))
        self._dbi = DBMgr.getInstance()
def buildCache(ids):
    i = 1
    for id in ids:
        DBMgr.getInstance().startRequest()
        try:
            conf = ConferenceHolder().getById(id)
        except:
            print "conf %s not found"
            continue
        j = 1
        for cont in conf.getContributionList():
            print "conf %d:%s - contrib %d:%s"%(i, conf.getId(), j, cont.getId())
            og = outputGenerator(AccessWrapper())
            x = og.contribToXMLMarc21(cont, 1, overrideCache=True)
            for subCont in cont.getSubContributionList():
                print "conf %d:%s - contrib %d:%s - subContrib:%s"%(i, conf.getId(), j, cont.getId(), subCont.getId())
                y = og.subContribToXMLMarc21(subCont, 1, overrideCache=True)
            j += 1
        i += 1
        DBMgr.getInstance().endRequest()
Example #29
0
def getToList():
    toList = []
    DBMgr.getInstance().startRequest()
    ch = conference.ConferenceHolder()
    c = ch.getById("0")
    toList = []
    i = 0
    for contrib in c.getContributionList():
        if contrib.getPaper() == None or contrib.getPaper().getResourceList() == []:
            if not isinstance(contrib.getCurrentStatus(), conference.ContribStatusWithdrawn):
                i += 1
                for pa in contrib.getPrimaryAuthorList():
                    if pa.getEmail().strip() != "" and (not pa.getEmail() in toList):
                        toList.append(pa.getEmail())
                for spk in contrib.getSpeakerList():
                    if spk.getEmail().strip() != "" and (not spk.getEmail() in toList):
                        toList.append(spk.getEmail())
    DBMgr.getInstance().endRequest()
    print "Number of contribs without papers:%s"%i
    return toList
def changeCreator(oldUser, newUser):
    dbi = DBMgr.getInstance()

    dbi.startRequest()
    Factory.getDALManager().connect()

    # check if the users exist
    if AvatarHolder().getById(oldUser) is None:
        print "There is no user with id %s"%oldUser
        return
    if AvatarHolder().getById(newUser) is None:
        print "There is no user with id %s"%newUser
        return

    resvEx = ReservationBase()
    resvEx.createdBy = oldUser

    allResv4OldUser = CrossLocationQueries.getReservations( resvExample = resvEx)

    if allResv4OldUser == []:
        print "No reservations for user %s"%oldUser
        return

    # resvs = ReservationBase.getReservations()
    # allResv4OldUser = [x for x in allResv if x.createdBy == oldUser]

    if type(allResv4OldUser) is not list:
        allResv4OldUser = [allResv4OldUser]

    # Modify reservations
    for r in allResv4OldUser:
        r.createdBy = newUser
        #print r.createdBy, r.id

    # Update index
    userReservationsIndexBTree = Reservation.getUserReservationsIndexRoot()

    newUserResvs = userReservationsIndexBTree.get( newUser )
    if newUserResvs == None:
        newUserResvs = [] # New list of reservations for this room
        userReservationsIndexBTree.insert( newUser, newUserResvs )
    newUserResvs.extend( allResv4OldUser )
    userReservationsIndexBTree[newUser] = newUserResvs[:]

    if userReservationsIndexBTree.has_key(oldUser):
        userReservationsIndexBTree.pop(oldUser)

    userReservationsIndexBTree._p_changed = 1

    # close DB connection
    Factory.getDALManager().commit()
    Factory.getDALManager().disconnect()
    dbi.endRequest()
    print "%s reservations have moved from creator %s to creator %s" % (len(allResv4OldUser), oldUser, newUser)
Example #31
0
def updateCategsAndEvents():

    DBMgr.getInstance().startRequest()
    cm = CategoryManager()
    l = [cat.getId() for cat in cm.getList()]
    DBMgr.getInstance().endRequest()
    for id in l:
        DBMgr.getInstance().startRequest()
        cat = cm.getById(id)
        log("\nupdate category %s:%s" % (cat.getId(), cat.getName()))
        if cat.getId() in catTZMap.keys() and catTZMap[cat.getId()]:
            tz = catTZMap[cat.getId()]
            log("    found tz for this category: %s" % tz)
        else:
            tz = defTZ
            log("    use default tz: %s" % tz)
        cat.setTimezone(tz)
        updateCatTasks(cat)
        for conf in cat.getConferenceList():
            updateEvent(conf, tz)
            log("  conf %s: %s updated with tz: %s" %
                (conf.getId(), conf.getTitle(), tz))
        DBMgr.getInstance().endRequest()
Example #32
0
def runMigration(withRBDB=False,
                 prevVersion=parse_version(__version__),
                 specified=[]):

    print "\nExecuting migration...\n"

    dbi = DBMgr.getInstance()

    print "Probing DB connection...",

    # probe DB connection
    dbi.startRequest()
    dbi.endRequest(False)

    print "DONE!\n"

    # go from older to newer version and execute corresponding tasks
    for version, task, always in MIGRATION_TASKS:
        if specified and task.__name__ not in specified:
            continue
        if parse_version(version) > prevVersion or always:
            print console.colored("#", 'green', attrs=['bold']), \
                  task.__doc__.replace('\n', '').strip(),
            print console.colored("(%s)" % version, 'yellow')
            dbi.startRequest()
            if withRBDB:
                DALManager.connect()

            task(dbi, withRBDB, prevVersion)

            if withRBDB:
                DALManager.commit()
            dbi.endRequest()

            print console.colored("  DONE\n", 'green', attrs=['bold'])

    print console.colored("Database Migration successful!\n",
                          'green',
                          attrs=['bold'])
Example #33
0
def main():

    global scenarios, results

    #logger = logging.getLogger('')
    #handler = logging.StreamHandler()

    #logger.addHandler(handler)
    #logger.setLevel(logging.DEBUG)

    dirpath = tempfile.mkdtemp()

    server = TestZEOServer(12355, os.path.join(dirpath, 'data.fs'),
                           'localhost')
    server.start()

    DBMgr.setInstance(DBMgr(hostname='localhost', port=12355))

    scenarios = list((nworkers, sbatch) for nworkers in range(1, 10) \
                     for sbatch in range(100, 1100, 100))

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    runTests('pcuds86.cern.ch', 80, scenarios)

    dbi.abort()

    server.shutdown()
    DBMgr.setInstance(None)

    with open('/tmp/buploader.csv', 'w') as f:
        csvfile = csv.writer(f)

        for params, result in results.iteritems():
            csvfile.writerow(list(params) + [result])
Example #34
0
def __request(req, params, private=False):
    start = datetime.now()
    DBMgr.getInstance().startRequest()
    a = oai2.OAIResponse(req.hostname, req.uri, private)
    response = a.oaiResponseMaker(params)

    DBMgr.getInstance().abort()
    DBMgr.getInstance().endRequest()

    stop = datetime.now()
    tsec = (stop - start).seconds
    msec = (stop - start).microseconds
    min = int(tsec / 60)
    sec = tsec - min * 60

    Logger.get('oai/interface').debug(
        "from: %s request: %s responseTime: %s\n" %
        (req.connection.remote_ip, req.unparsed_uri, "%d:%d:%d" %
         (min, sec, msec)))

    req.content_type = "text/xml"  # set content type
    return response
Example #35
0
 def _prepareDB(self):
     self._dbi = DBMgr.getInstance()
Example #36
0
import sys
from pprint import pprint

from MaKaC.common import DBMgr
from MaKaC.user import AvatarHolder

from indico.util.suggestions import get_category_scores, update_event_data, iter_interesting_events

with DBMgr.getInstance().global_connection():
    # 44 is jb
    # 22116 is pedro
    # 42604 is me (adrian)
    avatar = AvatarHolder().getById(sys.argv[1] if len(sys.argv) > 1 else '42604')
    pprint(dict((' -> '.join(c.getCategoryPathTitles()), score)
                for c, score in get_category_scores(avatar, True).iteritems()))
    data = {}
    for categ, score in get_category_scores(avatar).iteritems():
        if score > 0:
            update_event_data(avatar, categ, data)
    if data:
        for event in iter_interesting_events(avatar, data):
            print repr(event)
Example #37
0
def handler(req, **params):
    ContextManager.destroy()
    logger = Logger.get('httpapi')
    path, query = req.URLFields['PATH_INFO'], req.URLFields['QUERY_STRING']
    if req.method == 'POST':
        # Convert POST data to a query string
        queryParams = dict(req.form)
        for key, value in queryParams.iteritems():
            queryParams[key] = [str(value)]
        query = urllib.urlencode(remove_lists(queryParams))
    else:
        # Parse the actual query string
        queryParams = parse_qs(query)

    dbi = DBMgr.getInstance()
    dbi.startRequest()
    minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
    if minfo.getRoomBookingModuleActive():
        Factory.getDALManager().connect()

    mode = path.split('/')[1]

    apiKey = get_query_parameter(queryParams, ['ak', 'apikey'], None)
    signature = get_query_parameter(queryParams, ['signature'])
    timestamp = get_query_parameter(queryParams, ['timestamp'],
                                    0,
                                    integer=True)
    no_cache = get_query_parameter(queryParams, ['nc', 'nocache'],
                                   'no') == 'yes'
    pretty = get_query_parameter(queryParams, ['p', 'pretty'], 'no') == 'yes'
    onlyPublic = get_query_parameter(queryParams, ['op', 'onlypublic'],
                                     'no') == 'yes'

    # Disable caching if we are not exporting
    if mode != 'export':
        no_cache = True

    # Get our handler function and its argument and response type
    func, dformat = HTTPAPIHook.parseRequest(path, queryParams)
    if func is None or dformat is None:
        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

    ak = error = result = None
    ts = int(time.time())
    typeMap = {}
    try:
        # Validate the API key (and its signature)
        ak, enforceOnlyPublic = checkAK(apiKey, signature, timestamp, path,
                                        query)
        if enforceOnlyPublic:
            onlyPublic = True
        # Create an access wrapper for the API key's user
        aw = buildAW(ak, req, onlyPublic)
        # Get rid of API key in cache key if we did not impersonate a user
        if ak and aw.getUser() is None:
            cache_key = normalizeQuery(path,
                                       query,
                                       remove=('ak', 'apiKey', 'signature',
                                               'timestamp', 'nc', 'nocache'))
        else:
            cache_key = normalizeQuery(path,
                                       query,
                                       remove=('signature', 'timestamp', 'nc',
                                               'nocache'))
            if signature:
                # in case the request was signed, store the result under a different key
                cache_key = 'signed_' + cache_key

        obj = None
        addToCache = True
        cache = GenericCache('HTTPAPI')
        cache_key = RE_REMOVE_EXTENSION.sub('', cache_key)
        if not no_cache:
            obj = cache.get(cache_key)
            if obj is not None:
                result, extra, ts, complete, typeMap = obj
                addToCache = False
        if result is None:
            # Perform the actual exporting
            res = func(aw, req)
            if isinstance(res, tuple) and len(res) == 4:
                result, extra, complete, typeMap = res
            else:
                result, extra, complete, typeMap = res, {}, True, {}
        if result is not None and addToCache:
            ttl = HelperMaKaCInfo.getMaKaCInfoInstance().getAPICacheTTL()
            cache.set(cache_key, (result, extra, ts, complete, typeMap), ttl)
    except HTTPAPIError, e:
        error = e
        if e.getCode():
            req.status = e.getCode()
            if req.status == apache.HTTP_METHOD_NOT_ALLOWED:
                req.headers_out[
                    'Allow'] = 'GET' if req.method == 'POST' else 'POST'
Example #38
0
 def setOnRunningListSince(self, dt):
     dbi = DBMgr.getInstance()
     self.onRunningListSince = dt
     dbi.commit()
Example #39
0
 def run(self):
     dbi = DBMgr.getInstance()
     delete_web_sessions(dbi, self.getLogger())
Example #40
0
def handler(req, **params):
    ContextManager.destroy()
    logger = Logger.get('httpapi')
    path, query = req.URLFields['PATH_INFO'], req.URLFields['QUERY_STRING']
    if req.method == 'POST':
        # Convert POST data to a query string
        queryParams = dict(req.form)
        for key, value in queryParams.iteritems():
            queryParams[key] = [str(value)]
        query = urllib.urlencode(remove_lists(queryParams))
    else:
        # Parse the actual query string
        queryParams = parse_qs(query)

    dbi = DBMgr.getInstance()
    dbi.startRequest()
    minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
    if minfo.getRoomBookingModuleActive():
        Factory.getDALManager().connect()

    apiKey = get_query_parameter(queryParams, ['ak', 'apikey'], None)
    cookieAuth = get_query_parameter(queryParams, ['ca', 'cookieauth'], 'no') == 'yes'
    signature = get_query_parameter(queryParams, ['signature'])
    timestamp = get_query_parameter(queryParams, ['timestamp'], 0, integer=True)
    noCache = get_query_parameter(queryParams, ['nc', 'nocache'], 'no') == 'yes'
    pretty = get_query_parameter(queryParams, ['p', 'pretty'], 'no') == 'yes'
    onlyPublic = get_query_parameter(queryParams, ['op', 'onlypublic'], 'no') == 'yes'
    onlyAuthed = get_query_parameter(queryParams, ['oa', 'onlyauthed'], 'no') == 'yes'

    # Get our handler function and its argument and response type
    hook, dformat = HTTPAPIHook.parseRequest(path, queryParams)
    if hook is None or dformat is None:
        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

    # Disable caching if we are not just retrieving data (or the hook requires it)
    if req.method == 'POST' or hook.NO_CACHE:
        noCache = True

    ak = error = result = None
    ts = int(time.time())
    typeMap = {}
    try:
        session = None
        if cookieAuth:
            session = getSessionForReq(req)
            if not session.getUser():  # ignore guest sessions
                session = None

        if apiKey or not session:
            # Validate the API key (and its signature)
            ak, enforceOnlyPublic = checkAK(apiKey, signature, timestamp, path, query)
            if enforceOnlyPublic:
                onlyPublic = True
            # Create an access wrapper for the API key's user
            aw = buildAW(ak, req, onlyPublic)
            # Get rid of API key in cache key if we did not impersonate a user
            if ak and aw.getUser() is None:
                cacheKey = normalizeQuery(path, query,
                                          remove=('ak', 'apiKey', 'signature', 'timestamp', 'nc', 'nocache',
                                                  'oa', 'onlyauthed'))
            else:
                cacheKey = normalizeQuery(path, query,
                                          remove=('signature', 'timestamp', 'nc', 'nocache', 'oa', 'onlyauthed'))
                if signature:
                    # in case the request was signed, store the result under a different key
                    cacheKey = 'signed_' + cacheKey
        else:
            # We authenticated using a session cookie.
            if Config.getInstance().getCSRFLevel() >= 2:
                token = req.headers_in.get('X-CSRF-Token', get_query_parameter(queryParams, ['csrftoken']))
                if session.csrf_token != token:
                    raise HTTPAPIError('Invalid CSRF token', apache.HTTP_FORBIDDEN)
            aw = AccessWrapper()
            if not onlyPublic:
                aw.setUser(session.getUser())
            userPrefix = 'user-' + session.getUser().getId() + '_'
            cacheKey = userPrefix + normalizeQuery(path, query,
                                                   remove=('nc', 'nocache', 'ca', 'cookieauth', 'oa', 'onlyauthed',
                                                           'csrftoken'))

        # Bail out if the user requires authentication but is not authenticated
        if onlyAuthed and not aw.getUser():
            raise HTTPAPIError('Not authenticated', apache.HTTP_FORBIDDEN)

        obj = None
        addToCache = not hook.NO_CACHE
        cache = GenericCache('HTTPAPI')
        cacheKey = RE_REMOVE_EXTENSION.sub('', cacheKey)
        if not noCache:
            obj = cache.get(cacheKey)
            if obj is not None:
                result, extra, ts, complete, typeMap = obj
                addToCache = False
        if result is None:
            # Perform the actual exporting
            res = hook(aw, req)
            if isinstance(res, tuple) and len(res) == 4:
                result, extra, complete, typeMap = res
            else:
                result, extra, complete, typeMap = res, {}, True, {}
        if result is not None and addToCache:
            ttl = HelperMaKaCInfo.getMaKaCInfoInstance().getAPICacheTTL()
            cache.set(cacheKey, (result, extra, ts, complete, typeMap), ttl)
    except HTTPAPIError, e:
        error = e
        if e.getCode():
            req.status = e.getCode()
            if req.status == apache.HTTP_METHOD_NOT_ALLOWED:
                req.headers_out['Allow'] = 'GET' if req.method == 'POST' else 'POST'
Example #41
0
class RH(RequestHandlerBase):
    """This class is the base for request handlers of the application. A request
        handler will be instantiated when a web request arrives to mod_python;
        the mp layer will forward the request to the corresponding request
        handler which will know which action has to be performed (displaying a
        web page or performing some operation and redirecting to another page).
        Request handlers will be responsible for parsing the parameters coming
        from a mod_python request, handle the errors which occurred during the
        action to perform, managing the sessions, checking security for each
        operation (thus they implement the access control system of the web
        interface).
        It is important to encapsulate all this here as in case of changing
        the web application framework we'll just need to adapt this layer (the
        rest of the system wouldn't need any change).

        Attributes:
            _uh - (URLHandler) Associated URLHandler which points to the
                current rh.
            _req - (mod_python.Request) mod_python request received for the
                current rh.
            _requestStarted - (bool) Flag which tells whether a DB transaction
                has been started or not.
            _websession - ( webinterface.session.sessionManagement.PSession )
                Web session associated to the HTTP request.
            _aw - (AccessWrapper) Current access information for the rh.
            _target - (Locable) Reference to an object which is the destination
                of the operations needed to carry out the rh. If set it must
                provide (through the standard Locable interface) the methods
                to get the url parameters in order to reproduce the access to
                the rh.
            _reqParams - (dict) Dictionary containing the received HTTP
                 parameters (independently of the method) transformed into
                 python data types. The key is the parameter name while the
                 value should be the received paramter value (or values).
    """
    _tohttps = False  # set this value to True for the RH that must be HTTPS when there is a BaseSecureURL
    _doNotSanitizeFields = []

    def __init__(self, req):
        """Constructor. Initialises the rh setting up basic attributes so it is
            able to process the request.

            Parameters:
                req - (mod_python.Request) mod_python request received for the
                    current rh.
        """
        RequestHandlerBase.__init__(self, req)
        self._requestStarted = False
        self._websession = None
        self._aw = AccessWrapper(
        )  #Fill in the aw instance with the current information
        self._target = None
        self._reqParams = {}
        self._startTime = None
        self._endTime = None
        self._tempFilesToDelete = []
        self._doProcess = True  #Flag which indicates whether the RH process
        #   must be carried out; this is useful for
        #   the checkProtection methods when they
        #   detect that an inmediate redirection is
        #   needed

    # Methods =============================================================

    def getTarget(self):
        return self._target

    def _setSession(self):
        """Sets up a reference to the corresponding web session. It uses the
            session manager to retrieve the session corresponding to the
            received request and makes sure it is a valid one. In case of having
            an invalid session it reset client settings and creates a new one.
       """
        if not self._websession:
            sm = session.getSessionManager()
            try:
                self._websession = sm.get_session(self._req)
            except session.SessionError:
                sm.revoke_session_cookie(self._req)
                self._websession = sm.get_session(self._req)

    def _getSession(self):
        """Returns the web session associated to the received mod_python
            request.
        """
        if not self._websession:
            self._setSession()
        return self._websession

    def _setSessionUser(self):
        """
        """
        self._aw.setUser(self._getSession().getUser())

    def _getRequestParams(self):
        return self._reqParams

    def getRequestParams(self):
        return self._getRequestParams()

    def _disableCaching(self):
        """
        Disables caching, i.e. for materials
        """

        # IE doesn't seem to like 'no-cache' Cache-Control headers...
        if (re.match(r'.*MSIE.*', self._req.headers_in.get("User-Agent", ""))):
            # actually, the only way to safely disable caching seems to be this one
            self._req.headers_out["Cache-Control"] = "private"
            self._req.headers_out["Expires"] = "-1"
        else:
            self._req.headers_out[
                "Cache-Control"] = "no-store, no-cache, must-revalidate"
            self._req.headers_out["Pragma"] = "no-cache"

    def _redirect(self,
                  targetURL,
                  noCache=False,
                  status=apache.HTTP_SEE_OTHER):
        """Utility for redirecting the client web browser to the specified
            URL.
            Params:
                newURL - Target URL of the redirection
        """
        #check if there is no \r\n character to avoid http header injection

        if str(targetURL):
            if "\r" in str(targetURL) or "\n" in str(targetURL):
                raise MaKaCError(_("http header CRLF injection detected"))
        self._req.headers_out["Location"] = str(targetURL)

        if noCache:
            self._disableCaching()
        try:
            self._req.status = status
        except NameError:
            pass

    def _checkHttpsRedirect(self):
        """
        If HTTPS must be used but it is not, redirect!
        """
        if self.use_https() and not self._req.is_https():
            self._redirect(self.getRequestURL(secure=True))
            return True
        else:
            return False

    def _normaliseListParam(self, param):
        if not isinstance(param, list):
            return [param]
        return param

    def _processError(self, ex):
        """
        """
        raise

    def _checkParams(self, params):
        """
        """
        pass

    def _process(self):
        """
        """
        pass

    def _processGeneralError(self, e):
        """Treats general errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info('Request %s finished with: "%s"' %
                                          (id(self._req), e))

        p = errors.WPGenericError(self)
        return p.display()

    def _processUnexpectedError(self, e):
        """Unexpected errors
        """

        Logger.get('requestHandler').exception('Request %s failed: "%s"' %
                                               (id(self._req), e))
        p = errors.WPUnexpectedError(self)
        return p.display()

    def _processHostnameResolveError(self, e):
        """Unexpected errors
        """

        Logger.get('requestHandler').exception('Request %s failed: "%s"' %
                                               (id(self._req), e))
        p = errors.WPHostnameResolveError(self)
        return p.display()

    def _processAccessError(self, e):
        """Treats access errors occured during the process of a RH.
        """
        Logger.get('requestHandler').info(
            'Request %s finished with AccessError: "%s"' % (id(self._req), e))

        self._req.status = apache.HTTP_FORBIDDEN
        p = errors.WPAccessError(self)
        return p.display()

    def _processKeyAccessError(self, e):
        """Treats access errors occured during the process of a RH.
        """
        Logger.get('requestHandler').info(
            'Request %s finished with KeyAccessError: "%s"' %
            (id(self._req), e))

        self._req.status = apache.HTTP_FORBIDDEN
        # We are going to redirect to the page asking for access key
        # and so it must be https if there is a BaseSecureURL. And that's
        # why we set _tohttps to True.
        self._tohttps = True
        if self._checkHttpsRedirect():
            return
        p = errors.WPKeyAccessError(self)
        return p.display()

    def _processModificationError(self, e):
        """Treats modification errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info(
            'Request %s finished with ModificationError: "%s"' %
            (id(self._req), e))

        p = errors.WPModificationError(self)
        return p.display()

    def _processConferenceClosedError(self, e):
        """Treats access to modification pages for conferences when they are closed.
        """
        p = WPConferenceModificationClosed(self, e._conf)
        return p.display()

    def _processTimingError(self, e):
        """Treats timing errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info(
            'Request %s finished with TimingError: "%s"' % (id(self._req), e))

        p = errors.WPTimingError(self, e)
        return p.display()

    def _processNoReportError(self, e):
        """Process errors without reporting
        """

        Logger.get('requestHandler').info(
            'Request %s finished with NoReportError: "%s"' %
            (id(self._req), e))

        p = errors.WPNoReportError(self, e)
        return p.display()

    def _processNotFoundError(self, e):
        """Process not found error; uses NoReportError template
        """

        Logger.get('requestHandler').info(
            'Request %s finished with NotFoundError: "%s"' %
            (id(self._req), e))

        try:
            self._req.status = apache.HTTP_NOT_FOUND
        except NameError:
            pass

        p = errors.WPNoReportError(self, e)
        return p.display()

    def _processParentTimingError(self, e):
        """Treats timing errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info(
            'Request %s finished with ParentTimingError: "%s"' %
            (id(self._req), e))

        p = errors.WPParentTimingError(self, e)
        return p.display()

    def _processEntryTimingError(self, e):
        """Treats timing errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info(
            'Request %s finished with EntryTimingError: "%s"' %
            (id(self._req), e))

        p = errors.WPEntryTimingError(self, e)
        return p.display()

    def _processFormValuesError(self, e):
        """Treats user input related errors occured during the process of a RH.
        """

        Logger.get('requestHandler').info(
            'Request %s finished with FormValuesError: "%s"' %
            (id(self._req), e))

        p = errors.WPFormValuesError(self, e)
        return p.display()

    def _processHtmlScriptError(self, e):

        Logger.get('requestHandler').info(
            'Request %s finished with ProcessHtmlScriptError: "%s"' %
            (id(self._req), e))

        p = errors.WPHtmlScriptError(self, escape(str(e)))
        return p.display()

    def _processRestrictedHTML(self, e):

        Logger.get('requestHandler').info(
            'Request %s finished with ProcessRestrictedHTMLError: "%s"' %
            (id(self._req), e))

        p = errors.WPRestrictedHTML(self, escape(str(e)))
        return p.display()

    def process(self, params):
        """
        """
        profile = Config.getInstance().getProfile()
        proffilename = ""
        res = ""
        MAX_RETRIES = 10
        retry = MAX_RETRIES
        textLog = []
        self._startTime = datetime.now()

        # clear the context
        ContextManager.destroy()
        ContextManager.set('currentRH', self)

        #redirect to https if necessary
        if self._checkHttpsRedirect():
            return

        DBMgr.getInstance().startRequest()
        self._startRequestSpecific2RH(
        )  # I.e. implemented by Room Booking request handlers
        textLog.append("%s : Database request started" %
                       (datetime.now() - self._startTime))
        Logger.get('requestHandler').info(
            '[pid=%s] Request %s started (%s)' %
            (os.getpid(), id(self._req), self._req.unparsed_uri))

        # notify components that the request has started
        self._notify('requestStarted', self._req)

        forcedConflicts = Config.getInstance().getForceConflicts()
        try:
            while retry > 0:

                if retry < MAX_RETRIES:
                    # notify components that the request is being retried
                    self._notify('requestRetry', self._req,
                                 MAX_RETRIES - retry)

                try:
                    Logger.get('requestHandler').info(
                        '\t[pid=%s] from host %s' %
                        (os.getpid(), self.getHostIP()))
                    try:
                        # clear the fossile cache at the start of each request
                        fossilize.clearCache()
                        # delete all queued emails
                        GenericMailer.flushQueue(False)

                        DBMgr.getInstance().sync()
                        # keep a link to the web session in the access wrapper
                        # this is used for checking access/modification key existence
                        # in the user session
                        self._aw.setIP(self.getHostIP())
                        self._aw.setSession(self._getSession())
                        #raise(str(dir(self._websession)))
                        self._setSessionUser()
                        self._setLang(params)
                        if self._getAuth():
                            if self._getUser():
                                Logger.get('requestHandler').info(
                                    'Request %s identified with user %s (%s)' %
                                    (id(self._req),
                                     self._getUser().getFullName(),
                                     self._getUser().getId()))
                            if not self._tohttps and Config.getInstance(
                            ).getAuthenticatedEnforceSecure():
                                self._tohttps = True
                                if self._checkHttpsRedirect():
                                    return

                        #if self._getUser() != None and self._getUser().getId() == "893":
                        #    profile = True
                        self._reqParams = copy.copy(params)
                        self._checkParams(self._reqParams)

                        self._checkProtection()
                        security.Sanitization.sanitizationCheck(
                            self._target, self._reqParams, self._aw,
                            self._doNotSanitizeFields)
                        if self._doProcess:
                            if profile:
                                import profile, pstats
                                proffilename = os.path.join(
                                    Config.getInstance().getTempDir(),
                                    "stone%s.prof" % str(random.random()))
                                result = [None]
                                profile.runctx("result[0] = self._process()",
                                               globals(), locals(),
                                               proffilename)
                                res = result[0]
                            else:
                                res = self._process()

                        # Save web session, just when needed
                        sm = session.getSessionManager()
                        sm.maintain_session(self._req, self._websession)

                        # notify components that the request has finished
                        self._notify('requestFinished', self._req)
                        # Raise a conflict error if enabled. This allows detecting conflict-related issues easily.
                        if retry > (MAX_RETRIES - forcedConflicts):
                            raise ConflictError
                        self._endRequestSpecific2RH(
                            True
                        )  # I.e. implemented by Room Booking request handlers
                        DBMgr.getInstance().endRequest(True)

                        Logger.get('requestHandler').info(
                            'Request %s successful' % (id(self._req)))
                        #request succesfull, now, doing tas that must be done only once
                        try:
                            GenericMailer.flushQueue(True)  # send emails
                            self._deleteTempFiles()
                        except:
                            Logger.get('mail').exception(
                                'Mail sending operation failed')
                            pass
                        break
                    except MaKaCError, e:
                        #DBMgr.getInstance().endRequest(False)
                        res = self._processError(e)
                except (ConflictError, POSKeyError):
                    import traceback
                    # only log conflict if it wasn't forced
                    if retry <= (MAX_RETRIES - forcedConflicts):
                        Logger.get('requestHandler').warning(
                            'Conflict in Database! (Request %s)\n%s' %
                            (id(self._req), traceback.format_exc()))
                    self._abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    continue
                except ClientDisconnected:
                    Logger.get('requestHandler').warning(
                        'Client Disconnected! (Request %s)' % id(self._req))
                    self._abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    time.sleep(10 - retry)
                    continue
        except KeyAccessError, e:
            #Key Access error treatment
            res = self._processKeyAccessError(e)
            self._endRequestSpecific2RH(False)
            DBMgr.getInstance().endRequest(False)
        except AccessError, e:
            #Access error treatment
            res = self._processAccessError(e)
            self._endRequestSpecific2RH(False)
            DBMgr.getInstance().endRequest(False)
Example #42
0
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.common import DBMgr
from MaKaC.common.indexes import IndexesHolder
from indico.core.index import Catalog

if __name__ == '__main__':

    dbi = DBMgr.getInstance()

    dbi.startRequest()

    for idx_name in ['categ_conf_sd']:
        idx = Catalog.getIdx(idx_name)
        for problem in idx._check(dbi=dbi):
            print "[%s] %s" % (idx_name, problem)

    for idx_name in ['category', 'calendar', 'categoryDate']:
        idx = IndexesHolder().getIndex(idx_name)
        for problem in idx._check(dbi=dbi):
            print "[%s] %s" % (idx_name, problem)

    dbi.endRequest()
Example #43
0
def teardown_module():
    DBMgr.getInstance().abort()
    DBMgr.getInstance().endRequest()
Example #44
0
def setup_module():
    DBMgr.getInstance().startRequest()
Example #45
0
def main(argv):
    category = -1
    meeting = -1
    show = 0

    ContextManager.create()

    try:
        opts, args = getopt.getopt(argv, "hm:c:s",
                                   ["help", "meeting=", "category=", "show"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-s", "--show"):
            show = 1
        elif opt in ("-m", "--meeting"):
            meeting = arg
        elif opt in ("-c", "--category"):
            category = arg

    # Create database instance and open trashcan manager object
    DBMgr.getInstance().startRequest()
    t = TrashCanManager()
    conf = None
    if (show):
        for i in t.getList():
            if isinstance(i, Conference):
                if meeting != -1 and i.getId() == meeting:
                    print "[%s]%s" % (i.getId(), i.getTitle())
                elif meeting == -1:
                    print "[%s]%s" % (i.getId(), i.getTitle())
        sys.exit()

    if (meeting != -1 and category != -1):

        print "Meeting:%s" % meeting
        print "Category:%s" % category
        for i in t.getList():
            if isinstance(i, Conference):
                if i.getId() == meeting:
                    conf = i
                    break

        if conf:
            DBMgr.getInstance().sync()

            with RequestListenerContext():

                # Remove meeting from the TrashCanManager
                t.remove(conf)
                # Attach meeting to desired category
                cat = CategoryManager().getById(category)
                ConferenceHolder().add(conf)
                cat._addConference(conf)

                # Add Evaluation
                c = ConferenceHolder().getById(meeting)
                from MaKaC.evaluation import Evaluation
                c.setEvaluations([Evaluation(c)])

                # indexes
                c.indexConf()
                c._notify('created', cat)

                for contrib in c.getContributionList():
                    contrib._notify('created', c)
        else:
            print "not found!"

        DBMgr.getInstance().endRequest()

    ContextManager.destroy()
Example #46
0
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

import recovery
from MaKaC.common import DBMgr
from MaKaC import conference
from datetime import datetime

eventId = "5705"
date = datetime(2006, 10, 4, 23, 0)

ch = conference.ConferenceHolder()
dbm = DBMgr.getInstance()
dbm.startRequest()
c = ch.getById(eventId)
cr = recovery.ParticipantRecovery(c)
cr.proceed(date)
Example #47
0
def registerHelpers(objDict):
    """
    Adds helper methods to the dictionary.
    Does it only if symbol does not exist - backward compatibility.
    """
    if not 'contextHelp' in objDict:
        objDict['contextHelp'] = contextHelp
    if not 'inlineContextHelp' in objDict:
        objDict['inlineContextHelp'] = inlineContextHelp
    if not 'escapeAttrVal' in objDict:
        objDict['escapeAttrVal'] = escapeAttrVal
    if not 'escape' in objDict:
        objDict['escape'] = escape
    if not 'quoteattr' in objDict:
        objDict['quoteattr'] = quoteattr
    if not 'verbose' in objDict:
        objDict['verbose'] = verbose
    if not 'verbose_dt' in objDict:
        objDict['verbose_dt'] = verbose_dt
    if not 'verbose_t' in objDict:
        objDict['verbose_t'] = verbose_t
    if not 'dequote' in objDict:
        objDict['dequote'] = dequote
    if not 'formatTime' in objDict:
        objDict['formatTime'] = formatTime
    if not 'formatDate' in objDict:
        objDict['formatDate'] = formatDate
    if not 'systemIcon' in objDict:
        objDict['systemIcon'] = systemIcon
    if not 'formatDateTime' in objDict:
        objDict['formatDateTime'] = formatDateTime
    if not 'linkify' in objDict:
        objDict['linkify'] = linkify
    if not 'truncateTitle' in objDict:
        objDict['truncateTitle'] = truncateTitle
    if not 'urlHandlers' in objDict:
        objDict['urlHandlers'] = MaKaC.webinterface.urlHandlers
    if not 'Config' in objDict:
        objDict['Config'] = MaKaC.common.Configuration.Config
    if not 'jsBoolean' in objDict:
        objDict['jsBoolean'] = jsBoolean
    if not 'offlineRequest' in objDict:
        from MaKaC.services.interface.rpc.offline import offlineRequest
        objDict['offlineRequest'] = offlineRequest
    if not 'jsonDescriptor' in objDict:
        from MaKaC.services.interface.rpc.offline import jsonDescriptor
        objDict['jsonDescriptor'] = jsonDescriptor
    if not 'jsonDescriptorType' in objDict:
        from MaKaC.services.interface.rpc.offline import jsonDescriptorType
        objDict['jsonDescriptorType'] = jsonDescriptorType
    if not 'jsonEncode' in objDict:
        from MaKaC.services.interface.rpc.json import encode as jsonEncode
        objDict['jsonEncode'] = jsonEncode
    if not 'roomInfo' in objDict:
        from MaKaC.services.interface.rpc.offline import roomInfo
        objDict['roomInfo'] = roomInfo
    if not 'roomBookingActive' in objDict:
        if DBMgr.getInstance().isConnected():
            minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()
            objDict['roomBookingActive'] = minfo.getRoomBookingModuleActive()
    if not 'user' in objDict:
        if not '__rh__' in objDict or not objDict['__rh__']:
            objDict[
                'user'] = "******"
        else:
            objDict['user'] = objDict['__rh__']._getUser(
            )  # The '__rh__' is set by framework
    if 'rh' not in objDict and '__rh__' in objDict:
        objDict['rh'] = objDict['__rh__']
    if not roomClass in objDict:
        objDict['roomClass'] = roomClass
    if not 'systemIcon' in objDict:
        objDict['systemIcon'] = systemIcon
    if not 'iconFileName' in objDict:
        objDict['iconFileName'] = iconFileName
    if not 'escapeHTMLForJS' in objDict:
        objDict['escapeHTMLForJS'] = escapeHTMLForJS
    if not 'deepstr' in objDict:
        objDict['deepstr'] = deepstr
    if not 'beautify' in objDict:
        objDict['beautify'] = beautify
    # allow fossilization
    if not 'fossilize' in objDict:
        from MaKaC.common.fossilize import fossilize
        objDict['fossilize'] = fossilize
    if not 'N_' in objDict:
        objDict['N_'] = ngettext
    if not 'format_number' in objDict:
        objDict['format_number'] = format_number
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.common import DBMgr
from MaKaC.conference import ConferenceHolder

CONFID='XXXXX'  # Replace XXXX with the ID of your conference.

DBMgr.getInstance().startRequest()

c=ConferenceHolder().getById(CONFID)

for contrib in c.getContributionList():
    contrib._submittersEmail=map(lambda x: x.lower(),contrib.getSubmitterEmailList())

DBMgr.getInstance().commit()
DBMgr.getInstance().sync()

for contrib in c.getContributionList():
    for email in contrib.getSubmitterEmailList():
        email=email.lower()
        res=AvatarHolder().match({'email':email})
        if len(res)==1:
            contrib.grantSubmission(res[0])
Example #49
0
    def process(self, params):
        """
        """
        profile = Config.getInstance().getProfile()
        proffilename = ""
        res = ""
        MAX_RETRIES = 10
        retry = MAX_RETRIES
        textLog = []
        self._startTime = datetime.now()

        # clear the context
        ContextManager.destroy()
        ContextManager.set('currentRH', self)

        #redirect to https if necessary
        if self._checkHttpsRedirect():
            return

        DBMgr.getInstance().startRequest()
        self._startRequestSpecific2RH(
        )  # I.e. implemented by Room Booking request handlers
        textLog.append("%s : Database request started" %
                       (datetime.now() - self._startTime))
        Logger.get('requestHandler').info(
            '[pid=%s] Request %s started (%s)' %
            (os.getpid(), id(self._req), self._req.unparsed_uri))

        # notify components that the request has started
        self._notify('requestStarted', self._req)

        forcedConflicts = Config.getInstance().getForceConflicts()
        try:
            while retry > 0:

                if retry < MAX_RETRIES:
                    # notify components that the request is being retried
                    self._notify('requestRetry', self._req,
                                 MAX_RETRIES - retry)

                try:
                    Logger.get('requestHandler').info(
                        '\t[pid=%s] from host %s' %
                        (os.getpid(), self.getHostIP()))
                    try:
                        # clear the fossile cache at the start of each request
                        fossilize.clearCache()
                        # delete all queued emails
                        GenericMailer.flushQueue(False)

                        DBMgr.getInstance().sync()
                        # keep a link to the web session in the access wrapper
                        # this is used for checking access/modification key existence
                        # in the user session
                        self._aw.setIP(self.getHostIP())
                        self._aw.setSession(self._getSession())
                        #raise(str(dir(self._websession)))
                        self._setSessionUser()
                        self._setLang(params)
                        if self._getAuth():
                            if self._getUser():
                                Logger.get('requestHandler').info(
                                    'Request %s identified with user %s (%s)' %
                                    (id(self._req),
                                     self._getUser().getFullName(),
                                     self._getUser().getId()))
                            if not self._tohttps and Config.getInstance(
                            ).getAuthenticatedEnforceSecure():
                                self._tohttps = True
                                if self._checkHttpsRedirect():
                                    return

                        #if self._getUser() != None and self._getUser().getId() == "893":
                        #    profile = True
                        self._reqParams = copy.copy(params)
                        self._checkParams(self._reqParams)

                        self._checkProtection()
                        security.Sanitization.sanitizationCheck(
                            self._target, self._reqParams, self._aw,
                            self._doNotSanitizeFields)
                        if self._doProcess:
                            if profile:
                                import profile, pstats
                                proffilename = os.path.join(
                                    Config.getInstance().getTempDir(),
                                    "stone%s.prof" % str(random.random()))
                                result = [None]
                                profile.runctx("result[0] = self._process()",
                                               globals(), locals(),
                                               proffilename)
                                res = result[0]
                            else:
                                res = self._process()

                        # Save web session, just when needed
                        sm = session.getSessionManager()
                        sm.maintain_session(self._req, self._websession)

                        # notify components that the request has finished
                        self._notify('requestFinished', self._req)
                        # Raise a conflict error if enabled. This allows detecting conflict-related issues easily.
                        if retry > (MAX_RETRIES - forcedConflicts):
                            raise ConflictError
                        self._endRequestSpecific2RH(
                            True
                        )  # I.e. implemented by Room Booking request handlers
                        DBMgr.getInstance().endRequest(True)

                        Logger.get('requestHandler').info(
                            'Request %s successful' % (id(self._req)))
                        #request succesfull, now, doing tas that must be done only once
                        try:
                            GenericMailer.flushQueue(True)  # send emails
                            self._deleteTempFiles()
                        except:
                            Logger.get('mail').exception(
                                'Mail sending operation failed')
                            pass
                        break
                    except MaKaCError, e:
                        #DBMgr.getInstance().endRequest(False)
                        res = self._processError(e)
                except (ConflictError, POSKeyError):
                    import traceback
                    # only log conflict if it wasn't forced
                    if retry <= (MAX_RETRIES - forcedConflicts):
                        Logger.get('requestHandler').warning(
                            'Conflict in Database! (Request %s)\n%s' %
                            (id(self._req), traceback.format_exc()))
                    self._abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    continue
                except ClientDisconnected:
                    Logger.get('requestHandler').warning(
                        'Client Disconnected! (Request %s)' % id(self._req))
                    self._abortSpecific2RH()
                    DBMgr.getInstance().abort()
                    retry -= 1
                    time.sleep(10 - retry)
                    continue
        except KeyAccessError, e:
            #Key Access error treatment
            res = self._processKeyAccessError(e)
            self._endRequestSpecific2RH(False)
            DBMgr.getInstance().endRequest(False)
Example #50
0
def run4eachConfFast():
    DBMgr.getInstance().startRequest()
    ch = ConferenceHolder()
    for conf in ch.getList():
        moveLogoToDisplayMgr(conf)
    DBMgr.getInstance().endRequest()
Example #51
0
             time.sleep(10 - retry)
             continue
 except KeyAccessError, e:
     #Key Access error treatment
     res = self._processKeyAccessError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
 except AccessError, e:
     #Access error treatment
     res = self._processAccessError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
 except HostnameResolveError, e:
     res = self._processHostnameResolveError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
 except ModificationError, e:
     #Modification error treatment
     res = self._processModificationError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
 except ParentTimingError, e:
     #Modification error treatment
     res = self._processParentTimingError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
 except EntryTimingError, e:
     #Modification error treatment
     res = self._processEntryTimingError(e)
     self._endRequestSpecific2RH(False)
     DBMgr.getInstance().endRequest(False)
Example #52
0
def updateOAIIndexes():
    DBMgr.getInstance().startRequest()
    ch = ConferenceHolder()
    ih = indexes.IndexesHolder()
    catIdx = ih.getById("category")
    confIdx = ih.getById("OAIConferenceModificationDate")
    contIdx = ih.getById("OAIContributionModificationDate")
    confIdxPr = ih.getById("OAIPrivateConferenceModificationDate")
    contIdxPr = ih.getById("OAIPrivateContributionModificationDate")
    confIdx.initIndex()
    contIdx.initIndex()
    confIdxPr.initIndex()
    contIdxPr.initIndex()
    DBMgr.getInstance().commit()
    log("Count conferences...")
    ids = catIdx.getItems('0')
    totalConf = len(ids)
    log("%d conferences found" % totalConf)
    ic = 1
    DBMgr.getInstance().sync()
    DBMgr.getInstance().endRequest()
    i = 0
    pubConf = 0
    privConf = 0
    while ids:
        if len(ids) >= 10:
            lids = ids[:10]
            del ids[:10]
        else:
            lids = ids
            ids = None
        startic = ic
        startPubConf = pubConf
        startPrivConf = privConf
        for j in range(10):
            try:
                DBMgr.getInstance().startRequest()
                for id in lids:
                    conf = ch.getById(id)
                    confIdx = ih.getById("OAIConferenceModificationDate")
                    contIdx = ih.getById("OAIContributionModificationDate")
                    confIdxPr = ih.getById(
                        "OAIPrivateConferenceModificationDate")
                    contIdxPr = ih.getById(
                        "OAIPrivateContributionModificationDate")
                    log("Index conference %s: %d on %d" % (id, ic, totalConf))
                    ic += 1
                    if conf.hasAnyProtection():
                        confIdxPr.indexConference(conf)
                        privConf += 1
                    else:
                        confIdx.indexConference(conf)
                        pubConf += 1
                    for cont in conf.getContributionList():
                        if cont.hasAnyProtection():
                            contIdxPr.indexContribution(cont)
                        else:
                            contIdx.indexContribution(cont)
                        for sc in cont.getSubContributionList():
                            if cont.isProtected():
                                contIdxPr.indexContribution(sc)
                            else:
                                contIdx.indexContribution(sc)
                DBMgr.getInstance().endRequest()
                log("wait 0.5s...")
                sleep(0.5)
                break
            except Exception, e:
                log("error %s, retry %d time(s)" % (e, int(10 - j)))
                sleep(int(j))
                ic = startic
                pubConf = startPubConf
                privConf = startPrivConf
                DBMgr.getInstance().abort()
Example #53
0
# -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.common import DBMgr

DBMgr.getInstance().pack(days=1)

Example #54
0
    for dom in catalog.dump():
        dh._getIdx()[dom.getId()] = dom
        count += 1
    print "[Done:%s]" % count


def migrateConferences(catalog):
    print "Migrating Conferences...",
    ch = ConferenceHolder()
    count = 0
    for conf in catalog.dump():
        ch._getIdx()[conf.getId()] = conf
        count += 1
    print "[Done:%s]" % count


from MaKaC.common import DBMgr

DBMgr.getInstance().startRequest()
root = DBMgr.getInstance().getDBConnection().root()
migrateAvatars(root["Catalogs"]["MaKaC.user.Avatar"])
migrateGroups(root["Catalogs"]["MaKaC.user.Group"])
migrateDomains(root["Catalogs"]["MaKaC.domain.Domain"])
migrateConferences(root["Catalogs"]["MaKaC.conference.Conference"])
del root["Catalogs"]
del root["_ic_registry"]
del root["first time"]
from MaKaC.conference import CategoryManager
CategoryManager().getRoot()._reIndex()
DBMgr.getInstance().endRequest()
Example #55
0
# -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

import sys
sys.path.append("c:/development/indico/code/code")

from MaKaC.common import DBMgr
from MaKaC import conference

DBMgr.getInstance().startRequest()
conference.CategoryManager().getRoot()._setNumConferences()
DBMgr.getInstance().endRequest()

Example #56
0
    registrants = linkedTo['registration']

    for registrantRole in registrants:
        for reg in registrants[registrantRole]:
            try:
                confHolder.getById(reg.getConference().getId())
            except:
                registrants[registrantRole].remove(reg)
                fixes += 1

    # rebuild the TLE table
    user.resetTimedLinkedEvents()


try:
    DBMgr.getInstance().startRequest()

    ah = user.AvatarHolder()
    ch = conference.ConferenceHolder()
    list = ah.getList()

    totalUsers = len(list)

    print totalUsers, 'registers'

    count = 0

    for user in ah.getList():
        count += 1
        percent_show(count, totalUsers)
        try:
Example #57
0
 def _process(self):
     save = False
     ih = AuthenticatorMgr()
     minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()
     self._params["msg"] = ""
     if self._save:
         save = True
         #check submited data
         if not self._params.get("name", ""):
             self._params["msg"] += _("You must enter a name.") + "<br>"
             save = False
         if not self._params.get("surName", ""):
             self._params["msg"] += _("You must enter a surname.") + "<br>"
             save = False
         if not self._params.get("organisation", ""):
             self._params["msg"] += _(
                 "You must enter the name of your organisation.") + "<br>"
             save = False
         if not self._params.get("email", ""):
             self._params["msg"] += _(
                 "You must enter an email address.") + "<br>"
             save = False
         if not self._params.get("login", ""):
             self._params["msg"] += _("You must enter a login.") + "<br>"
             save = False
         if not self._params.get("password", ""):
             self._params["msg"] += _(
                 "You must define a password.") + "<br>"
             save = False
         if self._params.get("password", "") != self._params.get(
                 "passwordBis", ""):
             self._params["msg"] += _(
                 "You must enter the same password twice.") + "<br>"
             save = False
         if not ih.isLoginFree(self._params.get("login", "")):
             self._params["msg"] += _(
                 "Sorry, the login you requested is already in use. Please choose another one."
             ) + "<br>"
             save = False
         if not self._validMail(self._params.get("email", "")):
             self._params["msg"] += _(
                 "You must enter a valid email address")
             save = False
     if save:
         #Data are OK, Now check if there is an existing user or create a new one
         ah = user.AvatarHolder()
         res = ah.match({"email": self._params["email"]},
                        exact=1,
                        forceWithoutExtAuth=True)
         if res:
             #we find a user with the same email
             a = res[0]
             #check if the user have an identity:
             if a.getIdentityList():
                 self._redirect(
                     urlHandlers.UHUserExistWithIdentity.getURL(a))
                 return
             else:
                 #create the identity to the user and send the comfirmatio email
                 _UserUtils.setUserData(a, self._params)
                 li = user.LoginInfo(self._params["login"],
                                     self._params["password"])
                 id = ih.createIdentity(li, a, "Local")
                 ih.add(id)
                 DBMgr.getInstance().commit()
                 if minfo.getModerateAccountCreation():
                     mail.sendAccountCreationModeration(a).send()
                 else:
                     mail.sendConfirmationRequest(a).send()
                     if minfo.getNotifyAccountCreation():
                         mail.sendAccountCreationNotification(a).send()
         else:
             a = user.Avatar()
             _UserUtils.setUserData(a, self._params)
             ah.add(a)
             li = user.LoginInfo(self._params["login"],
                                 self._params["password"])
             id = ih.createIdentity(li, a, "Local")
             ih.add(id)
             DBMgr.getInstance().commit()
             if minfo.getModerateAccountCreation():
                 mail.sendAccountCreationModeration(a).send()
             else:
                 mail.sendConfirmationRequest(a).send()
                 if minfo.getNotifyAccountCreation():
                     mail.sendAccountCreationNotification(a).send()
         self._redirect(urlHandlers.UHUserCreated.getURL(a))
     else:
         cp = None
         if self._params.has_key("cpEmail"):
             ph = pendingQueues.PendingQueuesHolder()
             cp = ph.getFirstPending(self._params["cpEmail"])
         if self._aw.getUser() and self._aw.getUser() in minfo.getAdminList(
         ).getList():
             p = adminPages.WPUserCreation(self, self._params, cp)
         else:
             p = adminPages.WPUserCreationNonAdmin(self, self._params, cp)
         return p.display()
Example #58
0
 def run(self, args):
     self._dbi = DBMgr.getInstance()
     self._dbi.startRequest()
     result = self._run(args)
     self._dbi.endRequest(True)
     return result