samba: Hide common system partitions

Hide some common partitions where users shouldn't create a share -
/.snapshots, /boot and /boot/firmware.

Tested that mount points 'boot' and '.snapshots' do not appear in the
list of shareable disks on Pioneer Freedombox.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Add /boot/efi to list of ignored mount points]
[sunil: Update test to check if mounts points are ignored]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa 2020-07-17 18:45:02 +03:00 committed by Sunil Mohan Adapa
parent c7bf1bb46f
commit 31eb35cb9e
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 19 additions and 3 deletions

View File

@ -27,6 +27,14 @@ DISKS = [{
'percent_used': 63,
'size_str': '9.5 GiB',
'used_str': '5.7 GiB'
}, {
'device': '/dev/sda2',
'label': '',
'filesystem_type': 'vfat',
'mount_point': '/boot/efi',
'percent_used': 50,
'size_str': '150 MiB',
'used_str': '75 MiB'
}]
SHARES = [
@ -96,7 +104,7 @@ def test_samba_shares_view(rf):
view = views.SambaAppView.as_view()
response, _ = make_request(rf.get(''), view)
assert response.context_data['disks'] == DISKS
assert response.context_data['disks'] == [DISKS[0]]
assert response.context_data['shared_mounts'] == {
'/': ['open', 'home'],
'/media/root/otherdisk': ['open']

View File

@ -12,7 +12,6 @@ from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST
from plinth import views
from plinth.errors import ActionError
from plinth.modules import samba, storage
@ -20,6 +19,15 @@ from plinth.modules import samba, storage
logger = logging.getLogger(__name__)
def get_share_mounts():
"""Return list of mount points."""
ignore_points = ('/boot', '/boot/efi', '/boot/firmware', '/.snapshots')
return [
mount for mount in storage.get_mounts()
if mount['mount_point'] not in ignore_points
]
class SambaAppView(views.AppView):
"""Samba sharing basic configuration."""
app_id = 'samba'
@ -28,7 +36,7 @@ class SambaAppView(views.AppView):
def get_context_data(self, *args, **kwargs):
"""Return template context data."""
context = super().get_context_data(*args, **kwargs)
disks = storage.get_mounts()
disks = get_share_mounts()
shares = samba.get_shares()
for disk in disks: