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

[Backport 4.0.x] [Fixes #10142] storage_manager copy dont assign the folder/file permi… #10154

Merged
merged 1 commit into from
Oct 17, 2022
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
11 changes: 10 additions & 1 deletion geonode/storage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def copy_files_list(self, files: List[str]):
out = []
random_suffix = f'{uuid1().hex[:8]}'
new_path = mkdtemp()

if settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS is not None:
# value is always set by default as None
# https://docs.djangoproject.com/en/3.2/ref/settings/#file-upload-directory-permissions
os.chmod(new_path, settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS)
_new_path = None
for f in files:
with self.open(f, 'rb+') as open_file:
old_file_name, _ = os.path.splitext(os.path.basename(f))
Expand All @@ -199,7 +205,10 @@ def copy_files_list(self, files: List[str]):
new_file = f"{new_path}/{suffixed_name}{ext}"
else:
new_file = f"{new_path}/{old_file_name}_{random_suffix}{ext}"
out.append(self.copy_single_file(open_file, new_file))
_new_path = self.copy_single_file(open_file, new_file)
out.append(_new_path)
if _new_path:
os.chmod(_new_path, settings.FILE_UPLOAD_PERMISSIONS)
return out

def copy_single_file(self, old_file: BinaryIO, new_file: str):
Expand Down
19 changes: 18 additions & 1 deletion geonode/storage/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from geonode.storage.gcs import GoogleStorageManager
from geonode.storage.dropbox import DropboxStorageManager
from geonode.base.populate_test_data import create_single_dataset
from geonode.tests.base import GeoNodeBaseTestSupport


class TestDropboxStorageManager(SimpleTestCase):
Expand Down Expand Up @@ -281,7 +282,7 @@ def test_aws_size(self, aws):
aws.assert_called_once_with('name')


class TestStorageManager(TestCase):
class TestStorageManager(GeoNodeBaseTestSupport):

def setUp(self):
self.sut = StorageManager
Expand Down Expand Up @@ -400,6 +401,22 @@ def test_storage_manager_replace_single_file(self, path, strg):
output = self.sut().replace(dataset, new_file)
self.assertListEqual([expected], output['files'])

@override_settings(FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o777)
@override_settings(FILE_UPLOAD_PERMISSIONS=0o777)
def test_storage_manager_copy(self):
'''
Test that the copy works as expected and the permissions are corerct
'''
dataset = create_single_dataset(name="test_copy")
dataset.files = [os.path.join(f"{self.project_root}", "tests/data/test_sld.sld")]
dataset.save()
output = self.sut().copy(dataset)

self.assertTrue(os.path.exists(output.get("files")[0]))
self.assertEqual(os.stat(os.path.exists(output.get("files")[0])).st_mode, 8592)
os.remove(output.get("files")[0])
self.assertFalse(os.path.exists(output.get("files")[0]))


class TestDataRetriever(TestCase):
@classmethod
Expand Down