def collection_post(self): settings = self.request.registry.settings locale = self.request.validated['locale'] title = "{}_{}".format(locale.document_id, locale.lang) content = '<a href="{}">{}</a>'.format( self.request.referer, locale.title) category = settings['discourse.category'] # category could be id or name try: category = int(category) except: pass client = get_discourse_client(settings) try: response = client.client.create_post(content, title=title, category=category) except: raise HTTPInternalServerError('Error with Discourse') if "topic_id" in response: document_topic = DocumentTopic(topic_id=response['topic_id']) locale.document_topic = document_topic update_cache_version_direct(locale.document_id) DBSession.flush() return response
def post(self): """ Mark the given document as editable. Request: `POST` `/documents/unprotect` Request body: {'document_id': @document_id@} """ document_id = self.request.validated['document_id'] document = _get_document(document_id) # Do nothing if document is already not protected. if not document.protected: return {} document.protected = False user_id = self.request.authenticated_userid DocumentRest.update_version(document, user_id, 'Unprotected document', [UpdateType.FIGURES], []) update_cache_version_direct(document_id) return {}
def merge_user_accounts(source_user_id, target_user_id, queue_config): print('Removing from cache...') remove_from_cache(source_user_id) print('Removing geo associations...') _remove_geo_associations(source_user_id) print('Transfering associations...') _transfer_associations(source_user_id, target_user_id) print('Transfering tags...') _transfer_tags(source_user_id, target_user_id) print('Updating feed entries...') _update_feed_entries(source_user_id, target_user_id) print('Updating contributions versions and histories...') _update_history_metadata(source_user_id, target_user_id) print('Unregistering from mailing lists...') _unregister_from_mailinglists(source_user_id) print('Removing profile and user account...') _remove_user_account(source_user_id) # update the cache version for the source and target user accounts print('Updating associated documents cache...') update_cache_version_direct(source_user_id) update_cache_version_full(target_user_id, USERPROFILE_TYPE) # notify ES the source account no longer exists print('Notifying Elastic Search...') notify_es_syncer(queue_config)
def post(self): """ Merges a document into another document. - Associations and tags of the source document are transferred to the target document. - The association log entries are rewritten to the target document. - The time of the log entries is updated, so that the ES syncer will pick up the new associations of the target document. - The attribute `redirects_to` of the source document is set. - A new version is created for the source document. This makes sure that the ES syncer removes the document from ES index. - Update the cache version of the source document. - Update the cache version of the target document and its associations. - Removes the feed entries of the source document. Request: `POST` `/documents/merge` Request body: { 'source_document_id': @document_id@, 'target_document_id': @document_id@ } """ source_document_id = self.request.validated['source_document_id'] target_document_id = self.request.validated['target_document_id'] source_doc = DBSession.query(Document).get(source_document_id) # transfer associations from source to target transfer_associations(source_document_id, target_document_id) # transfer tags from source to target transfer_tags(source_document_id, target_document_id) # if waypoint, update main waypoint of routes if source_doc.type == WAYPOINT_TYPE: _transfer_main_waypoint(source_document_id, target_document_id) # set redirection and create a new version source_doc.redirects_to = target_document_id DocumentRest.update_version( source_doc, self.request.authenticated_userid, 'merged with {}'.format(target_document_id), [UpdateType.FIGURES], []) # update the cache version for the source and target document update_cache_version_direct(source_document_id) update_cache_version_full(target_document_id, source_doc.type) _remove_feed_entry(source_document_id) if source_doc.type == IMAGE_TYPE: delete_all_files_for_image(source_document_id, self.request) notify_es_syncer(self.request.registry.queue_config) return {}
def collection_post(self): settings = self.request.registry.settings locale = self.request.validated['locale'] document = self.request.validated['document'] document_type = association_keys_for_types[document.type] document_path = "/{}/{}/{}".format(document_type, locale.document_id, locale.lang) content = '<a href="https://www.camptocamp.org{}">{}</a>'.format( document_path, locale.title or document_path) category = settings['discourse.category'] # category could be id or name try: category = int(category) except Exception: pass client = get_discourse_client(settings) try: title = "{}_{}".format(locale.document_id, locale.lang) response = client.client.create_post(content, title=title, category=category) except Exception as e: log.error('Error with Discourse: {}'.format(str(e)), exc_info=True) raise HTTPInternalServerError('Error with Discourse') if "topic_id" in response: topic_id = response['topic_id'] document_topic = DocumentTopic(topic_id=topic_id) locale.document_topic = document_topic update_cache_version_direct(locale.document_id) DBSession.flush() if locale.type == document_types.OUTING_TYPE: try: self.invite_participants(client, locale, topic_id) except Exception: log.error( 'Inviting participants of outing {} failed'.format( locale.document_id), exc_info=True) return response
def post(self): """ Mark the given document as editable. Request: `POST` `/documents/unprotect` Request body: {'document_id': @document_id@} """ document_id = self.request.validated['document_id'] document = _get_document(document_id) document.protected = False update_cache_version_direct(document_id) return {}