Esempio n. 1
0
    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 {}
Esempio n. 2
0
    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 {}
Esempio n. 3
0
    def test_delete_former_main_waypoint(self):
        """ Test that a former main waypoint can be deleted.
        """
        self.route3.main_waypoint_id = self.waypoint3.document_id
        self.session.flush()
        DocumentRest.update_version(self.route3,
                                    self.global_userids['contributor'],
                                    'Update', [UpdateType.FIGURES], [])

        self.route3.main_waypoint_id = self.waypoint1.document_id
        self.session.flush()
        DocumentRest.update_version(self.route3,
                                    self.global_userids['contributor'],
                                    'Update', [UpdateType.FIGURES], [])

        self._delete(self.waypoint3.document_id, 200)
Esempio n. 4
0
    def setUp(self):  # noqa
        super(TestDocumentDeleteRest, self).setUp()
        self._prefix = '/documents/delete/'

        user_id = self.global_userids['contributor']

        self.waypoint1 = Waypoint(
            waypoint_type='summit',
            elevation=2000,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='fr',
                               title='Dent de Crolles',
                               description='...',
                               summary='La Dent de Crolles')
            ])
        self.session.add(self.waypoint1)

        self.waypoint2 = Waypoint(
            waypoint_type='summit',
            elevation=4985,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont Blanc',
                               description='...',
                               document_topic=DocumentTopic(topic_id=1),
                               summary='The heighest point in Europe')
            ])
        self.session.add(self.waypoint2)

        self.waypoint3 = Waypoint(
            waypoint_type='summit',
            elevation=3,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint3.locales.append(
            WaypointLocale(lang='en',
                           title='Mont Granier',
                           description='...',
                           access='yep',
                           document_topic=DocumentTopic(topic_id=2)))
        self.waypoint3.locales.append(
            WaypointLocale(lang='fr',
                           title='Mont Granier',
                           description='...',
                           access='ouai',
                           document_topic=DocumentTopic(topic_id=3)))
        self.session.add(self.waypoint3)
        self.session.flush()

        self.waypoint4 = Waypoint(
            waypoint_type='summit',
            elevation=3,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'))
        self.waypoint4.locales.append(
            WaypointLocale(lang='en', title='Mont Ventoux', description='...'))
        self.session.add(self.waypoint4)
        self.session.flush()

        DocumentRest.create_new_version(self.waypoint1, user_id)
        update_feed_document_create(self.waypoint1, user_id)
        DocumentRest.create_new_version(self.waypoint2, user_id)
        update_feed_document_create(self.waypoint2, user_id)
        DocumentRest.create_new_version(self.waypoint3, user_id)
        update_feed_document_create(self.waypoint3, user_id)
        DocumentRest.create_new_version(self.waypoint4, user_id)
        update_feed_document_create(self.waypoint4, user_id)
        self.session.flush()

        route1_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.route1 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1',
                            main_waypoint_id=self.waypoint1.document_id,
                            geometry=route1_geometry)
        self.route1.locales.append(
            RouteLocale(lang='en',
                        title='Mont Blanc from the air',
                        description='...',
                        title_prefix='Mont Blanc :',
                        gear='paraglider'))
        self.session.add(self.route1)

        route2_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.route2 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1',
                            geometry=route2_geometry)
        self.route2.locales.append(
            RouteLocale(lang='en',
                        title='Mont Blanc from the air',
                        description='...',
                        title_prefix='Mont Blanc :',
                        gear='paraglider',
                        document_topic=DocumentTopic(topic_id=4)))
        self.session.add(self.route2)
        self.session.flush()

        self._add_association(self.waypoint1, self.route1)
        self._add_association(self.waypoint2, self.route2)
        self.session.flush()

        route3_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.route3 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            height_diff_up=800,
                            height_diff_down=800,
                            durations='1',
                            geometry=route3_geometry)
        self.route3.locales.append(
            RouteLocale(lang='en',
                        title='Mont Blanc from the air',
                        description='...',
                        title_prefix='Mont Blanc :',
                        gear='paraglider',
                        document_topic=DocumentTopic(topic_id=5)))
        self.session.add(self.route3)
        self.session.flush()

        DocumentRest.create_new_version(self.route1, user_id)
        update_feed_document_create(self.route1, user_id)
        DocumentRest.create_new_version(self.route2, user_id)
        update_feed_document_create(self.route2, user_id)
        DocumentRest.create_new_version(self.route3, user_id)
        update_feed_document_create(self.route3, user_id)

        self._add_association(self.waypoint1, self.route3)
        self._add_association(self.waypoint2, self.route3)
        self._add_association(self.waypoint3, self.route3)
        self._add_tag(self.route3)
        self.session.flush()

        outing1_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.outing1 = Outing(activities=['skitouring'],
                              date_start=datetime.date(2016, 1, 1),
                              date_end=datetime.date(2016, 1, 1),
                              geometry=outing1_geometry,
                              locales=[
                                  OutingLocale(
                                      lang='en',
                                      title='...',
                                      description='...',
                                      weather='sunny',
                                      document_topic=DocumentTopic(topic_id=6))
                              ])
        self.session.add(self.outing1)
        self.session.flush()

        DocumentRest.create_new_version(self.outing1, user_id)
        update_feed_document_create(self.outing1, user_id)
        self._add_association(self.route1, self.outing1)
        self.session.flush()

        outing1b_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.outing1b = Outing(activities=['skitouring'],
                               date_start=datetime.date(2016, 1, 1),
                               date_end=datetime.date(2016, 1, 1),
                               geometry=outing1b_geometry,
                               redirects_to=self.outing1.document_id,
                               locales=[
                                   OutingLocale(lang='en',
                                                title='...',
                                                description='...',
                                                weather='sunny')
                               ])
        self.session.add(self.outing1b)
        self.session.flush()

        DocumentRest.create_new_version(self.outing1b, user_id)
        self.session.flush()

        outing2_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')
        self.outing2 = Outing(activities=['skitouring'],
                              date_start=datetime.date(2016, 1, 1),
                              date_end=datetime.date(2016, 1, 1),
                              geometry=outing2_geometry,
                              locales=[
                                  OutingLocale(
                                      lang='en',
                                      title='...',
                                      description='...',
                                      weather='sunny',
                                      document_topic=DocumentTopic(topic_id=7))
                              ])
        self.session.add(self.outing2)
        self.session.flush()

        DocumentRest.create_new_version(self.outing2, user_id)
        update_feed_document_create(self.outing2, user_id)
        self._add_association(self.route2, self.outing2)
        self._add_association(self.route3, self.outing2)
        self.session.flush()

        self.article1 = Article(
            activities=['skitouring'],
            categories=['gear'],
            article_type='personal',
            locales=[
                DocumentLocale(lang='en',
                               title='Some article',
                               description='Some content',
                               document_topic=DocumentTopic(topic_id=8))
            ])
        self.session.add(self.article1)
        self.session.flush()

        DocumentRest.create_new_version(self.article1, user_id)
        update_feed_document_create(self.article1, user_id)
        self.session.flush()

        self.article1.locales[0].title = 'Some other article title'
        article1_lang = self.article1.locales[0].lang
        self.session.flush()
        DocumentRest.update_version(self.article1, user_id, 'new title',
                                    [UpdateType.LANG], [article1_lang])
        self.session.flush()

        self._add_association(self.route2, self.article1)
        self._add_association(self.outing2, self.article1)
        self.session.flush()

        self.article2 = Article(activities=['skitouring'],
                                categories=['gear'],
                                article_type='personal',
                                locales=[
                                    DocumentLocale(lang='en',
                                                   title='Some other article',
                                                   description='Some content')
                                ])
        self.session.add(self.article2)
        self.session.flush()

        # Make the article older than 24h old
        written_at = datetime.datetime(2016, 1, 1, 0, 0, 0)
        DocumentRest.create_new_version(self.article2, user_id, written_at)
        update_feed_document_create(self.article2, user_id)
        self.session.flush()

        self.book1 = Book(activities=['skitouring'],
                          book_types=['biography'],
                          locales=[
                              DocumentLocale(
                                  lang='en',
                                  title='Some book',
                                  description='Some content',
                                  document_topic=DocumentTopic(topic_id=9))
                          ])
        self.session.add(self.book1)
        self.session.flush()

        DocumentRest.create_new_version(self.book1, user_id)
        update_feed_document_create(self.book1, user_id)
        self._add_association(self.book1, self.route2)
        self._add_association(self.book1, self.route3)
        self.session.flush()

        self.xreport1 = Xreport(
            event_activity='alpine_climbing',
            event_type='stone_ice_fall',
            locales=[
                XreportLocale(lang='en',
                              title='Lac d\'Annecy',
                              place='some place descrip. in english',
                              document_topic=DocumentTopic(topic_id=10)),
                XreportLocale(lang='fr',
                              title='Lac d\'Annecy',
                              place='some place descrip. in french',
                              document_topic=DocumentTopic(topic_id=11))
            ])
        self.session.add(self.xreport1)
        self.session.flush()

        DocumentRest.create_new_version(self.xreport1, user_id)
        update_feed_document_create(self.xreport1, user_id)
        self._add_association(self.outing2, self.xreport1)
        self._add_association(self.route3, self.xreport1)
        self.session.flush()

        self.image1 = Image(filename='image1.jpg',
                            activities=['paragliding'],
                            height=1500,
                            image_type='collaborative',
                            locales=[
                                DocumentLocale(
                                    lang='en',
                                    title='Mont Blanc from the air',
                                    description='...',
                                    document_topic=DocumentTopic(topic_id=12))
                            ])
        self.session.add(self.image1)
        self.session.flush()

        DocumentRest.create_new_version(self.image1, user_id)
        self._add_association(self.outing1, self.image1)
        self._add_association(self.route3, self.image1)
        self._add_association(self.waypoint3, self.image1)
        self.session.flush()

        update_feed_images_upload(
            [self.image1],
            [{
                'filename': 'image1.jpg',
                'activities': ['paragliding'],
                'image_type': 'collaborative',
                'height': 1500,
                'locales': [{
                    'lang': 'en',
                    'title': 'Mont Blanc from the air'
                }],
                'associations': {
                    'outings': [{
                        'document_id': self.outing1.document_id
                    }],
                    'routes': [{
                        'document_id': self.route3.document_id
                    }],
                    'waypoints': [{
                        'document_id': self.waypoint3.document_id
                    }]
                }
            }], user_id)

        self.image1.filename = 'image1.1.jpg'
        self.session.flush()
        DocumentRest.update_version(self.image1, user_id, 'changed filename',
                                    [UpdateType.FIGURES], [])
        self.session.flush()

        self.topo_map1 = TopoMap(
            code='3232ET',
            editor='IGN',
            scale='25000',
            locales=[DocumentLocale(lang='fr', title='Belley')],
            geometry=DocumentGeometry(
                geom_detail=
                'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))'
            )  # noqa
        )
        self.session.add(self.topo_map1)
        self.session.flush()
        self.session.add(
            TopoMapAssociation(document=self.waypoint2,
                               topo_map=self.topo_map1))
        self.session.add(
            TopoMapAssociation(document=self.waypoint3,
                               topo_map=self.topo_map1))
        self.session.add(
            TopoMapAssociation(document=self.route2, topo_map=self.topo_map1))
        self.session.add(
            TopoMapAssociation(document=self.route3, topo_map=self.topo_map1))
        self.session.flush()

        self.area1 = Area(
            area_type='range',
            geometry=DocumentGeometry(
                geom_detail=
                'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))'  # noqa
            ))
        self.session.add(self.area1)
        self.session.flush()
        self.session.add(
            AreaAssociation(document=self.waypoint2, area=self.area1))
        self.session.add(
            AreaAssociation(document=self.waypoint3, area=self.area1))
        self.session.add(AreaAssociation(document=self.route2,
                                         area=self.area1))
        self.session.add(AreaAssociation(document=self.route3,
                                         area=self.area1))
        self.session.flush()
Esempio n. 5
0
    def setUp(self):  # noqa
        super(TestDocumentMergeRest, self).setUp()
        self._prefix = '/documents/merge'

        contributor_id = self.global_userids['contributor']

        self.waypoint1 = Waypoint(
            waypoint_type='summit',
            elevation=2000,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='fr',
                               title='Dent de Crolles',
                               description='...',
                               summary='La Dent de Crolles')
            ])
        self.session.add(self.waypoint1)
        self.waypoint2 = Waypoint(
            waypoint_type='summit',
            elevation=4985,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont Blanc',
                               description='...',
                               summary='The heighest point in Europe')
            ])
        self.session.add(self.waypoint2)
        self.session.flush()
        self.waypoint3 = Waypoint(
            waypoint_type='summit',
            elevation=4985,
            redirects_to=self.waypoint1.document_id,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont Blanc',
                               description='...',
                               summary='The heighest point in Europe')
            ])
        self.session.add(self.waypoint3)
        self.waypoint4 = Waypoint(
            waypoint_type='summit',
            elevation=4985,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont Blanc',
                               description='...',
                               summary='The heighest point in Europe')
            ])
        self.session.add(self.waypoint4)
        self.session.flush()

        self.route1 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            main_waypoint_id=self.waypoint1.document_id,
                            locales=[
                                RouteLocale(lang='fr',
                                            title='Mont Blanc du ciel',
                                            description='...',
                                            summary='Ski')
                            ])
        self.session.add(self.route1)
        self.session.flush()

        DocumentRest.create_new_version(self.waypoint1, contributor_id)
        update_feed_document_create(self.waypoint1, contributor_id)

        association = Association.create(parent_document=self.waypoint1,
                                         child_document=self.route1)
        self.session.add(association)
        self.session.add(
            association.get_log(self.global_userids['contributor']))

        association = Association.create(parent_document=self.waypoint1,
                                         child_document=self.waypoint4)
        self.session.add(association)
        self.session.add(
            association.get_log(self.global_userids['contributor']))

        association = Association.create(parent_document=self.waypoint2,
                                         child_document=self.waypoint4)
        self.session.add(association)
        self.session.add(
            association.get_log(self.global_userids['contributor']))
        self.session.flush()

        self.image1 = Image(filename='image1.jpg',
                            activities=['paragliding'],
                            height=1500,
                            image_type='collaborative',
                            locales=[
                                DocumentLocale(lang='en',
                                               title='Mont Blanc from the air',
                                               description='...')
                            ])
        self.session.add(self.image1)

        self.image2 = Image(filename='image2.jpg',
                            activities=['paragliding'],
                            height=1500,
                            image_type='collaborative',
                            locales=[
                                DocumentLocale(lang='en',
                                               title='Mont Blanc from the air',
                                               description='...')
                            ])
        self.session.add(self.image2)

        self.session.flush()
        DocumentRest.create_new_version(self.image1, contributor_id)
        self.session.flush()

        self.image1.filename = 'image1.1.jpg'
        self.session.flush()
        DocumentRest.update_version(self.image1, contributor_id,
                                    'changed filename', [UpdateType.FIGURES],
                                    [])
        self.session.flush()
Esempio n. 6
0
    def _add_test_data(self):
        contributor_id = self.global_userids['contributor']

        self.waypoint1 = Waypoint(
            waypoint_type='summit',
            elevation=2000,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'),
            locales=[
                WaypointLocale(lang='fr',
                               title='Dent de Crolles',
                               description='...',
                               summary='La Dent de Crolles')
            ])
        self.session.add(self.waypoint1)
        self.waypoint2 = Waypoint(
            waypoint_type='summit',
            elevation=4810,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635957 5723605)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont Blanc',
                               description='...',
                               summary='The highest point in Europe')
            ])
        self.session.add(self.waypoint2)
        self.waypoint3 = Waypoint(
            waypoint_type='summit',
            elevation=2432,
            geometry=DocumentGeometry(geom='SRID=3857;POINT(635958 5723606)'),
            locales=[
                WaypointLocale(lang='en',
                               title='Mont de Grange',
                               description='...',
                               summary='Some nice peak')
            ])
        self.session.add(self.waypoint3)
        self.session.flush()

        self.initial_route1_geometry = DocumentGeometry(
            geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)',
            geom='SRID=3857;POINT(635961 5723624)')

        self.route1 = Route(activities=['skitouring'],
                            elevation_max=1500,
                            elevation_min=700,
                            main_waypoint_id=self.waypoint2.document_id,
                            geometry=self.initial_route1_geometry,
                            locales=[
                                RouteLocale(lang='fr',
                                            title='Mont Blanc du ciel',
                                            description='...',
                                            summary='Ski')
                            ])
        self.session.add(self.route1)
        self.session.flush()

        DocumentRest.create_new_version(self.waypoint1, contributor_id)
        DocumentRest.create_new_version(self.waypoint2, contributor_id)
        DocumentRest.create_new_version(self.route1, contributor_id)
        update_feed_document_create(self.waypoint1, contributor_id)
        update_feed_document_create(self.waypoint2, contributor_id)
        update_feed_document_create(self.route1, contributor_id)
        self.session.flush()

        association = Association.create(parent_document=self.waypoint1,
                                         child_document=self.route1)
        self.session.add(association)
        self.session.add(association.get_log(contributor_id))
        association = Association.create(parent_document=self.waypoint2,
                                         child_document=self.route1)
        self.session.add(association)
        self.session.add(association.get_log(contributor_id))
        self.session.flush()

        self.waypoint2.elevation = 8848
        for locale in self.waypoint2.locales:
            if locale.lang == 'en':
                locale.title = 'Mount Everest'
                locale.summary = 'The highest point in the world'
        self.waypoint2.geometry.geom = 'SRID=3857;POINT(0 0)'

        self.route1.activities = ['skitouring', 'hiking']
        self.route1.elevation_max = 4500
        self.route1.main_waypoint_id = self.waypoint3.document_id
        for locale in self.route1.locales:
            if locale.lang == 'fr':
                locale.title = 'Some new route name'
        self.route1.geometry.geom = 'SRID=3857;POINT(0 0)'
        self.session.flush()

        DocumentRest.update_version(
            self.waypoint2, contributor_id, 'new version',
            [UpdateType.FIGURES, UpdateType.GEOM, UpdateType.LANG], ['en'])
        DocumentRest.update_version(
            self.route1, contributor_id, 'new version',
            [UpdateType.FIGURES, UpdateType.GEOM, UpdateType.LANG], ['fr'])
        self.session.flush()

        association = Association.create(parent_document=self.waypoint3,
                                         child_document=self.route1)
        self.session.add(association)
        self.session.add(association.get_log(contributor_id))
        self.session.flush()