Code Duplication    Length = 18-18 lines in 4 locations

code/model/DNEnvironment.php 4 locations

@@ 379-396 (lines=18) @@
376
	 * @param Member|null $member
377
	 * @return boolean
378
	 */
379
	public function canDeploy($member = null) {
380
		if(!$member) {
381
			$member = Member::currentUser();
382
		}
383
		if(!$member) {
384
			return false;
385
		}
386
		// Must be logged in to check permissions
387
388
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
389
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_DEPLOYMENT, $member)) return true;
390
		} else {
391
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_DEPLOYMENT, $member)) return true;
392
		}
393
394
		return $this->Deployers()->byID($member->ID)
395
			|| $member->inGroups($this->DeployerGroups());
396
	}
397
398
	/**
399
	 * Allows only selected {@link Member} objects to restore {@link DNDataArchive} objects into this
@@ 405-422 (lines=18) @@
402
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
403
	 * @return boolean true if $member can restore, and false if they can't.
404
	 */
405
	public function canRestore($member = null) {
406
		if(!$member) {
407
			$member = Member::currentUser();
408
		}
409
		if(!$member) {
410
			return false;
411
		}
412
		// Must be logged in to check permissions
413
414
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
415
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
416
		} else {
417
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
418
		}
419
420
		return $this->CanRestoreMembers()->byID($member->ID)
421
			|| $member->inGroups($this->CanRestoreGroups());
422
	}
423
424
	/**
425
	 * Allows only selected {@link Member} objects to backup this {@link DNEnvironment} to a {@link DNDataArchive}
@@ 497-514 (lines=18) @@
494
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
495
	 * @return boolean true if $member can download archives from this environment, false if they can't.
496
	 */
497
	public function canDownloadArchive($member = null) {
498
		if(!$member) {
499
			$member = Member::currentUser();
500
		}
501
		if(!$member) {
502
			return false;
503
		}
504
		// Must be logged in to check permissions
505
506
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
507
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
508
		} else {
509
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
510
		}
511
512
		return $this->ArchiveDownloaders()->byID($member->ID)
513
			|| $member->inGroups($this->ArchiveDownloaderGroups());
514
	}
515
516
	/**
517
	 * Determine if the specified user can abort any pipelines
@@ 566-583 (lines=18) @@
563
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
564
	 * @return boolean true if $member can delete archives from this environment, false if they can't.
565
	 */
566
	public function canDeleteArchive($member = null) {
567
		if(!$member) {
568
			$member = Member::currentUser();
569
		}
570
		if(!$member) {
571
			return false;
572
		}
573
		// Must be logged in to check permissions
574
575
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
576
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
577
		} else {
578
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
579
		}
580
581
		return $this->ArchiveDeleters()->byID($member->ID)
582
			|| $member->inGroups($this->ArchiveDeleterGroups());
583
	}
584
	/**
585
	 * Get a string of groups/people that are allowed to deploy to this environment.
586
	 * Used in DNRoot_project.ss to list {@link Member}s who have permission to perform this action.