Code Duplication    Length = 25-30 lines in 2 locations

apps/provisioning_api/lib/Controller/UsersController.php 2 locations

@@ 638-667 (lines=30) @@
635
	 * @return DataResponse
636
	 * @throws OCSException
637
	 */
638
	public function addSubAdmin($userId, $groupid) {
639
		$group = $this->groupManager->get($groupid);
640
		$user = $this->userManager->get($userId);
641
642
		// Check if the user exists
643
		if($user === null) {
644
			throw new OCSException('User does not exist', 101);
645
		}
646
		// Check if group exists
647
		if($group === null) {
648
			throw new OCSException('Group does not exist',  102);
649
		}
650
		// Check if trying to make subadmin of admin group
651
		if($group->getGID() === 'admin') {
652
			throw new OCSException('Cannot create subadmins for admin group', 103);
653
		}
654
655
		$subAdminManager = $this->groupManager->getSubAdmin();
656
657
		// We cannot be subadmin twice
658
		if ($subAdminManager->isSubAdminofGroup($user, $group)) {
659
			return new DataResponse();
660
		}
661
		// Go
662
		if($subAdminManager->createSubAdmin($user, $group)) {
663
			return new DataResponse();
664
		} else {
665
			throw new OCSException('Unknown error occurred', 103);
666
		}
667
	}
668
669
	/**
670
	 * Removes a subadmin from a group
@@ 679-703 (lines=25) @@
676
	 * @return DataResponse
677
	 * @throws OCSException
678
	 */
679
	public function removeSubAdmin($userId, $groupid) {
680
		$group = $this->groupManager->get($groupid);
681
		$user = $this->userManager->get($userId);
682
		$subAdminManager = $this->groupManager->getSubAdmin();
683
684
		// Check if the user exists
685
		if($user === null) {
686
			throw new OCSException('User does not exist', 101);
687
		}
688
		// Check if the group exists
689
		if($group === null) {
690
			throw new OCSException('Group does not exist', 101);
691
		}
692
		// Check if they are a subadmin of this said group
693
		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
694
			throw new OCSException('User is not a subadmin of this group', 102);
695
		}
696
697
		// Go
698
		if($subAdminManager->deleteSubAdmin($user, $group)) {
699
			return new DataResponse();
700
		} else {
701
			throw new OCSException('Unknown error occurred', 103);
702
		}
703
	}
704
705
	/**
706
	 * Get the groups a user is a subadmin of