From ce1ae69d402e70a970abeada4514107a478f2c03 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Mon, 10 Apr 2023 16:37:36 +0100 Subject: [PATCH] :sparkles: Feat(Snapshot) - Adds possibility to add source. Adds possibility to add source when creating a snapshot. --- contrib/openldap/core-fd.schema | 8 ++++- include/management/class_management.inc | 6 ++-- .../snapshot/class_SnapshotCreateDialog.inc | 31 ++++++++++++++++--- .../snapshot/class_SnapshotHandler.inc | 5 ++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema index cb5367d10..da9453bad 100644 --- a/contrib/openldap/core-fd.schema +++ b/contrib/openldap/core-fd.schema @@ -64,6 +64,12 @@ attributetype ( 1.3.6.1.4.1.38414.62.1.4 NAME 'fdSnapshotObjectType' SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE ) +attributetype ( 1.3.6.1.4.1.38414.62.1.51 NAME 'fdSnapshotDataSource' + DESC 'FusionDirectory - snapshot data origin / source' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE ) + ##### Subscriptions Attributes ###### attributetype ( 1.3.6.1.4.1.38414.62.11.1 NAME 'fdSubscriptionStartDate' @@ -394,7 +400,7 @@ objectclass ( 1.3.6.1.4.1.10098.1.2.1.19.18 NAME 'gosaAcl' objectclass ( 1.3.6.1.4.1.10098.1.2.1.19.19 NAME 'gosaSnapshotObject' DESC 'GOsa - Container object for undo and snapshot data' SUP top STRUCTURAL - MUST ( gosaSnapshotTimestamp $ gosaSnapshotDN $ gosaSnapshotData ) + MUST ( gosaSnapshotTimestamp $ gosaSnapshotDN $ gosaSnapshotData $ fdSnapshotDataSource ) MAY ( fdSnapshotObjectType $ description ) ) ### New FusionDirectory Objectclass ### diff --git a/include/management/class_management.inc b/include/management/class_management.inc index 51631eb49..27f806e8c 100644 --- a/include/management/class_management.inc +++ b/include/management/class_management.inc @@ -1318,17 +1318,19 @@ class management implements FusionDirectoryDialog /*! * \brief Creates a new snapshot entry + * If source arg is not set, default to 'FD'. */ - function createSnapshot (string $dn, string $description) + function createSnapshot (string $dn, string $description, string $snapshotSource = 'FD') { global $ui; + if (empty($dn) || ($this->currentDn !== $dn)) { trigger_error('There was a problem with the snapshot workflow'); return; } $entry = $this->listing->getEntry($dn); if ($entry->snapshotCreationAllowed()) { - $this->snapHandler->createSnapshot($dn, $description, $entry->type); + $this->snapHandler->createSnapshot($dn, $description, $entry->type, $snapshotSource); logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snapshot created!'); } else { $error = new FusionDirectoryPermissionError(htmlescape(sprintf(_('You are not allowed to restore a snapshot for %s.'), $dn))); diff --git a/include/management/snapshot/class_SnapshotCreateDialog.inc b/include/management/snapshot/class_SnapshotCreateDialog.inc index dd04a8511..9629eca40 100644 --- a/include/management/snapshot/class_SnapshotCreateDialog.inc +++ b/include/management/snapshot/class_SnapshotCreateDialog.inc @@ -59,12 +59,10 @@ class SnapshotCreateDialog extends ManagementDialog 'dataSource' => [ 'name' => _('dataSource'), 'attrs' => [ - new SetAttribute( new SelectAttribute( 'Data source', _('Origin / Source of the data'), - 'SnapshotSource', FALSE, + 'snapshotSource', FALSE, ), - ), ] ], ]; @@ -75,10 +73,29 @@ class SnapshotCreateDialog extends ManagementDialog parent::__construct(NULL, NULL, $parent); // The attribut will be passed to parent for later saving, dataSource might require same logic. $this->attributesAccess['description']->setInLdap(FALSE); + $this->attributesAccess['snapshotSource']->setInLdap(FALSE); + + $recordedDataSources = $this->getLdapRecordedDataSources(); + if (!empty($recordedDataSources)) { + $this->attributesAccess['snapshotSource']->setChoices($recordedDataSources); + } + $this->object_dn = $dn; $this->aclCategory = $aclCategory; } + /* + * Retrieve the data sources from configuration. + */ + public function getLdapRecordedDataSources () : array + { + global $config; + $recordedDataSources = $config->current['SNAPSHOTSOURCEDATA']; + + return $recordedDataSources; + } + + /*! * \brief Get LDAP base to use for ACL checks */ @@ -128,8 +145,12 @@ class SnapshotCreateDialog extends ManagementDialog function save (): array { - // We have to modify the createSnapshot to integrate the source Data - $this->parent->createSnapshot($this->object_dn, $this->description); + // snapshotSource is always set but can be empty and must be defaulted. + if (empty($this->snapshotSource)) { + $this->snapshotSource = 'FD'; + } + error_log($this->snapshotSource); + $this->parent->createSnapshot($this->object_dn, $this->description, $this->snapshotSource); return []; } diff --git a/include/management/snapshot/class_SnapshotHandler.inc b/include/management/snapshot/class_SnapshotHandler.inc index 34ad2e2fb..371671ca9 100644 --- a/include/management/snapshot/class_SnapshotHandler.inc +++ b/include/management/snapshot/class_SnapshotHandler.inc @@ -197,8 +197,10 @@ class SnapshotHandler * \param string $description Snapshot description * * \param string $objectType Type of snapshotted object + * + * \param string $snapshotSource source of the data. */ - function createSnapshot ($dn, string $description, string $objectType) + function createSnapshot ($dn, string $description, string $objectType, string $snapshotSource = 'FD') { global $config; if (!$this->enabled()) { @@ -251,6 +253,7 @@ class SnapshotHandler $target['gosaSnapshotDN'] = $dn; $target['description'] = $description; $target['fdSnapshotObjectType'] = $objectType; + $target['fdSnapshotDataSource'] = $snapshotSource; /* Insert the new snapshot But we have to check first, if the given gosaSnapshotTimestamp -- GitLab