Code Duplication    Length = 18-18 lines in 4 locations

code/model/DNEnvironment.php 4 locations

@@ 402-419 (lines=18) @@
399
	 * @param Member|null $member
400
	 * @return boolean
401
	 */
402
	public function canDeploy($member = null) {
403
		if(!$member) {
404
			$member = Member::currentUser();
405
		}
406
		if(!$member) {
407
			return false;
408
		}
409
		// Must be logged in to check permissions
410
411
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
412
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_DEPLOYMENT, $member)) return true;
413
		} else {
414
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_DEPLOYMENT, $member)) return true;
415
		}
416
417
		return $this->Deployers()->byID($member->ID)
418
			|| $member->inGroups($this->DeployerGroups());
419
	}
420
421
	/**
422
	 * Provide reason why the user cannot deploy.
@@ 437-454 (lines=18) @@
434
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
435
	 * @return boolean true if $member can restore, and false if they can't.
436
	 */
437
	public function canRestore($member = null) {
438
		if(!$member) {
439
			$member = Member::currentUser();
440
		}
441
		if(!$member) {
442
			return false;
443
		}
444
		// Must be logged in to check permissions
445
446
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
447
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
448
		} else {
449
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
450
		}
451
452
		return $this->CanRestoreMembers()->byID($member->ID)
453
			|| $member->inGroups($this->CanRestoreGroups());
454
	}
455
456
	/**
457
	 * Allows only selected {@link Member} objects to backup this {@link DNEnvironment} to a {@link DNDataArchive}
@@ 529-546 (lines=18) @@
526
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
527
	 * @return boolean true if $member can download archives from this environment, false if they can't.
528
	 */
529
	public function canDownloadArchive($member = null) {
530
		if(!$member) {
531
			$member = Member::currentUser();
532
		}
533
		if(!$member) {
534
			return false;
535
		}
536
		// Must be logged in to check permissions
537
538
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
539
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
540
		} else {
541
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
542
		}
543
544
		return $this->ArchiveDownloaders()->byID($member->ID)
545
			|| $member->inGroups($this->ArchiveDownloaderGroups());
546
	}
547
548
	/**
549
	 * Determine if the specified user can abort any pipelines
@@ 598-615 (lines=18) @@
595
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
596
	 * @return boolean true if $member can delete archives from this environment, false if they can't.
597
	 */
598
	public function canDeleteArchive($member = null) {
599
		if(!$member) {
600
			$member = Member::currentUser();
601
		}
602
		if(!$member) {
603
			return false;
604
		}
605
		// Must be logged in to check permissions
606
607
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
608
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
609
		} else {
610
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
611
		}
612
613
		return $this->ArchiveDeleters()->byID($member->ID)
614
			|| $member->inGroups($this->ArchiveDeleterGroups());
615
	}
616
	/**
617
	 * Get a string of groups/people that are allowed to deploy to this environment.
618
	 * Used in DNRoot_project.ss to list {@link Member}s who have permission to perform this action.