Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-132266 / 25.04 / Allow filesystem.setperm to not have mode specified #14896

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/middlewared/middlewared/api/v25_04_0/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,20 @@ class FilesystemChownResult(BaseModel):

@single_argument_args('filesystem_setperm')
class FilesystemSetPermArgs(FilesystemPermChownBase):
mode: UnixPerm
mode: UnixPerm | None = None
options: FilesystemSetpermOptions = Field(default=FilesystemSetpermOptions())

@model_validator(mode='after')
def payload_is_actionable(self) -> Self:
""" User should be changing something. Either stripping ACL or setting mode """
if self.mode is None and self.options.stripacl is False:
raise ValueError(
'Payload must either explicitly specify permissions or '
'contain the stripacl option.'
)

return self


class FilesystemSetPermResult(BaseModel):
result: Literal[None]
29 changes: 29 additions & 0 deletions tests/api2/test_filesystem_setperm_strip_acl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

from middlewared.test.integration.assets.pool import dataset
from middlewared.test.integration.utils import call


def test__strip_acl_setperm():
""" verify ACL can be stripped on single file by explicity specifying strip """
with dataset('stripacl_test', {'share_type': 'SMB'}) as ds:
mp = os.path.join('/mnt', ds)

dir_path = os.path.join(mp, 'thedir')
assert call('filesystem.stat', mp)['acl']

call('filesystem.mkdir', {'path': dir_path, 'options': {'raise_chmod_error': False}})
assert call('filesystem.stat', dir_path)['acl']

# nonrecursive
call('filesystem.setperm', {'path': mp, 'options': {'stripacl': True}}, job=True)

# target for setperm should not have ACL anymore
assert not call('filesystem.stat', mp)['acl']

# but directory should
assert call('filesystem.stat', dir_path)['acl']

# recursive
call('filesystem.setperm', {'path': mp, 'options': {'stripacl': True, 'recursive': True}}, job=True)
assert not call('filesystem.stat', dir_path)['acl']
Loading