Exemple #1
0
def construct_wavelet_json_for_http_response(wavelet_data, wave_id, wavelet_id, email, b64Encode=False):
    '''
    Constructs the json that will be sent back through the http request from
    various elements
    @param wavelet_data: the dict with the wavelet and wavelet json
    @param wave_id: the id of the wave
    @param wavelet_id: the id of the wavelet
    @param email: the email of the user waiting for the response
    @param b64Encode=False: set to true if you want the response base64 encoded
    
    @return the json to be sent to the webpage
    '''
    #Fetch the required data from the datastore
    session = sessionTools.get(wave_id, wavelet_id, email)
    settings = settingsTools.get(session)
    waveMeta = waveTools.get(wave_id, wavelet_id)
    if waveMeta:
        participant_profiles = waveMeta.participant_profiles or {}
    else:
        participant_profiles = {}
    
    #Construct the outgoing json
    wavelet_json = {
        'wavelet'       :   wavelet_data.get("json"),
        'readblips'     :   settings.read_blips or [],
        'profiles'      :   participant_profiles,
        'isPublic'      :   sessionTools.isPublic(session),
        'rwPermission'  :   settings.rw_permission   
    }
    if b64Encode:
        return base64.b64encode(simplejson.dumps(wavelet_json))
    else:
        return simplejson.dumps(wavelet_json)
def regenerateUser(wave_id, wavelet_id, email):
    '''
    Fetches the database entry for this user and regenerates their unique url
    @param wave_id: the id of the wave to generate the link for
    @param wavelet_id: the id of the wavelet to generate the link for
    @param email: the email address to generate the link for
    @return unique url for this user and wave
    '''
    session = sessionTools.get(wave_id, wavelet_id, email)
    return _generateUrl(session.wave_id,
                        session.wavelet_id,
                        session.email,
                        session.auth_token)
def generateNewUser(wave_id, wavelet_id, email, rw_permission):
    '''
    Generates the database entry for this user and creates the unique url link
    If the user already exists does an overwrite
    @param wave_id: the id of the wave to generate the link for
    @param wavelet_id: the id of the wavelet to generate the link for
    @param email: the email address to generate the link for
    @param rw_permission: the raw read/write permission type this user has
    @return unique url for this user and wave
    '''
    #We don't want duplicates so we need to check for the sesison first. If
    #we do find an existing user we need to apply the default settings
    session = sessionTools.get(wave_id, wavelet_id, email)
    if session:
        logging.info("Found existing user with same credentials. Updating")
        auth_token = session.auth_token
        session.version = 2
        sessionTools.put(session)
        
        settings = settingsTools.get(session)
        if settings:
            settings.unseen_changes = True
            settings.rw_permission = rw_permission
        else:
            settings = Settings(unseen_changes  =   True,
                                rw_permission   =   rw_permission,
                                parent          =   parent,
                                key_name        =   settingsTools.generateKey(  wave_id,
                                                                                wavelet_id,
                                                                                email))
        settingsTools.put(settings, wave_id, wavelet_id, email)
    else:
        auth_token = _generateAuthToken()
        logging.info("Creating new token with auth code " + auth_token)
        session = Session(  wave_id         =   wave_id,
                            wavelet_id      =   wavelet_id,
                            email           =   email,
                            auth_token      =   auth_token,
                            version         =   2)
        sessionTools.put(session)

        settings = Settings(unseen_changes  =   True,
                            rw_permission   =   rw_permission,
                            parent          =   session,
                            key_name        =   settingsTools.generateKey(  wave_id,
                                                                            wavelet_id,
                                                                            email))
        settingsTools.put(settings, wave_id, wavelet_id, email)
    
    return _generateUrl(wave_id, wavelet_id, email, auth_token)
 def getSettings(self, handler):
     '''
     Fetches the settings object for this user
     @param handler: the webapp handler
     @return the settings object or None if it could not be found
     '''
     credentials = getAuthenticationValuesFromRequest(handler)
     session = sessionTools.get( credentials['wave_id'],
                                 credentials['wavelet_id'],
                                 credentials['email'])
     if session:
         settings = settingsTools.get(session)
         if settings:
             return settings
     return None
 def decorated_function(*args, **kwargs):
     handler = args[0]
     credentials = getAuthenticationValuesFromRequest(handler)
     session = sessionTools.get( credentials['wave_id'],
                                 credentials['wavelet_id'],
                                 credentials['email'])
     if session and session.auth_token == credentials['auth']:
         logging.info("Request authenticated")
         return function(*args, **kwargs)
     else:
         logging.info("Request not authenticated")
         if self.render_page:
             return eOutput.AuthenticationDenied(handler).RenderPage(eCodes.PERMISSION_DENIED_ERR)
         else:
             return eOutput.AuthenticationDenied(handler).ReturnResponse()
    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)