Code Duplication    Length = 25-30 lines in 2 locations

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

@@ 706-735 (lines=30) @@
703
	 * @return DataResponse
704
	 * @throws OCSException
705
	 */
706
	public function addSubAdmin($userId, $groupid) {
707
		$group = $this->groupManager->get($groupid);
708
		$user = $this->userManager->get($userId);
709
710
		// Check if the user exists
711
		if($user === null) {
712
			throw new OCSException('User does not exist', 101);
713
		}
714
		// Check if group exists
715
		if($group === null) {
716
			throw new OCSException('Group does not exist',  102);
717
		}
718
		// Check if trying to make subadmin of admin group
719
		if($group->getGID() === 'admin') {
720
			throw new OCSException('Cannot create subadmins for admin group', 103);
721
		}
722
723
		$subAdminManager = $this->groupManager->getSubAdmin();
724
725
		// We cannot be subadmin twice
726
		if ($subAdminManager->isSubAdminofGroup($user, $group)) {
727
			return new DataResponse();
728
		}
729
		// Go
730
		if($subAdminManager->createSubAdmin($user, $group)) {
731
			return new DataResponse();
732
		} else {
733
			throw new OCSException('Unknown error occurred', 103);
734
		}
735
	}
736
737
	/**
738
	 * Removes a subadmin from a group
@@ 747-771 (lines=25) @@
744
	 * @return DataResponse
745
	 * @throws OCSException
746
	 */
747
	public function removeSubAdmin($userId, $groupid) {
748
		$group = $this->groupManager->get($groupid);
749
		$user = $this->userManager->get($userId);
750
		$subAdminManager = $this->groupManager->getSubAdmin();
751
752
		// Check if the user exists
753
		if($user === null) {
754
			throw new OCSException('User does not exist', 101);
755
		}
756
		// Check if the group exists
757
		if($group === null) {
758
			throw new OCSException('Group does not exist', 101);
759
		}
760
		// Check if they are a subadmin of this said group
761
		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
762
			throw new OCSException('User is not a subadmin of this group', 102);
763
		}
764
765
		// Go
766
		if($subAdminManager->deleteSubAdmin($user, $group)) {
767
			return new DataResponse();
768
		} else {
769
			throw new OCSException('Unknown error occurred', 103);
770
		}
771
	}
772
773
	/**
774
	 * Get the groups a user is a subadmin of