Esempio n. 1
0
    def get(self, request, project_id, revision=None):
        """
        Get a publication. If a revision is not supplied, return
        the "Original" publication. Include the latest version if it
        is not being queried.
        """
        es_client = new_es_client()
        pub = BaseESPublication(project_id=project_id,
                                revision=revision,
                                using=es_client)
        latest_revision = IndexedPublication.max_revision(
            project_id=project_id, using=es_client)
        latest_pub_dict = None
        if latest_revision > 0 and latest_revision != revision:
            latest_pub = BaseESPublication(project_id=project_id,
                                           revision=latest_revision,
                                           using=es_client)
            if latest_pub is not None and hasattr(latest_pub, 'project'):
                latest_pub_dict = latest_pub.to_dict()

        if pub is not None and hasattr(pub, 'project'):
            pub_dict = pub.to_dict()

            if pub_dict['project']['value']['projectType'] != 'other':
                metrics.info('Data Depot',
                             extra={
                                 'user':
                                 request.user.username,
                                 'sessionId':
                                 getattr(request.session, 'session_key', ''),
                                 'operation':
                                 'listing',
                                 'agent':
                                 request.META.get('HTTP_USER_AGENT'),
                                 'ip':
                                 get_client_ip(request),
                                 'info': {
                                     'api': 'agave',
                                     'systemId':
                                     'designsafe.storage.published',
                                     'filePath': project_id,
                                     'query': {}
                                 }
                             })

            if latest_pub_dict:
                pub_dict['latestRevision'] = latest_pub_dict
            return JsonResponse(pub_dict)
        else:
            return JsonResponse({
                'status': 404,
                'message': 'Not found'
            },
                                status=404)
Esempio n. 2
0
    def post(self, request, **kwargs):
        """
        Amend a Publication
        """
        if request.is_ajax():
            data = json.loads(request.body)
        else:
            data = request.POST

        project_id = data['projectId']
        authors = data.get('authors', None)
        amendments = data.get('amendments', None)
        current_revision = IndexedPublication.max_revision(
            project_id=project_id)

        (tasks.amend_publication_data.s(project_id, amendments, authors,
                                        current_revision).set(queue='api')
         | tasks.zip_publication_files.si(
             project_id, current_revision).set(queue='files')).apply_async()

        return JsonResponse({'success': 'Publication is being amended.'},
                            status=200)
Esempio n. 3
0
    def post(self, request, **kwargs):
        """
        Publish a project or version a publication
        """
        if request.is_ajax():
            data = json.loads(request.body)
        else:
            data = request.POST

        status = data.get('status', 'saved')
        revision = data.get('revision', None)
        revision_text = data.get('revisionText', None)
        revision_titles = data.get('revisionTitles', None)
        revised_authors = data.get('revisionAuthors', None)
        selected_files = data.get('selectedFiles', None)

        project_id = data['publication']['project']['value']['projectId']

        current_revision = None
        # If revision is truthy, increment the revision count and pass it to the pipeline.
        if revision:
            latest_revision = IndexedPublication.max_revision(
                project_id=project_id)
            current_revision = latest_revision + 1 if latest_revision >= 2 else 2

        pub = initilize_publication(data['publication'],
                                    status,
                                    revision=current_revision,
                                    revision_text=revision_text,
                                    revision_titles=revision_titles)

        if data.get('status', 'save').startswith('publish'):
            (tasks.freeze_publication_meta.s(
                project_id=pub.projectId,
                entity_uuids=data.get('mainEntityUuids'),
                revision=current_revision,
                revised_authors=revised_authors).set(queue='api') | group(
                    tasks.save_publication.si(
                        project_id=pub.projectId,
                        entity_uuids=data.get('mainEntityUuids'),
                        revision=current_revision,
                        revised_authors=revised_authors).set(queue='files',
                                                             countdown=60),
                    tasks.copy_publication_files_to_corral.si(
                        project_id=pub.projectId,
                        revision=current_revision,
                        selected_files=selected_files).set(queue='files',
                                                           countdown=60))
             | tasks.swap_file_tag_uuids.si(pub.projectId,
                                            revision=current_revision)
             | tasks.set_publish_status.si(
                 project_id=pub.projectId,
                 entity_uuids=data.get('mainEntityUuids'),
                 revision=current_revision) | tasks.zip_publication_files.si(
                     pub.projectId, revision=current_revision)
             | tasks.email_user_publication_request_confirmation.si(
                 request.user.username) | tasks.check_published_files.si(
                     pub.projectId,
                     revision=current_revision,
                     selected_files=selected_files)).apply_async()

        return JsonResponse({'success': 'Project is publishing.'}, status=200)