Code Duplication    Length = 25-30 lines in 2 locations

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

@@ 755-784 (lines=30) @@
752
	 * @return DataResponse
753
	 * @throws OCSException
754
	 */
755
	public function addSubAdmin(string $userId, string $groupid): DataResponse {
756
		$group = $this->groupManager->get($groupid);
757
		$user = $this->userManager->get($userId);
758
759
		// Check if the user exists
760
		if($user === null) {
761
			throw new OCSException('User does not exist', 101);
762
		}
763
		// Check if group exists
764
		if($group === null) {
765
			throw new OCSException('Group does not exist',  102);
766
		}
767
		// Check if trying to make subadmin of admin group
768
		if($group->getGID() === 'admin') {
769
			throw new OCSException('Cannot create subadmins for admin group', 103);
770
		}
771
772
		$subAdminManager = $this->groupManager->getSubAdmin();
773
774
		// We cannot be subadmin twice
775
		if ($subAdminManager->isSubAdminofGroup($user, $group)) {
776
			return new DataResponse();
777
		}
778
		// Go
779
		if($subAdminManager->createSubAdmin($user, $group)) {
780
			return new DataResponse();
781
		} else {
782
			throw new OCSException('Unknown error occurred', 103);
783
		}
784
	}
785
786
	/**
787
	 * Removes a subadmin from a group
@@ 796-820 (lines=25) @@
793
	 * @return DataResponse
794
	 * @throws OCSException
795
	 */
796
	public function removeSubAdmin(string $userId, string $groupid): DataResponse {
797
		$group = $this->groupManager->get($groupid);
798
		$user = $this->userManager->get($userId);
799
		$subAdminManager = $this->groupManager->getSubAdmin();
800
801
		// Check if the user exists
802
		if($user === null) {
803
			throw new OCSException('User does not exist', 101);
804
		}
805
		// Check if the group exists
806
		if($group === null) {
807
			throw new OCSException('Group does not exist', 101);
808
		}
809
		// Check if they are a subadmin of this said group
810
		if(!$subAdminManager->isSubAdminOfGroup($user, $group)) {
811
			throw new OCSException('User is not a subadmin of this group', 102);
812
		}
813
814
		// Go
815
		if($subAdminManager->deleteSubAdmin($user, $group)) {
816
			return new DataResponse();
817
		} else {
818
			throw new OCSException('Unknown error occurred', 103);
819
		}
820
	}
821
822
	/**
823
	 * Get the groups a user is a subadmin of