Esempio n. 1
0
def _usage_dirs(calculate_usage=True):
    """
    Provide usage data

    Return maximum size and, optionally, current usage of a number of directories

    :param bool calculate_usage: True if usage should be calculated.
    :returns OrderedDict: Dict where key is a descriptive handle and value is a dict with the path, description, parent directory ID, and optionally size and usage.
    """
    # Put spaces before directories contained by the spaces
    #
    # Description is optional, but either a path or a location purpose (used to
    # look up the path) should be specified
    #
    # If only certain sudirectories within a path should be deleted, set
    # 'subdirectories' to a list of them
    dir_defs = (('shared', {
        'path':
        helpers.get_client_config_value('sharedDirectoryMounted')
    }), ('dips', {
        'description': 'DIP uploads',
        'path': os.path.join('watchedDirectories', 'uploadedDIPs'),
        'contained_by': 'shared'
    }), ('rejected', {
        'description': 'Rejected',
        'path': 'rejected',
        'contained_by': 'shared'
    }), ('failed', {
        'description': 'Failed',
        'path': 'failed',
        'contained_by': 'shared'
    }), ('tmp', {
        'description': 'Temporary file storage',
        'path': 'tmp',
        'contained_by': 'shared'
    }))

    dirs = collections.OrderedDict(dir_defs)

    # Resolve location paths and make relative paths absolute
    for _, dir_spec in dirs.iteritems():
        if 'contained_by' in dir_spec:
            # If contained, make path absolute
            space = dir_spec['contained_by']
            absolute_path = os.path.join(dirs[space]['path'], dir_spec['path'])
            dir_spec['path'] = absolute_path

            if calculate_usage:
                dir_spec['size'] = dirs[space]['size']
                dir_spec['used'] = _usage_get_directory_used_bytes(
                    dir_spec['path'])
        elif calculate_usage:
            # Get size/usage of space
            space_path = dir_spec['path']
            dir_spec['size'] = _usage_check_directory_volume_size(space_path)
            dir_spec['used'] = _usage_get_directory_used_bytes(space_path)

    return dirs
Esempio n. 2
0
 def inner(request, *args, **kwargs):
     elasticsearch_disabled = helpers.get_client_config_value('disableElasticsearchIndexing')
     if elasticsearch_disabled:
         return func(request, *args, **kwargs)
     else:
         status = elasticSearchFunctions.check_server_status()
         if status == 'OK':
             return func(request, *args, **kwargs)
         else:
             return render(request, 'elasticsearch_error.html', {'status': status})
Esempio n. 3
0
 def inner(request, *args, **kwargs):
     elasticsearch_disabled = helpers.get_client_config_value(
         'disableElasticsearchIndexing')
     if elasticsearch_disabled:
         return func(request, *args, **kwargs)
     else:
         status = elasticSearchFunctions.check_server_status()
         if status == 'OK':
             return func(request, *args, **kwargs)
         else:
             return render(request, 'elasticsearch_error.html',
                           {'status': status})
Esempio n. 4
0
def send_thumbnail(request, fileuuid):
    # get AIP location to use to find root of AIP storage
    sipuuid = helpers.get_file_sip_uuid(fileuuid)

    thumbnail_path = os.path.join(
        helpers.get_client_config_value('sharedDirectoryMounted'), 'www',
        'thumbnails', sipuuid, fileuuid + '.jpg')

    # send "blank" thumbnail if one exists:
    # Because thumbnails aren't kept in ElasticSearch they can be queried for,
    # during searches, from multiple dashboard servers.
    # Because ElasticSearch don't know if a thumbnail exists or not, this is
    # a way of not causing visual disruption if a thumbnail doesn't exist.
    if not os.path.exists(thumbnail_path):
        thumbnail_path = os.path.join(settings.BASE_PATH,
                                      'media/images/1x1-pixel.png')

    return helpers.send_file(request, thumbnail_path)
Esempio n. 5
0
def edit(request, id=None):
    if get_client_config_value('kioskMode') == 'True':
        return redirect('main.views.forbidden')

    # Forbidden if user isn't an admin and is trying to edit another user
    if str(request.user.id) != str(id) and id != None:
        if request.user.is_superuser is False:
            return redirect('main.views.forbidden')

    # Load user
    if id is None:
        user = request.user
        title = 'Edit your profile (%s)' % user
    else:
        try:
            user = User.objects.get(pk=id)
            title = 'Edit user %s' % user
        except:
            raise Http404

    # Form
    if request.method == 'POST':
        form = UserChangeForm(request.POST, instance=user)
        if form.is_valid():
            user = form.save(commit=False)

            # change password if requested
            password = request.POST.get('password', '')
            if password != '':
                user.set_password(password)

            # prevent non-admin from self-promotion
            if not request.user.is_superuser:
                user.is_superuser = False

            user.save()

            # regenerate API key if requested
            regenerate_api_key = request.POST.get('regenerate_api_key', '')
            if regenerate_api_key != '':
                try:
                    api_key = ApiKey.objects.get(user_id=user.pk)
                except ApiKey.DoesNotExist:
                    api_key = ApiKey.objects.create(user=user)
                api_key.key = api_key.generate_key()
                api_key.save()

            # determine where to redirect to
            if request.user.is_superuser is False:
                return_view = 'components.accounts.views.edit'
            else:
                return_view = 'components.accounts.views.list'

            messages.info(request, 'Saved.')
            return redirect(return_view)
    else:
        suppress_administrator_toggle = True
        if request.user.is_superuser:
            suppress_administrator_toggle = False
        form = UserChangeForm(
            instance=user,
            suppress_administrator_toggle=suppress_administrator_toggle)

    # load API key for display
    try:
        api_key_data = ApiKey.objects.get(user_id=user.pk)
        api_key = api_key_data.key
    except:
        api_key = '<no API key generated>'

    return render(
        request, 'accounts/edit.html', {
            'hide_features': hidden_features(),
            'form': form,
            'user': user,
            'api_key': api_key,
            'title': title
        })