store self service profiles as JSON
This commit is contained in:
		
							parent
							
								
									aa43b4721b
								
							
						
					
					
						commit
						f091b653b8
					
				|  | @ -6,6 +6,7 @@ use LAM\PDF\PDFStructureWriter; | ||||||
| use LAMCfgMain; | use LAMCfgMain; | ||||||
| use LAMConfig; | use LAMConfig; | ||||||
| use LAMException; | use LAMException; | ||||||
|  | use selfServiceProfile; | ||||||
| use function LAM\PDF\getAvailableLogos; | use function LAM\PDF\getAvailableLogos; | ||||||
| use function LAM\PDF\getPDFStructures; | use function LAM\PDF\getPDFStructures; | ||||||
| use function LAM\PDF\getPdfTemplateLogoBinary; | use function LAM\PDF\getPdfTemplateLogoBinary; | ||||||
|  | @ -74,10 +75,10 @@ class ConfigDataExporter { | ||||||
| 		$jsonData['accountProfileTemplates'] = $this->_getAccountProfileTemplates(); | 		$jsonData['accountProfileTemplates'] = $this->_getAccountProfileTemplates(); | ||||||
| 		$jsonData['pdfProfiles'] = $this->_getPdfProfiles($serverProfiles); | 		$jsonData['pdfProfiles'] = $this->_getPdfProfiles($serverProfiles); | ||||||
| 		$jsonData['pdfProfileTemplates'] = $this->_getPdfProfileTemplates(); | 		$jsonData['pdfProfileTemplates'] = $this->_getPdfProfileTemplates(); | ||||||
|  | 		$jsonData['selfServiceProfiles'] = $this->_getSelfServiceProfiles(); | ||||||
| 		/** | 		/** | ||||||
| 		 * TODO | 		 * TODO | ||||||
| 		 * | 		 * | ||||||
| 		 * self service profiles |  | ||||||
| 		 * webauthn | 		 * webauthn | ||||||
| 		 * cron job runs | 		 * cron job runs | ||||||
| 		 */ | 		 */ | ||||||
|  | @ -218,6 +219,26 @@ class ConfigDataExporter { | ||||||
| 		return $data; | 		return $data; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Returns the content of the self service profiles. | ||||||
|  | 	 * | ||||||
|  | 	 * @return array data | ||||||
|  | 	 */ | ||||||
|  | 	public function _getSelfServiceProfiles() { | ||||||
|  | 		$data = array(); | ||||||
|  | 		$profileTypes = getSelfServiceProfiles(); | ||||||
|  | 		foreach ($profileTypes as $profileType => $profileNames) { | ||||||
|  | 			foreach ($profileNames as $profileName) { | ||||||
|  | 				$profile = loadSelfServiceProfile($profileName, $profileType); | ||||||
|  | 				if ($profile === false) { | ||||||
|  | 					continue; | ||||||
|  | 				} | ||||||
|  | 				$data[$profileType][$profileName] = $profile->export(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return $data; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -273,6 +294,9 @@ class ConfigDataImporter { | ||||||
| 				case 'pdfProfileTemplates': | 				case 'pdfProfileTemplates': | ||||||
| 					$steps[] = new ImporterStep(_('PDF structures') . ' - ' . _('Global templates'), 'pdfProfileTemplates', $value); | 					$steps[] = new ImporterStep(_('PDF structures') . ' - ' . _('Global templates'), 'pdfProfileTemplates', $value); | ||||||
| 					break; | 					break; | ||||||
|  | 				case 'selfServiceProfiles': | ||||||
|  | 					$steps[] = new ImporterStep(_('Self service profiles'), 'selfServiceProfiles', $value); | ||||||
|  | 					break; | ||||||
| 				default: | 				default: | ||||||
| 					logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); | 					logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); | ||||||
| 			} | 			} | ||||||
|  | @ -317,6 +341,9 @@ class ConfigDataImporter { | ||||||
| 				case 'pdfProfileTemplates': | 				case 'pdfProfileTemplates': | ||||||
| 					$this->importPdfProfileTemplates($step); | 					$this->importPdfProfileTemplates($step); | ||||||
| 					break; | 					break; | ||||||
|  | 				case 'selfServiceProfiles': | ||||||
|  | 					$this->importSelfServiceProfiles($step); | ||||||
|  | 					break; | ||||||
| 				default: | 				default: | ||||||
| 					logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); | 					logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); | ||||||
| 			} | 			} | ||||||
|  | @ -511,6 +538,29 @@ class ConfigDataImporter { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	/** | ||||||
|  | 	 * Imports the self service profiles. | ||||||
|  | 	 * | ||||||
|  | 	 * @param ImporterStep $step importer step | ||||||
|  | 	 * @throws LAMException error saving profiles | ||||||
|  | 	 */ | ||||||
|  | 	private function importSelfServiceProfiles($step) { | ||||||
|  | 		$failedNames = array(); | ||||||
|  | 		$data = $step->getValue(); | ||||||
|  | 		foreach ($data as $typeId => $profileData) { | ||||||
|  | 			foreach ($profileData as $profileName => $currentProfileData) { | ||||||
|  | 				$profile = selfServiceProfile::import($currentProfileData); | ||||||
|  | 				$result = saveSelfServiceProfile($profileName, $typeId, $profile); | ||||||
|  | 				if (!$result) { | ||||||
|  | 					$failedNames[] = $profileName; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		if (!empty($failedNames)) { | ||||||
|  | 			throw new LAMException(_('Unable to save profile!'), implode(', ', $failedNames)); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  |  | ||||||
|  | @ -170,7 +170,7 @@ function checkSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOn | ||||||
| /** | /** | ||||||
| * Returns a list of all available self service profiles (without .conf) | * Returns a list of all available self service profiles (without .conf) | ||||||
| * | * | ||||||
| * @return array profile names (array(<account type> => array(<profile1>, <profile2>, ...))) | * @return array profile names (array('account type' => array('profile1', 'profile2'))) | ||||||
| */ | */ | ||||||
| function getSelfServiceProfiles() { | function getSelfServiceProfiles() { | ||||||
| 	$types = LAM\TYPES\getTypes(); | 	$types = LAM\TYPES\getTypes(); | ||||||
|  | @ -201,7 +201,7 @@ function getSelfServiceProfiles() { | ||||||
| * | * | ||||||
| * @param string $name profile name | * @param string $name profile name | ||||||
| * @param string $scope account type | * @param string $scope account type | ||||||
| * @return selfServiceProfile true if file was readable | * @return false|selfServiceProfile profile or false if file was not readable | ||||||
| */ | */ | ||||||
| function loadSelfServiceProfile($name, $scope) { | function loadSelfServiceProfile($name, $scope) { | ||||||
| 	if (!preg_match("/^[0-9a-z _-]+$/i", $name) || !preg_match("/^[0-9a-z _-]+$/i", $scope)) { | 	if (!preg_match("/^[0-9a-z _-]+$/i", $name) || !preg_match("/^[0-9a-z _-]+$/i", $scope)) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue