storage: Fix false error message visiting home page

When visiting homepage as a non-admin user, don't throw an error into the
console about not being able to get root partition information. This is a
regression from refactoring during backups change.

Fixes: #1468.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-01-23 12:53:26 -08:00 committed by James Valleroy
parent c35cecb34a
commit 9e316baa99
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 17 additions and 12 deletions

View File

@ -143,9 +143,11 @@ class UploadArchiveView(SuccessMessageMixin, FormView):
context['title'] = _('Upload and restore a backup file')
context['subsubmenu'] = subsubmenu
try:
disk_info = storage.get_disk_info('/', self.request)
except (PlinthError, PermissionError):
logger.error('Error getting information about root partition.')
disk_info = storage.get_disk_info('/')
except PlinthError as exception:
logger.exception(
'Error getting information about root partition: %s',
exception)
else:
# The maximum file size that can be uploaded and restored is at
# most half of the available disk space:

View File

@ -142,14 +142,13 @@ def get_filesystem_type(mount_point='/'):
raise ValueError('No such mount point')
def get_disk_info(mountpoint, request):
def get_disk_info(mount_point):
"""Get information about the free space of a drive"""
if not is_user_admin(request, cached=True):
raise PermissionError
disks = get_disks()
list_root = [disk for disk in disks if disk['mountpoint'] == mountpoint]
list_root = [disk for disk in disks if disk['mountpoint'] == mount_point]
if not list_root:
raise PlinthError
raise PlinthError('Mount point {} not found.'.format(mount_point))
percent_used = list_root[0]['percent_used']
free_bytes = list_root[0]['free']
free_gib = free_bytes / (1024**3)

View File

@ -32,7 +32,7 @@ from django.views.decorators.http import require_POST
from plinth import actions
from plinth.errors import PlinthError
from plinth.modules import storage
from plinth.utils import format_lazy
from plinth.utils import format_lazy, is_user_admin
from . import get_disk_info, get_error_message
@ -91,10 +91,14 @@ def expand_partition(request, device):
def warn_about_low_disk_space(request):
"""Warn about insufficient space on root partition."""
if not is_user_admin(request, cached=True):
return
try:
root_info = get_disk_info('/', request)
except (PlinthError, PermissionError):
logger.error('Error getting information about root partition.')
root_info = get_disk_info('/')
except PlinthError as exception:
logger.exception('Error getting information about root partition: %s',
exception)
return
message = format_lazy(