Exemplo n.º 1
0
    def _PublicReplies(self):
        '''
        Sends a reply to wave from the public user
        Maybe consider merging this into _publicReplies in the future. Methods are very similar
        '''
        self.name = self.incoming.get("name", None)
        if not self.name:
            logger.warn("The response came from a public wave and expected the 'name' field but was not found")
            raise MalformedRequest("The response came from a public wave and expected the 'name' field but was not found")
        if not re.match("^[a-zA-Z0-9_]+$", self.name):
            logger.warn("The response came from a public wave and expected the 'name' field to only contain [a-zA-Z0-9_] but it was " + name)
            raise MalformedRequest("The response came from a public wave and expected the 'name' field to only contain [a-zA-Z0-9_] but it was " + name)
        
        #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.getProxyForFromPublic(self.name)
        
        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.name + "(via Mr-Ray Public)")
        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)
        
        #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)
Exemplo n.º 2
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)