new type API

This commit is contained in:
Roland Gruber 2017-05-06 10:47:19 +02:00
parent 9c9d8b3f09
commit f60c37edcd
3 changed files with 189 additions and 131 deletions

View File

@ -1,10 +1,11 @@
<?php
use \LAM\TYPES\TypeManager;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2007 - 2016 Roland Gruber
2007 - 2017 Roland Gruber
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
@ -41,10 +42,6 @@ class posixGroup extends baseModule implements passwordService {
/** change GIDs of users and hosts? */
private $changegids;
/** specifies if the cn attribute should be managed by this module */
protected $manageCnAttribute = true;
/** specifies if the description attribute should be managed by this module */
protected $manageDescriptionAttribute = true;
/** password attribute */
protected $passwordAttrName = 'userPassword';
/** cache for existing GID numbers */
@ -54,6 +51,35 @@ class posixGroup extends baseModule implements passwordService {
/** cache for existing groups */
private $cachedGroupNameList = null;
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
function get_uploadColumns($selectedModules) {
$return = parent::get_uploadColumns($selectedModules);
if ($this->manageCnAndDescription($selectedModules)) {
array_unshift($return,
array(
'name' => 'posixGroup_cn',
'description' => _('Group name'),
'help' => 'cn',
'example' => _('adminstrators'),
'required' => true,
'unique' => true
)
);
array_unshift($return,
array(
'name' => 'posixGroup_description',
'description' => _('Group description'),
'help' => 'description',
'example' => _('Administrators group')
)
);
}
return $return;
}
/**
* In this function the LDAP account is built up.
*
@ -68,7 +94,7 @@ class posixGroup extends baseModule implements passwordService {
$needAutoGID = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
if (!in_array("posixGroup", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixGroup";
if ($this->manageCnAttribute) {
if ($this->manageCnAndDescription($selectedModules)) {
// group name
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'posixGroup_cn', 'cn', 'groupname', $this->messages['cn'][3], $error_messages);
}
@ -85,7 +111,7 @@ class posixGroup extends baseModule implements passwordService {
array_push($errMsg, array($i));
$error_messages[] = $errMsg;
}
if ($this->manageDescriptionAttribute) {
if ($this->manageCnAndDescription($selectedModules)) {
// description (UTF-8, no regex check needed)
if ($rawAccounts[$i][$ids['posixGroup_description']] == "") {
$partialAccounts[$i]['description'] = $partialAccounts[$i]['cn'];
@ -164,13 +190,14 @@ class posixGroup extends baseModule implements passwordService {
*/
function display_html_attributes() {
$return = new htmlTable();
$modules = $this->getAccountContainer()->get_type()->getModules();
if ($this->autoAddObjectClasses || (isset($this->attributes['objectClass']) && in_array('posixGroup', $this->attributes['objectClass']))) {
// auto sync group members
if ($this->isBooleanConfigOptionSet('posixGroup_autoSyncGon')) {
$this->syncGon();
}
// group name
if ($this->manageCnAttribute) {
if ($this->manageCnAndDescription($modules)) {
$cn = '';
if (isset($this->attributes['cn'][0])) {
$cn = $this->attributes['cn'][0];
@ -194,7 +221,7 @@ class posixGroup extends baseModule implements passwordService {
if (isset($this->attributes['description'][0])) {
$description = $this->attributes['description'][0];
}
if ($this->manageDescriptionAttribute) {
if ($this->manageCnAndDescription($modules)) {
$return->addElement(new htmlTableExtendedInputField(_('Description'), 'description', $description, 'description'), true);
}
// password buttons
@ -399,12 +426,6 @@ class posixGroup extends baseModule implements passwordService {
if (!$this->isBooleanConfigOptionSet('posixGroup_hidememberUid')) {
$return['attributes'][] = 'memberUid';
}
if ($this->manageCnAttribute) {
$return['attributes'][] = 'cn';
}
if ($this->manageDescriptionAttribute) {
$return['attributes'][] = 'description';
}
// profile options
if (!$this->autoAddObjectClasses) {
$profileContainer = new htmlTable();
@ -419,12 +440,6 @@ class posixGroup extends baseModule implements passwordService {
$return['PDF_fields']['memberUid'] = _('Group members');
$return['PDF_fields']['memberUidPrimary'] = _('Group members (incl. primary members)');
}
if ($this->manageCnAttribute) {
$return['PDF_fields']['cn'] = _('Group name');
}
if ($this->manageDescriptionAttribute) {
$return['PDF_fields']['description'] = _('Description');
}
// upload fields
$return['upload_columns'] = array(
array(
@ -448,28 +463,6 @@ class posixGroup extends baseModule implements passwordService {
'example' => _('user01,user02,user03')
);
}
if ($this->manageCnAttribute) {
array_unshift($return['upload_columns'],
array(
'name' => 'posixGroup_cn',
'description' => _('Group name'),
'help' => 'cn',
'example' => _('adminstrators'),
'required' => true,
'unique' => true
)
);
}
if ($this->manageDescriptionAttribute) {
array_unshift($return['upload_columns'],
array(
'name' => 'posixGroup_description',
'description' => _('Group description'),
'help' => 'description',
'example' => _('Administrators group')
)
);
}
// help Entries
$return['help'] = array(
'gidNumber' => array(
@ -612,6 +605,21 @@ class posixGroup extends baseModule implements passwordService {
return $configContainer;
}
/**
* {@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->manageCnAndDescription($modules)) {
$fields['cn'] = _('Group name');
$fields['description'] = _('Description');
}
return $fields;
}
/**
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
@ -673,6 +681,21 @@ class posixGroup extends baseModule implements passwordService {
}
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
public function getManagedAttributes($typeId) {
$attrs = parent::getManagedAttributes($typeId);
$typeManager = new TypeManager();
$modules = $typeManager->getConfiguredType($typeId)->getModules();
if ($this->manageCnAndDescription($modules)) {
$attrs[] = 'cn';
$attrs[] = 'description';
}
return $attrs;
}
/**
* This functions is used to check if all settings for this module have been made.
*
@ -686,8 +709,13 @@ class posixGroup extends baseModule implements passwordService {
return true;
}
}
if ($this->manageCnAttribute && ($this->attributes['cn'][0] == '')) return false;
if ($this->attributes['gidNumber'][0] == '') return false;
$modules = $this->getAccountContainer()->get_type()->getModules();
if ($this->manageCnAndDescription($modules) && ($this->attributes['cn'][0] == '')) {
return false;
}
if ($this->attributes['gidNumber'][0] == '') {
return false;
}
return true;
}
@ -736,11 +764,12 @@ class posixGroup extends baseModule implements passwordService {
}
return $errors;
}
$modules = $this->getAccountContainer()->get_type()->getModules();
// skip processing if object class is not set
if (!$this->autoAddObjectClasses && (!isset($this->attributes['objectClass']) || !in_array('posixGroup', $this->attributes['objectClass']))) {
return $errors;
}
if ($this->manageDescriptionAttribute) {
if ($this->manageCnAndDescription($modules)) {
$this->attributes['description'][0] = $_POST['description'];
}
if (isset($_POST['lockPassword'])) {
@ -802,7 +831,7 @@ class posixGroup extends baseModule implements passwordService {
}
}
}
if ($this->manageCnAttribute) {
if ($this->manageCnAndDescription($modules)) {
$this->attributes['cn'][0] = $_POST['cn'];
if (preg_match('/^[A-Z]+$/', $_POST['cn'])) {
$errors[] = $this->messages['cn'][0];
@ -1310,6 +1339,16 @@ class posixGroup extends baseModule implements passwordService {
return false;
}
/**
* Returns if cn and description attributes should be managed.
*
* @param string[] $modules modules
* @return boolean manage cn+description
*/
protected function manageCnAndDescription($modules) {
return true;
}
}
?>

View File

@ -2,6 +2,7 @@
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
use \LAM\TYPES\TypeManager;
/*
$Id$
@ -205,32 +206,6 @@ class pykotaUser extends baseModule {
'required' => true,
);
}
if ($this->manageUid()) {
$return['upload_columns'][] = array(
'name' => 'pykotaUser_uid',
'description' => _('User name'),
'help' => 'uid',
'example' => _('smiller'),
'required' => true,
'unique' => true,
);
}
if ($this->manageMail()) {
$return['upload_columns'][] = array(
'name' => 'pykotaUser_mail',
'description' => _('Email address'),
'help' => 'mail',
'example' => _('user@company.com'),
);
}
if ($this->manageDescription()) {
$return['upload_columns'][] = array(
'name' => 'pykotaUser_description',
'description' => _('Description'),
'help' => 'description',
'example' => _('Temp, contract till December'),
);
}
$return['upload_columns'][] = array(
'name' => 'pykotaUser_pykotaLimitBy',
'description' => _('Limit type'),
@ -267,18 +242,9 @@ class pykotaUser extends baseModule {
'pykotaLifeTimePaid' => _('Total paid'),
'pykotaPayments' => _('Payment history'),
);
if ($this->manageUid()) {
$return['PDF_fields']['uid'] = _('User name');
}
if ($this->isStructural()) {
$return['PDF_fields']['cn'] = _('Common name');
}
if ($this->manageMail()) {
$return['PDF_fields']['mail'] = _('Email address');
}
if ($this->manageDescription()) {
$return['PDF_fields']['description'] = _('Description');
}
// self service
$return['selfServiceFieldSettings'] = array(
'pykotaBalance' => _('Balance (read-only)'),
@ -337,9 +303,10 @@ class pykotaUser extends baseModule {
*/
function display_html_attributes() {
$container = new htmlTable();
$modules = $this->getAccountContainer()->get_type()->getModules();
if ($this->isStructural() || (isset($this->attributes['objectClass']) && in_array('pykotaAccount', $this->attributes['objectClass']))) {
// uid
if ($this->manageUid()) {
if ($this->manageUid($modules)) {
$this->addSimpleInputTextField($container, 'uid', _('User name'), true);
}
else {
@ -408,11 +375,11 @@ class pykotaUser extends baseModule {
$this->addSimpleInputTextField($container, 'cn', _('Common name'), true);
}
// mail
if ($this->manageMail()) {
if ($this->manageMail($modules)) {
$this->addSimpleInputTextField($container, 'mail', _('Email address'));
}
// description
if ($this->manageDescription()) {
if ($this->manageDescription($modules)) {
$this->addMultiValueInputTextField($container, 'description', _('Description'), false, null, true);
}
// remove button
@ -453,16 +420,17 @@ class pykotaUser extends baseModule {
}
return $errors;
}
$modules = $this->getAccountContainer()->get_type()->getModules();
if (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('pykotaAccount', 'pykotaAccountBalance'), $this->attributes['objectClass']);
$attrs = array('pykotaLimitBy', 'pykotaUserName');
if ($this->manageDescription()) {
if ($this->manageDescription($modules)) {
$attrs[] = 'description';
}
if ($this->manageMail()) {
if ($this->manageMail($modules)) {
$attrs[] = 'mail';
}
if ($this->manageUid()) {
if ($this->manageUid($modules)) {
$attrs[] = 'uid';
}
foreach ($attrs as $name) {
@ -477,7 +445,7 @@ class pykotaUser extends baseModule {
return $errors;
}
// uid
if ($this->manageUid()) {
if ($this->manageUid($modules)) {
if (isset($_POST['uid']) && ($_POST['uid'] != '')) {
if (!get_preg($_POST['uid'], 'username')) {
$errors[] = $this->messages['uid'][0];
@ -520,14 +488,14 @@ class pykotaUser extends baseModule {
}
}
// mail
if ($this->manageMail()) {
if ($this->manageMail($modules)) {
$this->attributes['mail'][0] = $_POST['mail'];
if (!empty($_POST['mail']) && !get_preg($_POST['mail'], 'email')) {
$errors[] = $this->messages['mail'][0];
}
}
// description
if ($this->manageDescription()) {
if ($this->manageDescription($modules)) {
$this->processMultiValueInputTextField('description', $errors);
}
// overcharge factor
@ -761,6 +729,41 @@ class pykotaUser extends baseModule {
}
}
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
function get_uploadColumns($selectedModules) {
$return = parent::get_uploadColumns($selectedModules);
if ($this->manageUid($selectedModules)) {
$return[] = array(
'name' => 'pykotaUser_uid',
'description' => _('User name'),
'help' => 'uid',
'example' => _('smiller'),
'required' => true,
'unique' => true,
);
}
if ($this->manageMail($selectedModules)) {
$return[] = array(
'name' => 'pykotaUser_mail',
'description' => _('Email address'),
'help' => 'mail',
'example' => _('user@company.com'),
);
}
if ($this->manageDescription($selectedModules)) {
$return[] = array(
'name' => 'pykotaUser_description',
'description' => _('Description'),
'help' => 'description',
'example' => _('Temp, contract till December'),
);
}
return $return;
}
/**
* In this function the LDAP account is built up.
*
@ -788,7 +791,7 @@ class pykotaUser extends baseModule {
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['pykotaUser_cn']];
}
// uid
if ($this->manageUid() && !empty($rawAccounts[$i][$ids['pykotaUser_uid']])) {
if ($this->manageUid($selectedModules) && !empty($rawAccounts[$i][$ids['pykotaUser_uid']])) {
if (!get_preg($rawAccounts[$i][$ids['pykotaUser_uid']], 'username')) {
$errMsg = $this->messages['uid'][1];
array_push($errMsg, array($i));
@ -804,7 +807,7 @@ class pykotaUser extends baseModule {
}
}
// mail
if ($this->manageUid() && !empty($rawAccounts[$i][$ids['pykotaUser_mail']])) {
if ($this->manageUid($selectedModules) && !empty($rawAccounts[$i][$ids['pykotaUser_mail']])) {
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'pykotaUser_mail', 'mail',
'email', $this->messages['mail'][1], $messages);
}
@ -883,6 +886,26 @@ class pykotaUser extends baseModule {
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->manageUid($modules)) {
$fields['uid'] = _('User name');
}
if ($this->manageMail($modules)) {
$fields['mail'] = _('Email address');
}
if ($this->manageDescription($modules)) {
$fields['description'] = _('Description');
}
return $fields;
}
/**
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
@ -1044,56 +1067,47 @@ class pykotaUser extends baseModule {
/**
* Returns if the uid attribute should be managed.
*
* @param string[] $modules account modules
* @return boolean manage uid attribute
*/
private function manageUid() {
if (isset($_SESSION['config'])) {
$conf = $_SESSION['config'];
if (in_array('inetOrgPerson', $conf->get_AccountModules($this->get_scope()))
|| in_array('posixAccount', $conf->get_AccountModules($this->get_scope()))) {
return false;
}
else {
return true;
}
private function manageUid($modules) {
if (in_array('inetOrgPerson', $modules)
|| in_array('posixAccount', $modules)) {
return false;
}
else {
return true;
}
return false;
}
/**
* Returns if the mail attribute should be managed.
*
* @param string[] $modules account modules
* @return boolean manage mail attribute
*/
private function manageMail() {
if (isset($_SESSION['config'])) {
$conf = $_SESSION['config'];
if (in_array('inetOrgPerson', $conf->get_AccountModules($this->get_scope()))) {
return false;
}
else {
return true;
}
private function manageMail($modules) {
if (in_array('inetOrgPerson', $modules)) {
return false;
}
else {
return true;
}
return false;
}
/**
* Returns if the description attribute should be managed.
*
* @param string[] $modules account modules
* @return boolean manage description attribute
*/
private function manageDescription() {
if (isset($_SESSION['config'])) {
$conf = $_SESSION['config'];
if (in_array('inetOrgPerson', $conf->get_AccountModules($this->get_scope()))) {
return false;
}
else {
return true;
}
private function manageDescription($modules) {
if (in_array('inetOrgPerson', $modules)) {
return false;
}
else {
return true;
}
return false;
}
/**

View File

@ -3,7 +3,7 @@
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 Roland Gruber
Copyright (C) 2013 - 2017 Roland Gruber
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
@ -36,16 +36,13 @@ include_once("posixGroup.inc");
* @package modules
*/
class windowsPosixGroup extends posixGroup {
/**
* Creates a new windowsPosixGroup object.
*
* @param string $scope account type (user, group, host)
*/
public function __construct($scope) {
// do not manage cn and description (managed by windowsGroup)
$this->manageCnAttribute = false;
$this->manageDescriptionAttribute = false;
// different password attribute name
$this->passwordAttrName = 'unixUserPassword';
// make optional
@ -53,12 +50,12 @@ class windowsPosixGroup extends posixGroup {
// call parent constructor
parent::__construct($scope);
}
/**
* Returns meta data that is interpreted by parent class
*
* @return array array with meta data
*
*
* @see baseModule::get_metaData()
*/
function get_metaData() {
@ -90,6 +87,14 @@ class windowsPosixGroup extends posixGroup {
return true;
}
/**
* {@inheritdoc}
*/
protected function manageCnAndDescription($modules) {
// do not manage cn and description (managed by windowsGroup)
return false;
}
}
?>