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
	 * Provide reason why the user cannot deploy.
@@ 414-431 (lines=18) @@
411
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
412
	 * @return boolean true if $member can restore, and false if they can't.
413
	 */
414
	public function canRestore($member = null) {
415
		if(!$member) {
416
			$member = Member::currentUser();
417
		}
418
		if(!$member) {
419
			return false;
420
		}
421
		// Must be logged in to check permissions
422
423
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
424
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
425
		} else {
426
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
427
		}
428
429
		return $this->CanRestoreMembers()->byID($member->ID)
430
			|| $member->inGroups($this->CanRestoreGroups());
431
	}
432
433
	/**
434
	 * Allows only selected {@link Member} objects to backup this {@link DNEnvironment} to a {@link DNDataArchive}
@@ 506-523 (lines=18) @@
503
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
504
	 * @return boolean true if $member can download archives from this environment, false if they can't.
505
	 */
506
	public function canDownloadArchive($member = null) {
507
		if(!$member) {
508
			$member = Member::currentUser();
509
		}
510
		if(!$member) {
511
			return false;
512
		}
513
		// Must be logged in to check permissions
514
515
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
516
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
517
		} else {
518
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
519
		}
520
521
		return $this->ArchiveDownloaders()->byID($member->ID)
522
			|| $member->inGroups($this->ArchiveDownloaderGroups());
523
	}
524
525
	/**
526
	 * Determine if the specified user can abort any pipelines
@@ 575-592 (lines=18) @@
572
	 * @param Member|null $member The {@link Member} object to test against. If null, uses Member::currentMember();
573
	 * @return boolean true if $member can delete archives from this environment, false if they can't.
574
	 */
575
	public function canDeleteArchive($member = null) {
576
		if(!$member) {
577
			$member = Member::currentUser();
578
		}
579
		if(!$member) {
580
			return false;
581
		}
582
		// Must be logged in to check permissions
583
584
		if ($this->Usage==='Production' || $this->Usage==='Unspecified') {
585
			if ($this->Project()->allowed(DNRoot::ALLOW_PROD_SNAPSHOT, $member)) return true;
586
		} else {
587
			if ($this->Project()->allowed(DNRoot::ALLOW_NON_PROD_SNAPSHOT, $member)) return true;
588
		}
589
590
		return $this->ArchiveDeleters()->byID($member->ID)
591
			|| $member->inGroups($this->ArchiveDeleterGroups());
592
	}
593
	/**
594
	 * Get a string of groups/people that are allowed to deploy to this environment.
595
	 * Used in DNRoot_project.ss to list {@link Member}s who have permission to perform this action.