Ejemplo n.º 1
0
def _addEmailUser(event, wavelet, gadgetWrapper, user, request):
    '''
    Adds an email particpant to the wave and updates the gadget to reflect
    @param event: the event that triggered the changed gadget
    @param wavelet: the wavelet where the request originated from
    @param user: the user that made the request
    @param gadgetWrapper: the object that wraps this gadgets state
    @param request: the request to process
    '''
    logging.info("Add email user request")
    email = request.get('params').get("email") or None
    message = request.get('params').get('message') or ""
    
    if email:
        logging.info("Creating new session for " + email)
        url = sessionCreation.generateNewUser(  wavelet.wave_id,
                                                wavelet.wavelet_id,
                                                email,
                                                pt_raw.RW['READ_WRITE'])
        deferred.defer(
            emailInterface.sendFirstNotificationEmail,
            url,
            wavelet.wave_id,
            wavelet.wavelet_id,
            email,
            event.modified_by,
            wavelet.title,
            message=message)

        wavelet.add_proxying_participant(utils.getProxyForFromEmail(email))
        gadgetWrapper.addEmailParticipant(email)
        gadgetWrapper.deleteIncomingRequest(user)
Ejemplo n.º 2
0
 def __MarkNewBlipRead(self, new_wavelet_data):
     '''
     Marks the new blip as read for the user so they know they have seen it
     already
     @param new_wavelet_data: the new wavelet from the server with the new
                                 blip included
     '''
     #Mark new blip read
     blip_id = self.incoming.get('blipid', "")
     new_parent_blip = new_wavelet_data.get('wavelet').blips.get(blip_id, None)
     if new_parent_blip:
         child_blips = new_parent_blip.child_blips
         for b in child_blips:
             if config.ROBOT_IDENT + "+" + utils.getProxyForFromEmail(self.email) + "@" + config.ROBOT_DOMAIN in b.contributors:
                 self.__UserReads(b.blip_id)
Ejemplo n.º 3
0
    def _UserReplies(self):
        '''
        Sends a reply to wave from the user along with other tasks such as
        marking the wave read etc.
        '''
        #Modify requirements if the wave is public
        if sessionTools.isPublic(sessionTools.get( self.wave_id, self.wavelet_id, self.email)):
            self._PublicReplies()
        else:
            #Fetch the wavelet and do some house-keeping
            wavelet = waveRpc.retry_fetch_wavelet(  config.HTTP_IMPORTANT_RETRY,
                                                    mrray,
                                                    self.wave_id,
                                                    self.wavelet_id)
        
            try:
                wavelet.robot_address = config.ROBOT_EMAIL
            except:
                pass#The wavelet already has the robot address
            proxy_for = utils.getProxyForFromEmail(self.email)
            
            if wavelet.participants.get_role(config.ROBOT_IDENT + "+" + proxy_for + "@" + config.ROBOT_DOMAIN) == wavelet.participants.ROLE_READ_ONLY:
                #TODO wrong exception raised here
                raise waveRpc.NotParticipantException("Wave permissions do not permit reply")
            if wavelet.participants.get_role(config.ROBOT_EMAIL) == wavelet.participants.ROLE_READ_ONLY:
                #TODO wrong exception raised here
                raise waveRpc.NotParticipantException("Wave permissions do not permit reply")
            
            wavelet.add_proxying_participant(proxy_for)
            self.__InsertBlipIntoWavelet(wavelet, proxy_for)
            self.__AlertEmailParticipants(wavelet, self.email+"(via Mr-Ray)")
            waveRpc.retry_submit(config.HTTP_IMPORTANT_RETRY, mrray, wavelet)

            #Re-fetch the new (updated) wavelet
            new_wavelet_data = waveRpc.retry_fetch_wavelet_json(config.HTTP_IMPORTANT_RETRY,
                                                                mrray,
                                                                self.wave_id,
                                                                self.wavelet_id)
            self.__MarkNewBlipRead(new_wavelet_data)
        
            #Write the response
            wavelet_json = utils.construct_wavelet_json_for_http_response(  new_wavelet_data,
                                                                            self.wave_id,
                                                                            self.wavelet_id,
                                                                            self.email)
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write(wavelet_json)
            self.response.set_status(201)
Ejemplo n.º 4
0
def onAddParticipantsChangedV1(event, wavelet, add_gadget):
    '''
    Deals with the add participants gadget changing, subscribes wave users etc
    @param event: the event that triggered the gadget state change
    @param wavelet: the wavelet the gadget lives in
    @param add_gadget: the add participants gadget retrieved from the wave
    '''

    #Fetch the values from the gadget
    participants_json = add_gadget.get("EMAIL-PARTICIPANTS", None)
    if participants_json:
        participants_json = base64.b64decode(participants_json)
    else:
        participants_json = "[]"
    participants = simplejson.loads(participants_json)
    new_participant = add_gadget.get("ADD-PARTICIPANT", None)

    if new_participant:
        logging.info("Subscribing new e-mail user: "******" not subscribed. E-mail address not valid")
            return

        #Only update if the user is new
        if not new_participant in participants:
            deferred.defer(
                    emailInterface.sendFirstNotificationEmail,
                    sessionCreation.generateNewUser(wavelet.wave_id,
                                                    wavelet.wavelet_id,
                                                    new_participant,
                                                    pt_raw.RW['READ_WRITE']),
                    wavelet.wave_id,
                    wavelet.wavelet_id,
                    new_participant,
                    event.modified_by,
                    wavelet.title)

            participants.append(new_participant)
            wavelet.add_proxying_participant(utils.getProxyForFromEmail(new_participant))

        #Update the gadget
        participants_json = simplejson.dumps(participants)
        add_gadget.update_element({ "ADD-PARTICIPANT": None,
                                    "EMAIL-PARTICIPANTS": base64.b64encode(participants_json)})