Example #1
0
def send_notifications(handler, persons, notes):
    """For each note, send a notification to subscriber.

    Args:
       notes: List of notes for which to send notification.
       persons: Dictionary of persons impacted by the notes,
                indexed by person_record_id.
       handler: Handler used to send email notification.
    """
    for note in notes:
        person = persons[note.person_record_id]
        subscribe.send_notifications(handler, person, [note])
Example #2
0
    def post(self):
        if not self.params.text:
            return self.error(
                200, _('Message is required. Please go back and try again.'))

        if not self.params.author_name:
            return self.error(
                200, _('Your name is required in the "About you" section.  '
                       'Please go back and try again.'))

        if self.params.status == 'is_note_author' and not self.params.found:
            return self.error(
                200, _('Please check that you have been in contact with '
                       'the person after the earthquake, or change the '
                       '"Status of this person" field.'))

        note = Note.create_original(
            self.subdomain,
            entry_date=get_utcnow(),
            person_record_id=self.params.id,
            author_name=self.params.author_name,
            author_email=self.params.author_email,
            author_phone=self.params.author_phone,
            source_date=get_utcnow(),
            found=bool(self.params.found),
            status=self.params.status,
            email_of_found_person=self.params.email_of_found_person,
            phone_of_found_person=self.params.phone_of_found_person,
            last_known_location=self.params.last_known_location,
            text=self.params.text)
        entities_to_put = [note]

        # Update the Person based on the Note.
        person = Person.get(self.subdomain, self.params.id)
        if person:
            person.update_from_note(note)
            # Send notification to all people
            # who subscribed to updates on this person
            subscribe.send_notifications(person, note, self)

            entities_to_put.append(person)

        # Write one or both entities to the store.
        db.put(entities_to_put)

        # If user wants to subscribe to updates, redirect to the subscribe page
        if self.params.subscribe:
            return self.redirect('/subscribe', id=person.record_id,
                                 subscribe_email=self.params.author_email)

        # Redirect to this page so the browser's back button works properly.
        self.redirect('/view', id=self.params.id, query=self.params.query)
    def post(self):
        if not self.params.text:
            return self.error(
                200, _('Message is required. Please go back and try again.'))

        if not self.params.author_name:
            return self.error(
                200, _('Your name is required in the "About you" section.  Please go back and try again.'))

        # TODO: To reduce possible abuse, we currently limit to 3 person
        # match. We could guard using e.g. an XSRF token, which I don't know how
        # to build in GAE.

        ids = set()
        for i in [1, 2, 3]:
            id = getattr(self.params, 'id%d' % i)
            if not id:
                break
            ids.add(id)

        if len(ids) > 1:
            notes = []
            for person_id in ids:
                person = Person.get(self.repo, person_id)
                person_notes = []
                for other_id in ids - set([person_id]):
                    note = Note.create_original(
                        self.repo,
                        entry_date=get_utcnow(),                        
                        person_record_id=person_id,
                        linked_person_record_id=other_id,
                        text=self.params.text,
                        author_name=self.params.author_name,
                        author_phone=self.params.author_phone,
                        author_email=self.params.author_email,
                        source_date=get_utcnow())
                    person_notes.append(note)
                # Notify person's subscribers of all new duplicates. We do not
                # follow links since each Person record in the ids list gets its
                # own note. However, 1) when > 2 records are marked as
                # duplicates, subscribers will still receive multiple
                # notifications, and 2) subscribers to already-linked Persons
                # will not be notified of the new link.
                subscribe.send_notifications(self, person, person_notes, False)
                notes += person_notes
            # Write all notes to store
            db.put(notes)
        self.redirect('/view', id=self.params.id1)
    def confirm_note_with_bad_words(self, note):
        """After a note containing bad words is confirmed by the author,
        we will:
        (1) set note.confirmed = True;
        (2) copy the note from NoteWithBadWords to Note;
        (3) log user action;
        (4) update person record. """
        note.confirmed = True;

        # Check whether the record author disabled notes on
        # this record during the time between the note author inputs the
        # note in the UI and confirms the note through email.
        person = model.Person.get(self.repo, note.person_record_id)
        if person.notes_disabled:
            return self.error(
                200, _('The author has disabled notes on this record.'))

        # Check whether the admin disabled reporting "believed_dead"
        # during the time between the note author inputs the
        # note in the UI and confirms the note through email.
        if (self.params.status == 'believed_dead' and
            not self.config.allow_believed_dead_via_ui):
            return self.error(
                200, _('Not authorized to post notes with the status '
                       '"believed_dead".'))

        # clone the flagged note to Note table.
        note_confirmed = model.Note.create_original(
            self.repo,
            entry_date=note.entry_date,
            person_record_id=note.person_record_id,
            author_name=note.author_name,
            author_email=note.author_email,
            author_phone=note.author_phone,
            source_date=note.source_date,
            author_made_contact=note.author_made_contact,
            status=note.status,
            email_of_found_person=note.email_of_found_person,
            phone_of_found_person=note.phone_of_found_person,
            last_known_location=note.last_known_location,
            text=note.text)
        entities_to_put = [note_confirmed]

        note.confirmed_copy_id = note_confirmed.get_record_id()
        entities_to_put.append(note)

        # Specially log 'believed_dead'.
        if note_confirmed.status == 'believed_dead':
            model.UserActionLog.put_new(
                    'mark_dead', note_confirmed, person.primary_full_name,
                    self.request.remote_addr)

        # Specially log a switch to an alive status.
        if (note_confirmed.status in ['believed_alive', 'is_note_author'] and
            person.latest_status not in ['believed_alive', 'is_note_author']):
            model.UserActionLog.put_new(
                    'mark_alive', note_confirmed, person.primary_full_name)

        # Update the Person based on the Note.
        if person:
            person.update_from_note(note_confirmed)
            # Send notification to all people
            # who subscribed to updates on this person
            subscribe.send_notifications(self, person, [note_confirmed])
            entities_to_put.append(person)

        # Write one or both entities to the store.
        db.put(entities_to_put)