Code Duplication    Length = 18-18 lines in 4 locations

code/model/DNEnvironment.php 4 locations

@@ 393-410 (lines=18) @@
390
	 * @param Member|null $member
391
	 * @return boolean
392
	 */
393
	public function canDeploy($member = null) {
394
		if(!$member) {
395
			$member = Member::currentUser();
396
		}
397
		if(!$member) {
398
			return false;
399
		}
400
		// Must be logged in to check permissions
401
402
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
403
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_DEPLOYMENT, $member)) return true;
404
		} else {
405
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_DEPLOYMENT, $member)) return true;
406
		}
407
408
		return $this->Deployers()->byID($member->ID)
409
			|| $member->inGroups($this->DeployerGroups());
410
	}
411
412
	/**
413
	 * Provide reason why the user cannot deploy.
@@ 428-445 (lines=18) @@
425
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
426
	 * @return boolean true if $member can restore, and false if they can't.
427
	 */
428
	public function canRestore($member = null) {
429
		if(!$member) {
430
			$member = Member::currentUser();
431
		}
432
		if(!$member) {
433
			return false;
434
		}
435
		// Must be logged in to check permissions
436
437
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
438
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
439
		} else {
440
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
441
		}
442
443
		return $this->CanRestoreMembers()->byID($member->ID)
444
			|| $member->inGroups($this->CanRestoreGroups());
445
	}
446
447
	/**
448
	 * Allows only selected {@link Member} objects to backup this {@link DNEnvironment} to a {@link DNDataArchive}
@@ 520-537 (lines=18) @@
517
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
518
	 * @return boolean true if $member can download archives from this environment, false if they can't.
519
	 */
520
	public function canDownloadArchive($member = null) {
521
		if(!$member) {
522
			$member = Member::currentUser();
523
		}
524
		if(!$member) {
525
			return false;
526
		}
527
		// Must be logged in to check permissions
528
529
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
530
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
531
		} else {
532
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
533
		}
534
535
		return $this->ArchiveDownloaders()->byID($member->ID)
536
			|| $member->inGroups($this->ArchiveDownloaderGroups());
537
	}
538
539
	/**
540
	 * Determine if the specified user can abort any pipelines
@@ 589-606 (lines=18) @@
586
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
587
	 * @return boolean true if $member can delete archives from this environment, false if they can't.
588
	 */
589
	public function canDeleteArchive($member = null) {
590
		if(!$member) {
591
			$member = Member::currentUser();
592
		}
593
		if(!$member) {
594
			return false;
595
		}
596
		// Must be logged in to check permissions
597
598
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
599
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
600
		} else {
601
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
602
		}
603
604
		return $this->ArchiveDeleters()->byID($member->ID)
605
			|| $member->inGroups($this->ArchiveDeleterGroups());
606
	}
607
	/**
608
	 * Get a string of groups/people that are allowed to deploy to this environment.
609
	 * Used in DNRoot_project.ss to list {@link Member}s who have permission to perform this action.