def get(self): # Check the request parameters. if not self.params.id: return self.error(404, 'No person id was specified.') try: person = Person.get_by_person_record_id(self.params.id) except ValueError: return self.error(404, 'There is no record for the specified id.') if not person: return self.error(404, 'There is no record for the specified id.') standalone = self.request.get('standalone') # Check if private info should be revealed. content_id = 'view:' + self.params.id reveal_url = reveal.make_reveal_url(self.request.url, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Get the notes and duplicate links. notes = Note.get_by_person_record_id(person.person_record_id, limit=200) person.sex_text = get_person_sex_text(person) for note in notes: note.status_text = get_note_status_text(note) linked_persons = person.get_linked_persons(note_limit=200) linked_person_info = [dict(id = p.person_record_id, name = "%s %s" % (p.first_name, p.last_name)) for p in linked_persons] # Render the page. self.render('templates/view.html', params=self.params, linked_person_info=linked_person_info, person=person, notes=notes, standalone=standalone, onload_function='view_page_loaded()', reveal_url=reveal_url, show_private_info=show_private_info)
def get(self): # To handle multiple persons, we create a single object where # each property is a list of values, one for each person. # This makes page rendering easier. person = dict([(prop, []) for prop in COMPARE_FIELDS]) any_person = dict([(prop, None) for prop in COMPARE_FIELDS]) # Get all persons from db. # TODO: Can later optimize to use fewer DB calls. for i in [1, 2, 3]: id = self.request.get('id%d' % i) if not id: break p = Person.get(self.repo, id) if not p: return self.error( 404, _("This person's entry does not exist or has been " "deleted.")) sanitize_urls(p) for prop in COMPARE_FIELDS: val = getattr(p, prop) if prop == 'sex': # convert enum value to localized text val = get_person_sex_text(p) elif prop == 'photo_url' and val: val = (self.should_show_inline_photo(val), val) person[prop].append(val) any_person[prop] = any_person[prop] or val # Compute the local times for the date fields on the person and format. person['source_datetime_local_string'] = map( self.to_formatted_local_datetime, person['source_date']) # Check if private info should be revealed. content_id = 'multiview:' + ','.join(person['person_record_id']) reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # TODO: Handle no persons found. person['profile_pages'] = [ view.get_profile_pages(profile_urls, self) for profile_urls in person['profile_urls'] ] any_person['profile_pages'] = any(person['profile_pages']) # Note: we're not showing notes and linked persons information # here at the moment. self.render('multiview.html', person=person, any=any_person, cols=len(person['full_name']) + 1, onload_function='view_page_loaded', markdup=True, show_private_info=show_private_info, reveal_url=reveal_url)
def post(self): """If no signature is present, send out a deletion code. If a signature is present, carry out the deletion.""" person = Person.get(self.subdomain, self.params.id) if not person: return self.error(400, 'No person with ID: %r' % self.params.id) action = ('delete', str(self.params.id)) if self.params.signature: if reveal.verify(action, self.params.signature): db.delete(get_entities_to_delete(person)) # i18n: Message telling the user that a record has been deleted. return self.error(200, _('The record has been deleted.')) else: # i18n: Message for an unauthorized attempt to delete a record. return self.error(403, _('The authorization code was invalid.')) else: mail.send_mail( sender='do not reply <do-not-reply@%s>' % self.env.domain, to='<%s>' % person.author_email, # i18n: Subject line of an e-mail message that gives the # i18n: user a link to delete a record subject=_( 'Deletion request for %(given_name)s %(family_name)s' ) % {'given_name': person.first_name, 'family_name': person.last_name}, # i18n: Body text of an e-mail message that gives the user # i18n: a link to delete a record body = _(''' We have received a deletion request for a missing person record at %(domain_name)s. Your e-mail address was entered as the author of this record, so we are contacting you to confirm whether you want to delete it. To delete this record, use this link: %(delete_url)s To view the record, use this link: %(view_url)s ''') % {'domain_name': self.env.domain, 'delete_url': self.get_url('/delete', id=self.params.id, signature=reveal.sign(action, 24*3600)), 'view_url': self.get_url('/view', id=self.params.id)} ) # i18n: Message explaining to the user that the e-mail message # i18n: containing a link to delete a record has been sent out. return self.error(200, _('An e-mail message with a deletion code has been sent. The code will expire in one day.'))
def get(self): email = self.request.get('email') token = self.request.get('token') is_verified = reveal.verify('unsubscribe:%s' % email, token) if not is_verified: return self.error(200, _('This link is invalid.')) subscription = Subscription.get(self.subdomain, self.params.id, email) if subscription: db.delete(subscription) return self.info(200, _('You have successfully unsubscribed.')) else: return self.error(200, _('You are already unsubscribed.'))
def get(self): email = self.request.get('email') token = self.request.get('token') is_verified = reveal.verify('unsubscribe:%s' % email, token) if not is_verified: return self.error(200, _('This link is invalid.')) subscription = Subscription.get(self.repo, self.params.id, email) if subscription: db.delete(subscription) return self.info(200, _('You have successfully unsubscribed.')) else: return self.error(200, _('You are already unsubscribed.'))
def get(self): # To handle multiple persons, we create a single object where # each property is a list of values, one for each person. # This makes page rendering easier. person = dict([(prop, []) for prop in COMPARE_FIELDS]) any_person = dict([(prop, None) for prop in COMPARE_FIELDS]) # Get all persons from db. # TODO: Can later optimize to use fewer DB calls. for i in [1, 2, 3]: id = self.request.get('id%d' % i) if not id: break p = Person.get(self.repo, id) if not p: return self.error( 404, _("This person's entry does not exist or has been " "deleted.")) sanitize_urls(p) for prop in COMPARE_FIELDS: val = getattr(p, prop) if prop == 'sex': # convert enum value to localized text val = get_person_sex_text(p) person[prop].append(val) any_person[prop] = any_person[prop] or val # Compute the local times for the date fields on the person and format. person['source_datetime_local_string'] = map( self.to_formatted_local_datetime, person['source_date']) # Check if private info should be revealed. content_id = 'multiview:' + ','.join(person['person_record_id']) reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # TODO: Handle no persons found. person['profile_pages'] = [view.get_profile_pages(profile_urls, self) for profile_urls in person['profile_urls']] any_person['profile_pages'] = any(person['profile_pages']) # Note: we're not showing notes and linked persons information # here at the moment. self.render('multiview.html', person=person, any=any_person, cols=len(person['full_name']) + 1, onload_function='view_page_loaded', markdup=True, show_private_info=show_private_info, reveal_url=reveal_url)
def get(self): note = model.Note.get(self.subdomain, self.params.id) if not note: return self.error(400, 'No note with ID: %r' % self.params.id) note.status_text = utils.get_note_status_text(note) captcha_html = note.hidden and self.get_captcha_html() or '' # Check if private info should be revealed. content_id = 'view:' + note.person_record_id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) self.render('templates/flag_note.html', onload_function='load_language_api()', note=note, captcha_html=captcha_html, reveal_url=reveal_url, flag_note_page=True, show_private_info=show_private_info, signature=self.params.signature)
def get_person_and_verify_params(self): """Checks the request for a valid person id and valid crypto token. Returns a tuple containing: (person, token) If there is an error we raise a RestoreError, instead of pretending we're using C.""" person = model.Person.get_by_key_name(self.params.id) if not person: raise RestoreError( 'The record with the following ID no longer exists: %s' % self.params.id.split(':', 1)[1]) token = self.request.get('token') data = 'restore:%s' % self.params.id if not reveal.verify(data, token): raise RestoreError('The token was invalid') return (person, token)
def get(self): # To handle multiple persons, we create a single object where # each property is a list of values, one for each person. # This makes page rendering easier. person = dict([(prop, []) for prop in COMPARE_FIELDS]) any = dict([(prop, None) for prop in COMPARE_FIELDS]) # Get all persons from db. # TODO: Can later optimize to use fewer DB calls. for i in [1, 2, 3]: id = self.request.get('id%d' % i) if not id: break p = Person.get(self.subdomain, id) for prop in COMPARE_FIELDS: val = getattr(p, prop) if prop == 'sex': # convert enum value to localized text val = get_person_sex_text(p) person[prop].append(val) any[prop] = any[prop] or val # Check if private info should be revealed. content_id = 'multiview:' + ','.join(person['person_record_id']) reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # TODO: Handle no persons found. # Add a calculated full name property - used in the title. person['full_name'] = [ fname + ' ' + lname for fname, lname in zip(person['first_name'], person['last_name'])] standalone = self.request.get('standalone') # Note: we're not showing notes and linked persons information # here at the moment. self.render('templates/multiview.html', person=person, any=any, standalone=standalone, cols=len(person['first_name']) + 1, onload_function='view_page_loaded()', markdup=True, show_private_info=show_private_info, reveal_url=reveal_url)
def get_note_and_verify_params(self): """Check the request for a valid note record_id and valid crypto token. Returns a tuple containing: (note, token) If there is an error we raise a ConfirmPostNoteWithBadWordsError. """ keyname = "%s:%s" % (self.repo, self.params.id) note = model.NoteWithBadWords.get_by_key_name(keyname) if not note: # Place holder name here is id_str, not id, because # the translation system doesn't allow the same string in both # a place holder name and a normal uppercase word in one message. raise ConfirmPostNoteWithBadWordsError( _('No note with ID: %(id_str)s.') % {'id_str': keyname}) token = self.request.get('token') data = 'confirm_post_note_with_bad_words:%s' % self.params.id if not reveal.verify(data, token): raise ConfirmPostNoteWithBadWordsError( _("The token %(token)s was invalid.") % {'token': token}) return (note, token)
def get(self): note = model.Note.get(self.repo, self.params.id) if not note: return self.error(400, 'No note with ID: %r' % self.params.id) note.status_text = utils.get_note_status_text(note) note.source_date_local = self.to_local_time(note.source_date) captcha_html = note.hidden and self.get_captcha_html() or '' # Check if private info should be revealed. content_id = 'view:' + note.person_record_id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) self.render('flag_note.html', note=note, captcha_html=captcha_html, reveal_url=reveal_url, flag_note_page=True, show_private_info=show_private_info, signature=self.params.signature)
def get_person_and_verify_params(self): """Check the request for a valid person id and valid crypto token. Returns a tuple containing: (person, token) If there is an error we raise a DisableAndEnableNotesError. """ person = model.Person.get_by_key_name(self.params.id) if not person: # Place holder name here is id_str, not id, because # the translation system doesn't allow the same string in both # a place holder name and a normal uppercase word in one message. raise DisableAndEnableNotesError( _('No person with ID: %(id_str)s.') % {'id_str': self.params.id}) token = self.request.get('token') data = 'disable_notes:%s' % self.params.id if not reveal.verify(data, token): raise DisableAndEnableNotesError( _("The token %(token)s was invalid.") % {'token': token}) return (person, token)
def get(self): # Check the request parameters. if not self.params.id: return self.error(404, 'No person id was specified.') try: person = Person.get(self.subdomain, self.params.id) except ValueError: return self.error(404, 'There is no record for the specified id.') if not person: return self.error(404, 'There is no record for the specified id.') standalone = self.request.get('standalone') # Check if private info should be revealed. content_id = 'view:' + self.params.id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Get the notes and duplicate links. try: notes = person.get_notes() except datastore_errors.NeedIndexError: notes = [] person.sex_text = get_person_sex_text(person) for note in notes: note.status_text = get_note_status_text(note) note.linked_person_url = \ self.get_url('/view', id=note.linked_person_record_id) note.flag_spam_url = \ self.get_url('/flag_note', id=note.note_record_id, hide=(not note.hidden) and 'yes' or 'no', signature=self.params.signature) try: linked_persons = person.get_linked_persons() except datastore_errors.NeedIndexError: linked_persons = [] linked_person_info = [ dict(id=p.record_id, name="%s %s" % (p.first_name, p.last_name), view_url=self.get_url('/view', id=p.record_id)) for p in linked_persons] # Render the page. dupe_notes_url = self.get_url( '/view', id=self.params.id, dupe_notes='yes') results_url = self.get_url( '/results', role=self.params.role, query=self.params.query, first_name=self.params.first_name, last_name=self.params.last_name) feed_url = self.get_url( '/feeds/note', person_record_id=self.params.id, subdomain=self.subdomain) subscribe_url = self.get_url('/subscribe', id=self.params.id) self.render('templates/view.html', person=person, notes=notes, linked_person_info=linked_person_info, standalone=standalone, onload_function='view_page_loaded()', show_private_info=show_private_info, admin=users.is_current_user_admin(), dupe_notes_url=dupe_notes_url, results_url=results_url, reveal_url=reveal_url, feed_url=feed_url, subscribe_url=subscribe_url)
def get(self): # Check the request parameters. if not self.params.id: return self.error(404, 'No person id was specified.') try: person = Person.get(self.subdomain, self.params.id) except ValueError: return self.error(404, 'There is no record for the specified id.') if not person: return self.error(404, 'There is no record for the specified id.') standalone = self.request.get('standalone') # Check if private info should be revealed. content_id = 'view:' + self.params.id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Get the notes and duplicate links. try: notes = person.get_notes() except datastore_errors.NeedIndexError: notes = [] person.sex_text = get_person_sex_text(person) for note in notes: note.status_text = get_note_status_text(note) note.linked_person_url = \ self.get_url('/view', id=note.linked_person_record_id) note.flag_spam_url = \ self.get_url('/flag_note', id=note.note_record_id, hide=(not note.hidden) and 'yes' or 'no', signature=self.params.signature) try: linked_persons = person.get_linked_persons() except datastore_errors.NeedIndexError: linked_persons = [] linked_person_info = [ dict(id=p.record_id, name="%s %s" % (p.first_name, p.last_name), view_url=self.get_url('/view', id=p.record_id)) for p in linked_persons ] # Render the page. dupe_notes_url = self.get_url('/view', id=self.params.id, dupe_notes='yes') results_url = self.get_url('/results', role=self.params.role, query=self.params.query, first_name=self.params.first_name, last_name=self.params.last_name) feed_url = self.get_url('/feeds/note', person_record_id=self.params.id, subdomain=self.subdomain) subscribe_url = self.get_url('/subscribe', id=self.params.id) self.render('templates/view.html', person=person, notes=notes, linked_person_info=linked_person_info, standalone=standalone, onload_function='view_page_loaded()', show_private_info=show_private_info, admin=users.is_current_user_admin(), dupe_notes_url=dupe_notes_url, results_url=results_url, reveal_url=reveal_url, feed_url=feed_url, subscribe_url=subscribe_url)
def get(self): # Check the request parameters. if not self.params.id: return self.error(404, 'No person id was specified.') try: person = Person.get(self.repo, self.params.id) except ValueError: return self.error(404, _("This person's entry does not exist or has been deleted.")) if not person: return self.error(404, _("This person's entry does not exist or has been deleted.")) standalone = self.request.get('standalone') # Check if private info should be revealed. content_id = 'view:' + self.params.id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Compute the local times for the date fields on the person. person.source_date_local_string = self.to_formatted_local_date( person.source_date) person.source_time_local_string = self.to_formatted_local_time( person.source_date) person.expiry_date_local_string = self.to_formatted_local_date( person.get_effective_expiry_date()) person.expiry_time_local_string = self.to_formatted_local_time( person.get_effective_expiry_date()) person.should_show_inline_photo = ( self.should_show_inline_photo(person.photo_url)) # Get the notes and duplicate links. try: notes = person.get_notes() except datastore_errors.NeedIndexError: notes = [] person.sex_text = get_person_sex_text(person) for note in notes: self.__add_fields_to_note(note) try: linked_persons = person.get_all_linked_persons() except datastore_errors.NeedIndexError: linked_persons = [] linked_person_info = [] for linked_person in linked_persons: try: linked_notes = linked_person.get_notes() except datastore_errors.NeedIndexError: linked_notes = [] for note in linked_notes: self.__add_fields_to_note(note) linked_person_info.append(dict( id=linked_person.record_id, name=linked_person.primary_full_name, view_url=self.get_url('/view', id=linked_person.record_id), notes=linked_notes)) # Render the page. dupe_notes_url = self.get_url( '/view', id=self.params.id, dupe_notes='yes') results_url = self.get_url( '/results', role=self.params.role, query_name=self.params.query_name, query_location=self.params.query_location, given_name=self.params.given_name, family_name=self.params.family_name) feed_url = self.get_url( '/feeds/note', person_record_id=self.params.id, repo=self.repo) subscribe_url = self.get_url('/subscribe', id=self.params.id) delete_url = self.get_url('/delete', id=self.params.id) disable_notes_url = self.get_url('/disable_notes', id=self.params.id) enable_notes_url = self.get_url('/enable_notes', id=self.params.id) extend_url = None extension_days = 0 expiration_days = None expiry_date = person.get_effective_expiry_date() if expiry_date and not person.is_clone(): expiration_delta = expiry_date - get_utcnow() extend_url = self.get_url('/extend', id=self.params.id) extension_days = extend.get_extension_days(self) if expiration_delta.days < EXPIRY_WARNING_THRESHOLD: # round 0 up to 1, to make the msg read better. expiration_days = expiration_delta.days + 1 if person.is_clone(): person.provider_name = person.get_original_domain() sanitize_urls(person) for note in notes: sanitize_urls(note) if person.profile_urls: person.profile_pages = get_profile_pages(person.profile_urls, self) self.render('view.html', person=person, notes=notes, linked_person_info=linked_person_info, standalone=standalone, onload_function='view_page_loaded()', show_private_info=show_private_info, admin=users.is_current_user_admin(), dupe_notes_url=dupe_notes_url, results_url=results_url, reveal_url=reveal_url, feed_url=feed_url, subscribe_url=subscribe_url, delete_url=delete_url, disable_notes_url=disable_notes_url, enable_notes_url=enable_notes_url, extend_url=extend_url, extension_days=extension_days, expiration_days=expiration_days)
def get(self): # Check the request parameters. if not self.params.id: return self.error(404, 'No person id was specified.') try: person = Person.get(self.repo, self.params.id) except ValueError: return self.error(404, _("This person's entry does not exist or has been deleted.")) if not person: return self.error(404, _("This person's entry does not exist or has been deleted.")) standalone = self.request.get('standalone') # Check if private info should be revealed. content_id = 'view:' + self.params.id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Compute the local times for the date fields on the person. person.source_date_local_string = self.to_formatted_local_time( person.source_date) person.expiry_date_local_string = self.to_formatted_local_time( person.get_effective_expiry_date()) person.should_show_inline_photo = ( self.should_show_inline_photo(person.photo_url)) # Get the notes and duplicate links. try: notes = person.get_notes() except datastore_errors.NeedIndexError: notes = [] person.sex_text = get_person_sex_text(person) for note in notes: self.__add_fields_to_note(note) try: linked_persons = person.get_all_linked_persons() except datastore_errors.NeedIndexError: linked_persons = [] linked_person_info = [] for linked_person in linked_persons: try: linked_notes = linked_person.get_notes() except datastore_errors.NeedIndexError: linked_notes = [] for note in linked_notes: self.__add_fields_to_note(note) linked_person_info.append(dict( id=linked_person.record_id, name=linked_person.primary_full_name, view_url=self.get_url('/view', id=linked_person.record_id), notes=linked_notes)) # Render the page. dupe_notes_url = self.get_url( '/view', id=self.params.id, dupe_notes='yes') results_url = self.get_url( '/results', role=self.params.role, query=self.params.query, given_name=self.params.given_name, family_name=self.params.family_name) feed_url = self.get_url( '/feeds/note', person_record_id=self.params.id, repo=self.repo) subscribe_url = self.get_url('/subscribe', id=self.params.id) delete_url = self.get_url('/delete', id=self.params.id) disable_notes_url = self.get_url('/disable_notes', id=self.params.id) enable_notes_url = self.get_url('/enable_notes', id=self.params.id) extend_url = None extension_days = 0 expiration_days = None expiry_date = person.get_effective_expiry_date() if expiry_date and not person.is_clone(): expiration_delta = expiry_date - get_utcnow() extend_url = self.get_url('/extend', id=self.params.id) extension_days = extend.get_extension_days(self) if expiration_delta.days < EXPIRY_WARNING_THRESHOLD: # round 0 up to 1, to make the msg read better. expiration_days = expiration_delta.days + 1 if person.is_clone(): person.provider_name = person.get_original_domain() sanitize_urls(person) for note in notes: sanitize_urls(note) if person.profile_urls: person.profile_pages = get_profile_pages(person.profile_urls, self) self.render('view.html', person=person, notes=notes, linked_person_info=linked_person_info, standalone=standalone, onload_function='view_page_loaded()', show_private_info=show_private_info, admin=users.is_current_user_admin(), dupe_notes_url=dupe_notes_url, results_url=results_url, reveal_url=reveal_url, feed_url=feed_url, subscribe_url=subscribe_url, delete_url=delete_url, disable_notes_url=disable_notes_url, enable_notes_url=enable_notes_url, extend_url=extend_url, extension_days=extension_days, expiration_days=expiration_days)
def get(self): # Check the request parameters. if not self.params.id: return self.error(404, "No person id was specified.") try: person = Person.get(self.subdomain, self.params.id) except ValueError: return self.error(404, "There is no record for the specified id.") if not person: return self.error(404, "There is no record for the specified id.") standalone = self.request.get("standalone") # Check if private info should be revealed. content_id = "view:" + self.params.id reveal_url = reveal.make_reveal_url(self, content_id) show_private_info = reveal.verify(content_id, self.params.signature) # Get the notes and duplicate links. try: notes = person.get_notes() except datastore_errors.NeedIndexError: notes = [] person.sex_text = get_person_sex_text(person) for note in notes: note.status_text = get_note_status_text(note) note.linked_person_url = self.get_url("/view", id=note.linked_person_record_id) try: linked_persons = person.get_linked_persons(note_limit=200) except datastore_errors.NeedIndexError: linked_persons = [] linked_person_info = [ dict( id=p.record_id, name="%s %s" % (p.first_name, p.last_name), view_url=self.get_url("/view", id=p.record_id), ) for p in linked_persons ] # Render the page. dupe_notes_url = self.get_url("/view", id=self.params.id, dupe_notes="yes") results_url = self.get_url( "/results", role=self.params.role, query=self.params.query, first_name=self.params.first_name, last_name=self.params.last_name, ) self.render( "templates/view.html", params=self.params, linked_person_info=linked_person_info, person=person, notes=notes, standalone=standalone, onload_function="view_page_loaded()", reveal_url=reveal_url, show_private_info=show_private_info, noindex=True, admin=users.is_current_user_admin(), dupe_notes_url=dupe_notes_url, results_url=results_url, )