DNDataArchive::canMoveTo PHP Method

canMoveTo() public method

Check if this member can move archive into the environment.
public canMoveTo ( DNEnvironment $targetEnv, Member | null $member = null ) : boolean
$targetEnv DNEnvironment Environment to check.
$member Member | null The {@link Member} object to test against. If null, uses Member::currentMember();
return boolean true if $member can upload archives linked to this environment, false if they can't.
    public function canMoveTo($targetEnv, $member = null)
    {
        if ($this->Environment()->Project()->ID != $targetEnv->Project()->ID) {
            // We don't permit moving snapshots between projects at this stage.
            return false;
        }
        if (!$member) {
            $member = Member::currentUser();
        }
        // Must be logged in to check permissions
        if (!$member) {
            return false;
        }
        // Admin can always move.
        if (Permission::checkMember($member, 'ADMIN')) {
            return true;
        }
        // Checks if the user can actually access the archive.
        if (!$this->canDownload($member)) {
            return false;
        }
        // Hooks into ArchiveUploaders permission to prevent proliferation of permission checkboxes.
        // Bypasses the quota check - we don't need to check for it as long as we move the snapshot within the project.
        return $targetEnv->ArchiveUploaders()->byID($member->ID) || $member->inGroups($targetEnv->ArchiveUploaderGroups());
    }

Usage Example

Exemplo n.º 1
0
 public function testCanMoveTo()
 {
     $samantha = $this->objFromFixture('Member', 'project1-samantha');
     $sarah = $this->objFromFixture('Member', 'project1-sarah');
     $eva = $this->objFromFixture('Member', 'eva');
     $uat1 = $this->objFromFixture('DNEnvironment', 'project1-uat');
     $live1 = $this->objFromFixture('DNEnvironment', 'project1-live');
     $uat2 = $this->objFromFixture('DNEnvironment', 'project2-uat');
     $live2 = $this->objFromFixture('DNEnvironment', 'project2-live');
     $archive = new DNDataArchive();
     $archive->EnvironmentID = $uat1->ID;
     $archive->write();
     // Samantha doesn't have upload permission to live1.
     $this->assertFalse($archive->canMoveTo($live1, $samantha));
     // Cross-project moves are forbidden.
     $this->assertFalse($archive->canMoveTo($uat2, $samantha));
     // Eva has upload permission to live1.
     $this->assertTrue($archive->canMoveTo($live1, $eva));
     // Cross-project moves are forbidden.
     $this->assertFalse($archive->canMoveTo($uat2, $eva));
     // Sarah has upload permission to live1, but not download to uat1.
     $this->assertFalse($archive->canMoveTo($live1, $sarah));
 }