Example #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)
Example #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)
Example #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)
Example #4
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)
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'}