Code Duplication    Length = 25-30 lines in 2 locations

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

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