Commit f62897d4 authored by Prosper De Laure's avatar Prosper De Laure
Browse files

Accept any profile option

parent e97e11c2
ALTER TABLE "recordsManagement"."archivalProfile" ADD COLUMN "acceptArchiveWithoutProfile" boolean default true;
ALTER TABLE "recordsManagement"."archivalProfile" ADD COLUMN "acceptAnyProfile" boolean default false;
CREATE TABLE "recordsManagement"."archivalProfileRelationship"
(
......
......@@ -287,7 +287,7 @@ class archivalProfile
$this->createDetail($archivalProfile);
// Contents profiles
$this->updateContainedProfiles($archivalProfile->archivalProfileId, $archivalProfile->containedProfiles);
$this->updateContainedProfiles($archivalProfile, $archivalProfile->containedProfiles);
// Life cycle journal
$eventItems = array('archivalProfileReference' => $archivalProfile->reference);
......@@ -331,7 +331,7 @@ class archivalProfile
// archival profile
$this->sdoFactory->update($archivalProfile, "recordsManagement/archivalProfile");
// Contents profiles
$this->updateContainedProfiles($archivalProfile->archivalProfileId, $archivalProfile->containedProfiles);
$this->updateContainedProfiles($archivalProfile, $archivalProfile->containedProfiles);
// Life cycle journal
$eventItems = array('archivalProfileReference' => $archivalProfile->reference);
......@@ -354,14 +354,23 @@ class archivalProfile
/**
* Cpdate an archival content profile
* @param string $archivalProfileId The parent profile identifier
* @param object $archivalProfile The parent profile
* @param array $containedProfiles The content profiles identifiers
*
* @return boolean The request of the request
*/
protected function updateContainedProfiles($parentProfileId, $containedProfiles)
protected function updateContainedProfiles($archivalProfile, $containedProfiles)
{
if ($archivalProfile->acceptAnyProfile) {
$containedProfiles = null;
}
if (!count($containedProfiles)) {
$oldcontainedProfiles = $this->sdoFactory->find("recordsManagement/archivalProfileRelationship", "parentProfileId = '$archivalProfile->archivalProfileId'");
if (count($oldcontainedProfiles)) {
$this->sdoFactory->deleteCollection($oldcontainedProfiles, "recordsManagement/archivalProfileRelationship");
}
return;
}
......@@ -374,21 +383,16 @@ class archivalProfile
throw new \core\Exception\NotFoundException("$profileId can't be found.");
}
if (!$this->validateContainedProfile($parentProfileId, $profileId)) {
if (!$this->validateContainedProfile($archivalProfile->archivalProfileId, $profileId)) {
throw new \core\Exception\ForbiddenException("$profile->reference can't be content in this archival profile.");
}
}
$oldcontainedProfiles = $this->sdoFactory->find("recordsManagement/archivalProfileRelationship", "parentProfileId = '$parentProfileId'");
if (count($oldcontainedProfiles)) {
$this->sdoFactory->deleteCollection($oldcontainedProfiles, "recordsManagement/archivalProfileRelationship");
}
$archivalProfileRelationships = [];
foreach ($containedProfiles as $containedProfileId) {
$archivalProfileRelationship = \laabs::newInstance('recordsManagement/archivalProfileRelationship');
$archivalProfileRelationship->parentProfileId = $parentProfileId;
$archivalProfileRelationship->parentProfileId = $archivalProfile->archivalProfileId;
$archivalProfileRelationship->containedProfileId = $containedProfileId;
$archivalProfileRelationships[] = $archivalProfileRelationship;
......@@ -435,7 +439,6 @@ class archivalProfile
{
$archivalProfile = $this->sdoFactory->read('recordsManagement/archivalProfile', $archivalProfileId);
// containedProfiles
$archivalProfileRelationships = $this->sdoFactory->find("recordsManagement/archivalProfileRelationship", "parentProfileId='$archivalProfileId' or containedProfileId='$archivalProfileId'");
if (count($archivalProfileRelationships)) {
......
......@@ -638,8 +638,9 @@ trait archiveEntryTrait
}
for ($i = 0; $i < $nbArchiveObjects; $i++) {
if (($archive->contents[$i]->archivalProfileReference == "" && !$this->currentArchivalProfile->acceptArchiveWithoutProfile) || !in_array($archive->contents[$i]->archivalProfileReference, $containedProfiles)) {
if (($archive->contents[$i]->archivalProfileReference == "" && !$this->currentArchivalProfile->acceptArchiveWithoutProfile) || (!$this->currentArchivalProfile->acceptAnyProfile && !in_array($archive->contents[$i]->archivalProfileReference, $containedProfiles))) {
throw new \core\Exception\ForbiddenException("Invalid contained archive profile");
}
}
$this->validateManagementMetadata($archive->contents[$i]);
......@@ -665,6 +666,10 @@ trait archiveEntryTrait
return;
}
if ($archive->archivalProfileReference != "" && $this->currentArchivalProfile->acceptAnyProfile) {
return;
}
foreach ($this->currentArchivalProfile->containedProfiles as $profile) {
if ($profile->reference == $archive->archivalProfileReference) {
return;
......
......@@ -105,6 +105,13 @@ class archivalProfile
*/
public $acceptArchiveWithoutProfile;
/**
* The archive accepts sub archive of any profile
*
* @var boolean
*/
public $acceptAnyProfile;
/**
* The list of profile description
*
......
......@@ -107,6 +107,13 @@ class archivalProfile
*/
public $acceptArchiveWithoutProfile;
/**
* The archive accepts sub archive of any profile
*
* @var boolean
*/
public $acceptAnyProfile;
/**
* The list of profile description
*
......
......@@ -59,6 +59,7 @@ CREATE TABLE "recordsManagement"."archivalProfile"
"acceptMultipleDocuments" boolean default false,
"acceptMultipleDocuments" boolean default false,
"acceptArchiveWithoutProfile" boolean default true,
"acceptAnyProfile" boolean default false,
PRIMARY KEY ("archivalProfileId"),
UNIQUE ("reference"),
FOREIGN KEY ("accessRuleCode")
......
......@@ -163,13 +163,25 @@ class welcome
$archive->originatorOrgName = $originatorOrg->displayName;
$archive->depositDate = $archive->depositDate->format('Y-m-d H:i:s');
if (!empty($archive->archivalProfileReference)) {
$archivalProfile = \laabs::callService('recordsManagement/archivalProfile/readByreference_reference_', $archive->archivalProfileReference);
$archive->archivalProfileName = $archivalProfile->name;
}
$depositPrivilege = \laabs::callService('auth/userAccount/readHasprivilege', "archiveDeposit/deposit");
if (count($archivalProfile->containedProfiles) && $archivalProfile->acceptArchiveWithoutProfile == false) {
$depositPrivilege = false;
}
$this->view->translate();
$this->view->setSource('containedProfiles', $archivalProfiles->containedProfiles);
$this->view->setSource("status", $archive->status);
$archive->status = $this->view->translator->getText($archive->status, false, "recordsManagement/messages");
$archive->finalDisposition = $this->view->translator->getText($archive->finalDisposition, false, "recordsManagement/messages");
$depositPrivilege = \laabs::callService('auth/userAccount/readHasprivilege', "archiveDeposit/deposit");
$this->getDescription($archive);
$this->view->setSource('retentionRules', $retentionRules);
......@@ -293,6 +305,7 @@ class welcome
if (!empty($archive->descriptionClass)) {
$presenter = \laabs::newPresenter($archive->descriptionClass);
$descriptionHtml = $presenter->read($archive->descriptionObject);
} else {
$descriptionHtml = '<table">';
......
......@@ -238,3 +238,6 @@ msgstr "Voulez vous enregistrer les modifications avant de quitter cet écran ?"
msgid "Go to"
msgstr "Aller vers"
msgid "Accept any profiles"
msgstr "Accepter tout les profiles"
......@@ -2,26 +2,34 @@
<br/>
<form class="form-horizontal">
<div class="form-group">
<label class="col-md-4 control-label">Accept archives without profile</label>
<div class="col-md-8">
<label class="col-md-6 control-label">Accept archives without profile</label>
<div class="col-md-6">
<input type="checkbox" id="acceptArchiveWithoutProfile" name="acceptArchiveWithoutProfile" data-toggle="toggle">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Accept the profile :</label>
<div class="col-md-8">
<div class="input-group">
<select id="profileList" name="profileList" class="form-control" data-profile-list="[?merge profileList ?]" data-contained-profiles="[?merge archivalProfile.containedProfiles ?]">
<option value="" data-properties="" data-dateproperties="[?merge dateFields ?]">Select a profile</option>
</select>
<span class="input-group-btn">
<button type="button" id="addProfile" class="btn btn-success"><span class="fa fa-plus"></span></button>
</span>
</div>
</div>
<label class="col-md-6 control-label">Accept any profiles</label>
<div class="col-md-6">
<input type="checkbox" id="acceptAnyProfile" name="acceptAnyProfile" data-toggle="toggle">
</div>
</div>
<div class="col-xs-12">
<ul id="containedProfileList" class="list-group"/>
<div id="subProfile" class="[?merge archivalProfile.acceptAnyProfile.bool().then('hide', '') ?]">
<div class="form-group">
<label class="col-md-4 control-label">Accept the profile :</label>
<div class="col-md-8">
<div class="input-group">
<select id="profileList" name="profileList" class="form-control" data-profile-list="[?merge profileList ?]" data-contained-profiles="[?merge archivalProfile.containedProfiles ?]">
<option value="" data-properties="" data-dateproperties="[?merge dateFields ?]">Select a profile</option>
</select>
<span class="input-group-btn">
<button type="button" id="addProfile" class="btn btn-success"><span class="fa fa-plus"></span></button>
</span>
</div>
</div>
</div>
<div class="col-xs-12">
<ul id="containedProfileList" class="list-group"/>
</div>
</div>
</form>
</div>
......@@ -86,6 +94,19 @@
this.select.find('option[value="'+profileId+'"]').removeClass('hide');
},
allowAnyProfile: function() {
this.list.find('li').each(function() {
ArchiveStructure.removeProfile($(this));
});
$('#subProfile').addClass('hide');
},
limitSubProfile: function() {
$('#subProfile').removeClass('hide');
},
serialize: function() {
var containedProfiles = []
......@@ -140,8 +161,6 @@
$('#containedProfileList').on('click', '.showProfile', function() {
var href = this.href;
console.log($('#contain').data('not-saved'));
if ($('#contain').data('not-saved') == false) {
location.href = href;
return;
......@@ -150,17 +169,24 @@
$('#saveProfileModal').modal();
$('#saveBeforeChange').one('click', function() {
$('#saveProfileModal').on('hide.bs.modal', function(){
$('#saveProfileModal').on('hide.bs.modal', function() {
ArchivalProfile.save(href);
})
});
$('#noSaveBeforeChange').one('click', function(){
$('#noSaveBeforeChange').one('click', function() {
location.href = href;
});
return false;
});
$('#acceptAnyProfile').on('change', function() {
if ($(this).is(':checked')) {
ArchiveStructure.allowAnyProfile();
} else {
ArchiveStructure.limitSubProfile();
}
})
</script>
......@@ -256,7 +256,8 @@ file that was distributed with this source code.
retentionRuleCode: $('#code').val(),
acceptUserIndex: $('#allowUserIndexes').prop("checked"),
archiveDescription: [],
acceptArchiveWithoutProfile: $('#acceptArchiveWithoutProfile').prop("checked")
acceptArchiveWithoutProfile: $('#acceptArchiveWithoutProfile').prop("checked"),
acceptAnyProfile: $('#acceptAnyProfile').prop("checked")
}
if(serializedObject.retentionStartDate ==''){
......@@ -288,7 +289,6 @@ file that was distributed with this source code.
ArchivalProfile.loadAccessCode();
$('input, select, textarea').on('change', function() {
console.log('ok');
$('#contain').data('not-saved', true);
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment