Commit 219d3975 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '5877-altered-and-provided-attributes-should-be-editable' into '1.4-dev'

Resolve "Altered and provided attributes should be editable"

See merge request fusiondirectory/fd-plugins!363
parents 420b5020 88ce7061
......@@ -26,23 +26,8 @@ class privateFormPage extends publicFormPage
function __construct($interactive = TRUE)
{
parent::__construct($interactive);
/* TODO POC alteredAttributes/providedAttributes/providedMultiValueAttributes */
$this->providedAttributes = array(
array('user','givenName'),
array('user','sn'),
array('mailAccount','mail'),
array('supannAccount','eduPersonAffiliation'),
array('supannAccount','eduPersonPrimaryAffiliation'),
array('supannAccount','supannListeRouge'),
array('supannAccount','supannEtuCursusAnnee'),
);
/* TODO POC providedMultiValueAttributes */
$this->providedMultiValueAttributes = array('eduPersonAffiliation');
/* Set readonly attributes in form (prefill from IDP) */
$this->alteredAttributes[1] = array(
'user' => array('givenName', 'sn'),
'supannAccount' => array('eduPersonAffiliation', 'eduPersonPrimaryAffiliation', 'supannRefId'),
'mailAccount' => array('mail'),
);
}
protected function getPrefilledValues($values = array())
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class publicFormAlteration extends simplePlugin
{
public static function plInfo()
{
return array(
'plShortName' => _('Altered fields'),
'plDescription' => _('Alteration on form fields'),
'plIcon' => '',
'plObjectClass' => array(),
'plObjectType' => array('publicForm'),
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
);
}
static function getAttributesInfo ()
{
global $config;
return array(
'main' => array(
'name' => _('Altered fields'),
'class' => array('fullwidth'),
'attrs' => array(
new OrderedArrayAttribute(
new PipeSeparatedCompositeAttribute(
_('Alteration on form fields'),
'fdPublicFormAlteredAttributes',
array(
new StringAttribute(
_('Field'), _('LDAP name of a form field'),
'fdPublicFormAlteredAttributes_field', TRUE
),
new BooleanAttribute(
_('Mandatory'), _('Should this field be mandatory'),
'fdPublicFormAlteredAttributes_mandatory', TRUE,
FALSE, '',
'mandatory', ''
),
new BooleanAttribute(
_('Read only'), _('Should this field be read only'),
'fdPublicFormAlteredAttributes_readonly', TRUE,
FALSE, '',
'readonly', ''
),
new BooleanAttribute(
_('Imported'), _('Should this field be imported from HTTP headers'),
'fdPublicFormAlteredAttributes_imported', TRUE,
FALSE, '',
'imported', ''
),
new BooleanAttribute(
_('Hidden'), _('Should this field be hidden away'),
'fdPublicFormAlteredAttributes_hidden', TRUE,
FALSE, '',
'hidden', ''
),
),
'',
''
),
// no order
FALSE,
// default value
array('base||||hidden'),
// edit enabled
TRUE
),
)
),
);
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
$this->attributesAccess['fdPublicFormAlteredAttributes']->setHeaders(
array(
_('Field'),
_('Mandatory'),
_('Read only'),
_('Imported'),
_('Hidden'),
)
);
}
}
?>
......@@ -54,6 +54,12 @@ attributetype ( 1.3.6.1.4.1.38414.67.10.7 NAME 'fdPublicFormCreationBase'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.67.10.8 NAME 'fdPublicFormAlteredAttributes'
DESC 'FusionDirectory - Form altered attributes: name|mandatory|readonly|imported|hidden'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
# Objectclasses
objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
......@@ -62,4 +68,5 @@ objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
MAY (
fdPublicFormTitle $ fdPublicFormText $
fdPublicFormTemplateType $ fdPublicFormTemplateDN $
fdPublicFormFinalText $ fdPublicFormPrivate $ fdPublicFormCreationBase ) )
fdPublicFormFinalText $ fdPublicFormPrivate $ fdPublicFormCreationBase $
fdPublicFormAlteredAttributes ) )
......@@ -37,21 +37,6 @@ class publicFormPage extends standAlonePage
{
parent::__construct($interactive);
$this->request = $_SERVER['REQUEST_URI'];
$this->alteredAttributes = array(
/* mandatory */
array(
'user' => array('givenName', 'sn'),
'mailAccount' => array('mail'),
),
/* readonly */
array(
),
/* hidden */
array(
'user' => array('base'),
'supannAccount' => array('supannRefId'),
),
);
}
function reset()
......@@ -122,15 +107,16 @@ class publicFormPage extends standAlonePage
$forms = objects::ls(
'publicForm',
array(
'dn' => 'raw',
'cn' => 1,
'fdPublicFormTitle' => 1,
'fdPublicFormText' => 1,
'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1
'dn' => 'raw',
'cn' => 1,
'fdPublicFormTitle' => 1,
'fdPublicFormText' => 1,
'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormAlteredAttributes' => '*',
),
$this->invitation['fdInvitationFormDN'],
'', FALSE, 'base'
......@@ -141,15 +127,16 @@ class publicFormPage extends standAlonePage
$forms = objects::ls(
'publicForm',
array(
'dn' => 'raw',
'cn' => 1,
'fdPublicFormTitle' => 1,
'fdPublicFormText' => 1,
'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1
'dn' => 'raw',
'cn' => 1,
'fdPublicFormTitle' => 1,
'fdPublicFormText' => 1,
'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1,
'fdPublicFormAlteredAttributes' => '*',
),
NULL,
'(cn='.ldap_escape_f($_GET['form']).')'
......@@ -208,20 +195,36 @@ class publicFormPage extends standAlonePage
return;
}
$this->template = new template($this->form['fdPublicFormTemplateType'], $this->form['fdPublicFormTemplateDN']);
$values = $this->getPrefilledValues();
/* Check that mandatory readonly attributes are prefilled */
foreach ($this->alteredAttributes[1] as $tab => $attributes) {
foreach ($attributes as $key => $attribute) {
if (!isset($values[$tab][$attribute]) &&
(
(isset($this->alteredAttributes[0][$tab]) && in_array($attribute, $this->alteredAttributes[0][$tab])) ||
$this->template->getAttribute($tab, $attribute)->isRequired()
)
) {
unset($this->alteredAttributes[1][$tab][$key]);
$this->alteredAttributes = array(array(),array(),array());
$this->providedAttributes = array();
foreach ($this->form['fdPublicFormAlteredAttributes'] as $alteredAttribute) {
list($attribute, $mandatory, $readonly, $imported, $hidden) = explode('|', $alteredAttribute, 5);
$tab = $this->template->getAttributeTab($attribute);
if ($mandatory) {
$this->alteredAttributes[0][$tab][] = $attribute;
}
if ($this->prefill) {
if ($readonly) {
/* Check that mandatory readonly attributes are prefilled */
if (
isset($values[$tab][$attribute]) ||
(!$mandatory && !$this->template->getAttribute($tab, $attribute)->isRequired())
) {
$this->alteredAttributes[1][$tab][] = $attribute;
}
}
if ($imported) {
$this->providedAttributes[] = array($tab, $attribute);
}
}
if ($hidden) {
$this->alteredAttributes[2][$tab][] = $attribute;
}
}
$this->template->alterAttributes(...$this->alteredAttributes);
$this->template->setValues($values, TRUE);
}
......
Markdown is supported
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