Exemplo n.º 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)
Exemplo n.º 2
0
    def __AlertEmailParticipants(self, wavelet, who_changed):
        '''
        Send an email out to any other proxy-for participants in the wave
        @param wavelet: the wavelet that the proxy-for participants are
                        subscribed to
        @param who_changed: the friendly name of who changed the wave
        '''
        #Alert other e-mail participants that a new blip has been posted
        sessions = sessionTools.fetch(wavelet.wave_id, wavelet.wavelet_id)

        for userSession in sessions:
            if not userSession.email == self.email and not sessionTools.isPublic(userSession):
                userSettings = settingsTools.get(userSession)
                if not userSettings.unseen_changes and not userSettings.rw_permission == pt_raw.RW['DELETED']:
                    deferred.defer(
                        emailInterface.sendNotificationEmail,
                        sessionCreation.regenerateUser( wavelet.wave_id,
                                                        wavelet.wavelet_id,
                                                        userSession.email   ),
                        wavelet.wave_id,
                        wavelet.wavelet_id,
                        userSession.email,
                        self.email,
                        wavelet.title,
                        who_modified_display=who_changed)
                    
                    settingsTools.markUnseenChanges(session=userSession)
Exemplo n.º 3
0
def updateUsers(event, wavelet):
    '''
    Loops through the users in the wave and sends email if these are the first
    new changes
    @param event: the event that triggered
    @param wavelet: the wavelet where the event triggered
    '''
    blip_id = None
    if event.blip:
        blip_id = event.blip.blip_id
    sessions = sessionTools.fetch(wavelet.wave_id, wavelet.wavelet_id)
    for userSession in sessions:
        if sessionTools.isPublic(userSession):
            continue
        #Dispatch e-mail if these are new changes
        userSettings = settingsTools.get(userSession)
        if userSettings and not userSettings.unseen_changes and not userSettings.rw_permission == pt_raw.RW['DELETED']:
            deferred.defer( emailInterface.sendNotificationEmail,
                            sessionCreation.regenerateUser( wavelet.wave_id,
                                                            wavelet.wavelet_id,
                                                            userSession.email   ),
                            wavelet.wave_id,
                            wavelet.wavelet_id,
                            userSession.email,
                            event.modified_by,
                            wavelet.title)
            settingsTools.markUnseenChanges(session=userSession)

        #Update each users blip unread status
        settingsTools.blipChanges(blip_id, session=userSession)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
def constructInitialState(wavelet):
    '''
    Constructs the initial gadget state. This is used purely for migration from
    the v1 gadget to v2 gadget. So it returns a list of email users in the 
    correct format for the gadget
    @param wavelet: the wavelet where the gadget will live
    @return a dictionary containing the key values of the initial state
    '''
    sessions = sessionTools.fetch(wavelet.wave_id, wavelet.wavelet_id)
    #Form the email list
    email_list = []
    public_session = None
    for session in sessions:
        if sessionTools.isPublic(session):
            public_session = session
        else:
            email_list.append(session.email)
            
    #Form public settings
    public = {}
    isPublic = False
    isReadOnly = True
    
    try:
        public_settings = settingsTools.get(public_session)
        rw_permission = public_settings.rw_permission
        
        if rw_permission == pt_raw.RW['READ']:
            isPublic = True
            isReadOnly = True
        elif rw_permission == pt_raw.RW['READ_WRITE']:
            isPublic = True
            isReadOnly = False
    except:
        #Just means public settings could not be found. Defaults will be used
        pass
    public.update({'isPublic' : isPublic, 'isReadOnly' : isReadOnly});
    
    output = base64.b64encode(simplejson.dumps({'emailParticipants' : email_list,
                                                'public'            : public}))
    return {'state' : output, 'participantDetailsState' : 'fetch'}