mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-22 10:01:45 +00:00
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:
parent
c35cecb34a
commit
9e316baa99
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user