Esempio n. 1
0
def storagesetup(request):
    # Display the dashboard UUID on the storage service setup page
    dashboard_uuid = helpers.get_setting("dashboard_uuid", None)
    assert dashboard_uuid is not None

    # Prefill the storage service URL
    inital_data = {
        "storage_service_url":
        helpers.get_setting("storage_service_url", "http://localhost:8000"),
        "storage_service_user":
        helpers.get_setting("storage_service_user", "test"),
        "storage_service_apikey":
        helpers.get_setting("storage_service_apikey", None),
    }
    storage_form = StorageSettingsForm(request.POST or None,
                                       initial=inital_data)
    if not storage_form.is_valid():
        return render(request, "installer/storagesetup.html", locals())
    storage_form.save()

    try:
        use_default_config = storage_form.cleaned_data[
            "storage_service_use_default_config"]
        setup_pipeline_in_ss(use_default_config)
    except Exception:
        messages.warning(
            request,
            _("Error creating pipeline: is the storage server running? Please contact an administrator."
              ),
        )

    return redirect("main.views.home")
Esempio n. 2
0
def storagesetup(request):
    # Display the dashboard UUID on the storage service setup page
    dashboard_uuid = helpers.get_setting('dashboard_uuid', None)
    assert dashboard_uuid is not None

    # Prefill the storage service URL
    inital_data = {
        'storage_service_url':
        helpers.get_setting('storage_service_url', 'http://localhost:8000'),
        'storage_service_user':
        helpers.get_setting('storage_service_user', 'test'),
        'storage_service_apikey':
        helpers.get_setting('storage_service_apikey', None)
    }
    storage_form = StorageSettingsForm(request.POST or None,
                                       initial=inital_data)
    if not storage_form.is_valid():
        return render(request, 'installer/storagesetup.html', locals())
    storage_form.save()

    try:
        use_default_config = storage_form.cleaned_data[
            'storage_service_use_default_config']
        setup_pipeline_in_ss(use_default_config)
    except Exception:
        messages.warning(
            request,
            _('Error creating pipeline: is the storage server running? Please contact an administrator.'
              ))

    return redirect('main.views.home')
Esempio n. 3
0
def general(request):
    toggleableSettings = {
        'dashboard_administration_atom_dip_enabled':
        'Hide AtoM DIP upload link',
        'dashboard_administration_dspace_enabled': 'Hide DSpace transfer type',
    }
    initial_data = _intial_settings_data()
    interface_form = SettingsForm(request.POST or None,
                                  prefix='interface',
                                  reverse_checkboxes=toggleableSettings)
    storage_form = StorageSettingsForm(request.POST or None,
                                       prefix='storage',
                                       initial=initial_data)

    if interface_form.is_valid() and storage_form.is_valid():
        interface_form.save()
        storage_form.save()
        messages.info(request, 'Saved.')

    dashboard_uuid = helpers.get_setting('dashboard_uuid')
    try:
        pipeline = storage_service._get_pipeline(dashboard_uuid)
    except Exception:
        messages.warning(
            request,
            "Storage server inaccessible.  Please contact an administrator or update storage service URL below."
        )
    else:
        if not pipeline:
            messages.warning(
                request,
                "This pipeline is not registered with the storage service or has been disabled in the storage service.  Please contact an administrator."
            )
    hide_features = helpers.hidden_features()
    return render(request, 'administration/general.html', locals())
Esempio n. 4
0
def general(request):
    initial_data = _intial_settings_data()
    initial_data['storage_service_use_default_config'] = {
        'False': False}.get(
            initial_data.get('storage_service_use_default_config', True),
            True)
    general_form = GeneralSettingsForm(request.POST or None,
                                       prefix='general', initial=initial_data)
    storage_form = StorageSettingsForm(request.POST or None,
                                       prefix='storage', initial=initial_data)
    checksum_form = ChecksumSettingsForm(request.POST or None,
                                         prefix='checksum algorithm',
                                         initial=initial_data)

    forms = (general_form, storage_form, checksum_form)
    if all(map(lambda form: form.is_valid(), forms)):
        map(lambda form: form.save(), forms)
        messages.info(request, _('Saved.'))

    dashboard_uuid = helpers.get_setting('dashboard_uuid')

    not_created_yet = False
    try:
        pipeline = storage_service.get_pipeline(dashboard_uuid)
    except Exception as err:
        if err.response is not None and err.response.status_code == 404:
            # The server has returned a 404, we're going to assume that this is
            # the Storage Service telling us that the pipeline is unknown.
            not_created_yet = True
        else:
            messages.warning(request, _('Storage Service inaccessible. Please'
                                        ' contact an administrator or update'
                                        ' the Storage Sevice URL below.'
                                        '<hr />%(error)s' % {'error': err}))

    if not_created_yet:
        if storage_form.is_valid():
            try:
                setup_pipeline_in_ss(
                    storage_form.cleaned_data[
                        'storage_service_use_default_config'])
            except Exception as err:
                messages.warning(request, _('Storage Service failed to create the'
                                            ' pipeline. This can happen if'
                                            ' the pipeline exists but it is'
                                            ' disabled. Please contact an'
                                            ' administrator.'
                                            '<hr />%(error)s'
                                            % {'error': err}))
        else:
            messages.warning(request, _('Storage Service returned a 404 error.'
                                        ' Has the pipeline been disabled or is'
                                        ' it not registered yet? Submitting'
                                        ' form will attempt to register the'
                                        ' pipeline.'))

    return render(request, 'administration/general.html', locals())
Esempio n. 5
0
def storagesetup(request):
    # Display the dashboard UUID on the storage service setup page
    dashboard_uuid = helpers.get_setting('dashboard_uuid', None)
    assert dashboard_uuid is not None
    # Prefill the storage service URL
    inital_data = {
        'storage_service_url':
        helpers.get_setting('storage_service_url', 'http://localhost:8000'),
        'storage_service_user':
        helpers.get_setting('storage_service_user', 'test'),
        'storage_service_apikey':
        helpers.get_setting('storage_service_apikey', None)
    }
    storage_form = StorageSettingsForm(request.POST or None,
                                       initial=inital_data)
    if storage_form.is_valid():
        # Set storage service URL
        storage_form.save()
        if "use_default" in request.POST:
            shared_path = helpers.get_server_config_value('sharedDirectory')
            # Post first user & API key
            user = User.objects.all()[0]
            api_key = ApiKey.objects.get(user=user)
            # Create pipeline, tell it to use default setup
            try:
                storage_service.create_pipeline(
                    create_default_locations=True,
                    shared_path=shared_path,
                    api_username=user.username,
                    api_key=api_key.key,
                )
            except Exception:
                messages.warning(
                    request,
                    'Error creating pipeline: is the storage server running? Please contact an administrator.'
                )
            else:
                # Add the storage service URL to the API whitelist
                ss_url = urlparse.urlparse(
                    helpers.get_setting('storage_service_url'))
                whitelist = helpers.get_setting('api_whitelist', '127.0.0.1')
                whitelist = '\n'.join([whitelist, ss_url.hostname])
                helpers.set_setting('api_whitelist', whitelist)
        else:
            # Storage service manually set up, just register Pipeline if
            # possible. Do not provide additional information about the shared
            # path, or API, as this is probably being set up in the storage
            # service manually.
            try:
                storage_service.create_pipeline()
            except Exception:
                pass
        return redirect('main.views.home')
    else:
        return render(request, 'installer/storagesetup.html', locals())
Esempio n. 6
0
 def save_ss_settings(self, options):
     POST = QueryDict("", mutable=True)
     POST.update({
         "storage_service_url": options["ss_url"],
         "storage_service_user": options["ss_user"],
         "storage_service_apikey": options["ss_api_key"],
     })
     form = StorageSettingsForm(POST)
     if not form.is_valid():
         raise CommandError("SS attributes are invalid")
     form.save()
Esempio n. 7
0
 def save_ss_settings(self, options):
     POST = QueryDict('', mutable=True)
     POST.update({
         'storage_service_url': options['ss_url'],
         'storage_service_user': options['ss_user'],
         'storage_service_apikey': options['ss_api_key'],
     })
     form = StorageSettingsForm(POST)
     if not form.is_valid():
         raise CommandError('SS attributes are invalid')
     form.save()
Esempio n. 8
0
def general(request):
    initial_data = _intial_settings_data()
    initial_data["storage_service_use_default_config"] = {"False": False}.get(
        initial_data.get("storage_service_use_default_config", True), True
    )
    general_form = GeneralSettingsForm(
        request.POST or None, prefix="general", initial=initial_data
    )
    storage_form = StorageSettingsForm(
        request.POST or None, prefix="storage", initial=initial_data
    )
    checksum_form = ChecksumSettingsForm(
        request.POST or None, prefix="checksum algorithm", initial=initial_data
    )

    forms = (general_form, storage_form, checksum_form)
    if all(map(lambda form: form.is_valid(), forms)):
        for item in forms:
            item.save()
        messages.info(request, _("Saved."))

    dashboard_uuid = helpers.get_setting("dashboard_uuid")

    not_created_yet = False
    try:
        pipeline = storage_service.get_pipeline(dashboard_uuid)
    except Exception as err:
        if err.response is not None and err.response.status_code == 404:
            # The server has returned a 404, we're going to assume that this is
            # the Storage Service telling us that the pipeline is unknown.
            not_created_yet = True
        else:
            messages.warning(
                request,
                _(
                    "Storage Service inaccessible. Please"
                    " contact an administrator or update"
                    " the Storage Sevice URL below."
                    "<hr />%(error)s" % {"error": err}
                ),
            )

    if not_created_yet:
        if storage_form.is_valid():
            try:
                setup_pipeline_in_ss(
                    storage_form.cleaned_data["storage_service_use_default_config"]
                )
            except Exception as err:
                messages.warning(
                    request,
                    _(
                        "Storage Service failed to create the"
                        " pipeline. This can happen if"
                        " the pipeline exists but it is"
                        " disabled. Please contact an"
                        " administrator."
                        "<hr />%(error)s" % {"error": err}
                    ),
                )
        else:
            messages.warning(
                request,
                _(
                    "Storage Service returned a 404 error."
                    " Has the pipeline been disabled or is"
                    " it not registered yet? Submitting"
                    " form will attempt to register the"
                    " pipeline."
                ),
            )

    return render(request, "administration/general.html", locals())