new type API

This commit is contained in:
Roland Gruber 2017-05-03 20:37:04 +02:00
parent 056cbce9c3
commit 9c9d8b3f09
1 changed files with 74 additions and 70 deletions

View File

@ -1,9 +1,10 @@
<?php <?php
use \LAM\TYPES\TypeManager;
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2015 Roland Gruber Copyright (C) 2013 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -101,12 +102,6 @@ class pykotaGroup extends baseModule {
$return['objectClasses'] = array('pykotaGroup'); $return['objectClasses'] = array('pykotaGroup');
// managed attributes // managed attributes
$return['attributes'] = array('pykotaLimitBy', 'pykotaGroupName'); $return['attributes'] = array('pykotaLimitBy', 'pykotaGroupName');
if ($this->manageCn()) {
$return['attributes'][] = 'cn';
}
if ($this->manageDescription()) {
$return['attributes'][] = 'description';
}
// help Entries // help Entries
$return['help'] = array( $return['help'] = array(
'cn' => array( 'cn' => array(
@ -151,23 +146,6 @@ class pykotaGroup extends baseModule {
'unique' => true, 'unique' => true,
) )
); );
if ($this->manageCn()) {
$return['upload_columns'][] = array(
'name' => 'pykotaGroup_cn',
'description' => _('Common name'),
'help' => 'cn',
'example' => _('adminstrators'),
'required' => true,
);
}
if ($this->manageDescription()) {
$return['upload_columns'][] = array(
'name' => 'pykotaGroup_description',
'description' => _('Description'),
'help' => 'description',
'example' => _('Administrators group'),
);
}
$return['upload_columns'][] = array( $return['upload_columns'][] = array(
'name' => 'pykotaGroup_pykotaLimitBy', 'name' => 'pykotaGroup_pykotaLimitBy',
'description' => _('Limit type'), 'description' => _('Limit type'),
@ -181,12 +159,6 @@ class pykotaGroup extends baseModule {
'pykotaGroupName' => _('PyKota group name'), 'pykotaGroupName' => _('PyKota group name'),
'pykotaLimitBy' => _('Limit type'), 'pykotaLimitBy' => _('Limit type'),
); );
if ($this->manageCn()) {
$return['PDF_fields']['cn'] = _('Common name');
}
if ($this->manageDescription()) {
$return['PDF_fields']['description'] = _('Description');
}
return $return; return $return;
} }
@ -212,9 +184,10 @@ class pykotaGroup extends baseModule {
*/ */
function display_html_attributes() { function display_html_attributes() {
$container = new htmlTable(); $container = new htmlTable();
$modules = $this->getAccountContainer()->get_type()->getModules();
if ($this->isStructural() || (isset($this->attributes['objectClass']) && in_array('pykotaGroup', $this->attributes['objectClass']))) { if ($this->isStructural() || (isset($this->attributes['objectClass']) && in_array('pykotaGroup', $this->attributes['objectClass']))) {
// cn // cn
if ($this->manageCn()) { if ($this->isUnixOrGonInactive($modules)) {
$this->addSimpleInputTextField($container, 'cn', _('Group name'), true); $this->addSimpleInputTextField($container, 'cn', _('Group name'), true);
} }
// pykotaGroupName // pykotaGroupName
@ -229,7 +202,7 @@ class pykotaGroup extends baseModule {
$limitSelect->setSortElements(false); $limitSelect->setSortElements(false);
$container->addElement($limitSelect, true); $container->addElement($limitSelect, true);
// description // description
if ($this->manageDescription()) { if ($this->isUnixOrGonInactive($modules)) {
$this->addMultiValueInputTextField($container, 'description', _('Description'), false, null, true); $this->addMultiValueInputTextField($container, 'description', _('Description'), false, null, true);
} }
// remove button // remove button
@ -267,13 +240,14 @@ class pykotaGroup extends baseModule {
} }
return $errors; return $errors;
} }
$modules = $this->getAccountContainer()->get_type()->getModules();
if (isset($_POST['remObjectClass'])) { if (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('pykotaGroup'), $this->attributes['objectClass']); $this->attributes['objectClass'] = array_delete(array('pykotaGroup'), $this->attributes['objectClass']);
$attrs = array('pykotaLimitBy', 'pykotaGroupName'); $attrs = array('pykotaLimitBy', 'pykotaGroupName');
if ($this->manageDescription()) { if ($this->isUnixOrGonInactive($modules)) {
$attrs[] = 'description'; $attrs[] = 'description';
} }
if ($this->manageCn()) { if ($this->isUnixOrGonInactive($modules)) {
$attrs[] = 'cn'; $attrs[] = 'cn';
} }
foreach ($attrs as $name) { foreach ($attrs as $name) {
@ -288,7 +262,7 @@ class pykotaGroup extends baseModule {
return $errors; return $errors;
} }
// cn // cn
if ($this->manageCn()) { if ($this->isUnixOrGonInactive($modules)) {
if (isset($_POST['cn']) && ($_POST['cn'] != '')) { if (isset($_POST['cn']) && ($_POST['cn'] != '')) {
if (!get_preg($_POST['cn'], 'groupname')) { if (!get_preg($_POST['cn'], 'groupname')) {
$errors[] = $this->messages['cn'][0]; $errors[] = $this->messages['cn'][0];
@ -324,7 +298,7 @@ class pykotaGroup extends baseModule {
// limit by // limit by
$this->attributes['pykotaLimitBy'][0] = $_POST['pykotaLimitBy']; $this->attributes['pykotaLimitBy'][0] = $_POST['pykotaLimitBy'];
// description // description
if ($this->manageDescription()) { if ($this->isUnixOrGonInactive($modules)) {
$this->processMultiValueInputTextField('description', $errors); $this->processMultiValueInputTextField('description', $errors);
} }
return $errors; return $errors;
@ -350,6 +324,20 @@ class pykotaGroup extends baseModule {
return parent::save_attributes(); return parent::save_attributes();
} }
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
public function getManagedAttributes($typeId) {
$attrs = parent::getManagedAttributes($typeId);
$typeManager = new TypeManager();
if ($this->isUnixOrGonInactive($typeManager->getConfiguredType($typeId)->getModules())) {
$attrs[] = 'cn';
$attrs[] = 'description';
}
return $attrs;
}
/** /**
* This function is used to check if all settings for this module have been made. * This function is used to check if all settings for this module have been made.
* *
@ -387,6 +375,30 @@ class pykotaGroup extends baseModule {
} }
} }
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
function get_uploadColumns($selectedModules) {
$return = parent::get_uploadColumns($selectedModules);
if ($this->isUnixOrGonInactive($selectedModules)) {
$return[] = array(
'name' => 'pykotaGroup_cn',
'description' => _('Common name'),
'help' => 'cn',
'example' => _('adminstrators'),
'required' => true,
);
$return[] = array(
'name' => 'pykotaGroup_description',
'description' => _('Description'),
'help' => 'description',
'example' => _('Administrators group'),
);
}
return $return;
}
/** /**
* In this function the LDAP account is built up. * In this function the LDAP account is built up.
* *
@ -407,7 +419,7 @@ class pykotaGroup extends baseModule {
$partialAccounts[$i]['objectClass'][] = 'pykotaObject'; $partialAccounts[$i]['objectClass'][] = 'pykotaObject';
} }
// cn // cn
if ($this->manageCn() && !empty($rawAccounts[$i][$ids['pykotaGroup_cn']])) { if ($this->isUnixOrGonInactive($selectedModules) && !empty($rawAccounts[$i][$ids['pykotaGroup_cn']])) {
if (!get_preg($rawAccounts[$i][$ids['pykotaGroup_cn']], 'groupname')) { if (!get_preg($rawAccounts[$i][$ids['pykotaGroup_cn']], 'groupname')) {
$errMsg = $this->messages['cn'][1]; $errMsg = $this->messages['cn'][1];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
@ -458,6 +470,21 @@ class pykotaGroup extends baseModule {
return $messages; return $messages;
} }
/**
* {@inheritDoc}
* @see baseModule::get_pdfFields()
*/
public function get_pdfFields($typeId) {
$fields = parent::get_pdfFields($typeId);
$typeManager = new TypeManager();
$modules = $typeManager->getConfiguredType($typeId)->getModules();
if ($this->isUnixOrGonInactive($modules)) {
$fields['cn'] = _('Common name');
$fields['description'] = _('Description');
}
return $fields;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* @see baseModule::get_pdfEntries() * @see baseModule::get_pdfEntries()
@ -477,44 +504,21 @@ class pykotaGroup extends baseModule {
} }
/** /**
* Returns if the cn attribute should be managed. * Checks if the active modules contain Unix or group of names.
* *
* @return boolean manage cn attribute * @param string[] $modules modules
* @return bool not active
*/ */
private function manageCn() { private function isUnixOrGonInactive($modules) {
if (isset($_SESSION['config'])) { if (in_array('posixGroup', $modules)
$conf = $_SESSION['config']; || in_array('groupOfNames', $modules)
if (in_array('posixGroup', $conf->get_AccountModules($this->get_scope())) || in_array('groupOfUniqueNames', $modules)) {
|| in_array('groupOfNames', $conf->get_AccountModules($this->get_scope()))
|| in_array('groupOfUniqueNames', $conf->get_AccountModules($this->get_scope()))) {
return false; return false;
} }
else { else {
return true; return true;
} }
} }
return false;
}
/**
* Returns if the description attribute should be managed.
*
* @return boolean manage description attribute
*/
private function manageDescription() {
if (isset($_SESSION['config'])) {
$conf = $_SESSION['config'];
if (in_array('posixGroup', $conf->get_AccountModules($this->get_scope()))
|| in_array('groupOfNames', $conf->get_AccountModules($this->get_scope()))
|| in_array('groupOfUniqueNames', $conf->get_AccountModules($this->get_scope()))) {
return false;
}
else {
return true;
}
}
return false;
}
/** /**
* Returns if the given cn already exists. * Returns if the given cn already exists.