Code Duplication    Length = 25-30 lines in 2 locations

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

@@ 791-820 (lines=30) @@
788
	 * @return DataResponse
789
	 * @throws OCSException
790
	 */
791
	public function addSubAdmin(string $userId, string $groupid): DataResponse {
792
		$group = $this->groupManager->get($groupid);
793
		$user = $this->userManager->get($userId);
794
795
		// Check if the user exists
796
		if($user === null) {
797
			throw new OCSException('User does not exist', 101);
798
		}
799
		// Check if group exists
800
		if($group === null) {
801
			throw new OCSException('Group does not exist',  102);
802
		}
803
		// Check if trying to make subadmin of admin group
804
		if($group->getGID() === 'admin') {
805
			throw new OCSException('Cannot create subadmins for admin group', 103);
806
		}
807
808
		$subAdminManager = $this->groupManager->getSubAdmin();
809
810
		// We cannot be subadmin twice
811
		if ($subAdminManager->isSubAdminofGroup($user, $group)) {
812
			return new DataResponse();
813
		}
814
		// Go
815
		if($subAdminManager->createSubAdmin($user, $group)) {
816
			return new DataResponse();
817
		} else {
818
			throw new OCSException('Unknown error occurred', 103);
819
		}
820
	}
821
822
	/**
823
	 * Removes a subadmin from a group
@@ 832-856 (lines=25) @@
829
	 * @return DataResponse
830
	 * @throws OCSException
831
	 */
832
	public function removeSubAdmin(string $userId, string $groupid): DataResponse {
833
		$group = $this->groupManager->get($groupid);
834
		$user = $this->userManager->get($userId);
835
		$subAdminManager = $this->groupManager->getSubAdmin();
836
837
		// Check if the user exists
838
		if($user === null) {
839
			throw new OCSException('User does not exist', 101);
840
		}
841
		// Check if the group exists
842
		if($group === null) {
843
			throw new OCSException('Group does not exist', 101);
844
		}
845
		// Check if they are a subadmin of this said group
846
		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
847
			throw new OCSException('User is not a subadmin of this group', 102);
848
		}
849
850
		// Go
851
		if($subAdminManager->deleteSubAdmin($user, $group)) {
852
			return new DataResponse();
853
		} else {
854
			throw new OCSException('Unknown error occurred', 103);
855
		}
856
	}
857
858
	/**
859
	 * Get the groups a user is a subadmin of