Skip to content

Commit

Permalink
Location: disallow move based on purpose
Browse files Browse the repository at this point in the history
The `posix_move` should not be always allowed for certain locations. This
commit ensures that it's not used when the original location is backlog or
AIP storage.

This is connected to archivematica/Issues#270.
  • Loading branch information
sevein committed Oct 25, 2018
1 parent 707a376 commit 239faee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions storage_service/locations/api/resources.py
Expand Up @@ -372,6 +372,10 @@ def _move_files_between_locations(self, files, origin_location, destination_loca
destination_location.relative_path, destination_path)

try:
if origin_location.is_move_allowed():
LOGGER.debug(
'Moving files from this location is not allowed')
raise PosixMoveUnsupportedError
origin_space.posix_move(
source_path=source_path,
destination_path=destination_path,
Expand Down
10 changes: 10 additions & 0 deletions storage_service/locations/models/location.py
Expand Up @@ -41,6 +41,12 @@ class Location(models.Model):
TRANSFER_SOURCE = 'TS'
REPLICATOR = 'RP'

# List of purposes where
PURPOSES_DISALLOWED_MOVE = (
BACKLOG,
AIP_STORAGE,
)

PURPOSE_CHOICES = (
(AIP_RECOVERY, _('AIP Recovery')),
(AIP_STORAGE, _('AIP Storage')),
Expand Down Expand Up @@ -133,6 +139,10 @@ def get_description(self):
""" Returns a user-friendly description (or the path). """
return self.description or self.full_path

def is_move_allowed(self):
"""Returns whether it's allowed to move contents from this location."""
return self.purpose not in self.PURPOSES_DISALLOWED_MOVE


@receiver(models.signals.pre_delete, sender=Location)
def unset_default_location(sender, instance, using, **kwargs):
Expand Down

0 comments on commit 239faee

Please sign in to comment.