Commit 6f9a9936 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Côme Bernigaud
Browse files

Fixes: #2624 ogroup should use simplePlugin

Conflicts:
	plugins/admin/ogroups/class_ogroup.inc
	plugins/admin/ogroups/class_ogroupManagement.inc
	plugins/admin/ogroups/tabs_ogroups.inc
Showing with 92 additions and 252 deletions
+92 -252
......@@ -55,27 +55,15 @@ class ogroupManagement extends simpleManagement
static function filterProperties($row, $gosaGroupObjects)
{
$conv= array(
"Y" => array("plugins/users/images/select_template.png" ,_("Templates") ,"ogroup"),
"U" => array('geticon.php?context=types&icon=user&size=16' ,_("User") ,"ogroup"),
"G" => array('geticon.php?context=types&icon=user-group&size=16' ,_("Group") ,"ogroup"),
"A" => array('geticon.php?context=types&icon=application&size=16' ,_("Application") ,"ogroup"),
"D" => array('geticon.php?context=places&icon=folder&size=16' ,_("Department") ,"ogroup"),
"S" => array('geticon.php?context=devices&icon=server&size=16' ,_("Server") ,"ogroup"),
"F" => array('geticon.php?context=devices&icon=telephone&size=16' ,_("Phone") ,"phonequeue"),
"W" => array('geticon.php?context=devices&icon=computer&size=16' ,_("Workstation") ,"workstartup"),
"O" => array('geticon.php?context=devices&icon=computer-windows&size=16' ,_("Windows Install") ,"ogroup"),
"T" => array('geticon.php?context=devices&icon=terminal&size=16' ,_("Terminal") ,"termgroup"),
"P" => array('geticon.php?context=devices&icon=printer&size=16' ,_("Printer") ,"ogroup")
);
$types = preg_replace("/[^a-z]/i","",$gosaGroupObjects[0]);
$result ="";
for($i = 0 ; $i < strlen($types); $i++){
$type = $types[$i];
$result.="<input class='center' type='image' src='".$conv[$type][0]."' ".
"alt='".$conv[$type][1]."' title='".$conv[$type][1].
"' name='listing_edit_tab_".$conv[$type][2]."_$row' style='padding:1px'>";
$types = preg_replace("/[^a-z]/i", "", $gosaGroupObjects[0]);
$result = "";
for ($i = 0; $i < strlen($types); $i++) {
if ($types[$i] == 'I') {
continue;
}
$info = objects::infos(ogroup::$objectTypes[$types[$i]]);
$result .= '<img class="center" src="'.$info['icon'].'" '.
'alt="'.$info['name'].'" title="'.$info['name'].'" style="padding:1px"/>';
}
if ($result == "") {
return '&nbsp;';
......
......@@ -45,7 +45,7 @@
</column>
<column>
<label>Properties</label>
<label>Object types</label>
<value>%{filter:filterProperties(row,gosaGroupObjects)}</value>
</column>
......
......@@ -19,227 +19,108 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class ogrouptabs extends tabs
class ogrouptabs extends simpleTabs_noSpecial
{
var $base = "";
var $acl_category;
var $dynamic_tabs;
private $groupObjects = NULL;
function __construct($config, $data, $dn, $category = "ogroup", $copied_object = NULL)
function __construct($type, $dn, $copied_object = NULL)
{
parent::__construct($config, $data, $dn, $category, $copied_object);
$this->base = $this->by_object['ogroup']->base;
$this->acl_category = $category;
parent::__construct($type, $dn, $copied_object);
/* Add references/acls/snapshots */
$this->dynamic_tabs = array(
"/T/" => array(
'termservice' => _('Devices'),
'termstartup' => _('Startup'),
),
"/[WT]/" => array(
'termgroup' => _('Systems'),
),
"/W/" => array(
'workservice' => _('Devices'),
),
"/[SW]/" => array(
'workstartup' => _('Workstartup'),
'debconfStartup' => _('Debconf'),
'faiStartup' => _('FAI'),
'faiSummary' => _('FAI summary'),
'argonautClient' => _('Argonaut client'),
),
"/O/" => array(
'opsiClient' => _('OPSI'),
),
);
$this->reload($this->by_object['ogroup']->gosaGroupObjects);
$this->addSpecialTabs();
$this->loadtabs($this->getBaseObject()->gosaGroupObjects);
}
function reload($dd)
function loadtabs($gosaGroupObjects)
{
$objects = preg_replace('/[\[\]]/', '', $dd);
$baseobject = $this->getBaseObject();
/* Check if we have a group with a set different mixed objects.
*/
$mixed_type = FALSE;
for ($i = 0 ; $i < (strlen($objects) -1 );$i++) {
$mixed_type |= $objects[$i] != $objects[($i+1)];
if ($this->groupObjects == $gosaGroupObjects) {
return;
}
/* If there is a phonequeue,
* but there is no user left with goPhoneAccount ... remove it.
*/
$usePhoneTab = false;
if (class_available("phonequeue")) {
foreach($baseobject->memberList as $dn => $val){
if(isset($baseobject->objcache[$dn])){
$obj = $baseobject->objcache[$dn];
if(isset($obj['objectClass'])){
if(in_array("goFonAccount",$obj['objectClass'])){
$usePhoneTab = true;
}
}
$this->groupObjects = $gosaGroupObjects;
$objects = preg_replace('/[\[\]]/', '', $gosaGroupObjects);
$tabs = array();
if (strlen($objects)) {
$dtabs = $this->config->data['TABS']['OGROUP-DYNAMICTABS'];
$tabs = FALSE;
for ($i = 0; $i < strlen($objects); $i++) {
if ($objects[$i] == 'I') {
continue;
}
}
if((!$usePhoneTab && isset($this->by_object['phonequeue']))||
(!preg_match("/U/",$objects) && isset($this->by_object['phonequeue']))){
$this->by_object['phonequeue']->remove_from_parent();
unset($this->by_object['phonequeue']);
unset($this->by_name['phonequeue']);
}
}
/* Remove mail group if there is no user anymore
*/
if(class_available("mailogroup")){
if(!preg_match("/U/",$objects) && isset($this->by_object['mailogroup'])){
$this->by_object['mailogroup']->remove_from_parent();
unset($this->by_object['mailogroup']);
unset($this->by_name['mailogroup']);
}
}
/* Create goPhoneAccount if theres an user with goPhoneAccount
* but only if there is currently no queue enabled.
*/
if(class_available("phonequeue")){
if(!isset($this->by_object['phonequeue'])){
foreach($baseobject->memberList as $dn => $val){
if(isset($baseobject->objcache[$dn])){
$obj = $baseobject->objcache[$dn];
if(isset($obj['objectClass'])){
if(in_array("goFonAccount",$obj['objectClass'])){
$this->by_name['phonequeue'] = _("Phone queue");
$this->by_object['phonequeue'] = new phonequeue($this->config, $this->dn, $baseobject);
$this->by_object['phonequeue']->parent = &$this;
break;
}
$otype = ogroup::$objectTypes[$objects[$i]];
$otabs = array();
if (isset($this->config->data['TABS'][strtoupper($otype).'TABS'])) {
$otabs = array_uintersect(
$dtabs,
$this->config->data['TABS'][strtoupper($otype).'TABS'],
function ($a, $b)
{
return strcmp($a['CLASS'], $b['CLASS']);
}
}
);
}
}
}
/* Add mail group tab , if there is curerntly no mail tab defined */
if(class_available("mailogroup")){
if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
if ($this->config->get_cfg_value("mailmethod") == "kolab"){
$this->by_name['mailogroup']= _("Mail");
$this->by_object['mailogroup']= new mailogroup($this->config, $this->dn, $baseobject);
$this->by_object['mailogroup']->parent= &$this;
if (isset($this->config->data['TABS']['OGROUP-'.strtoupper($otype).'TABS'])) {
$otabs = array_merge(
$otabs,
$this->config->data['TABS']['OGROUP-'.strtoupper($otype).'TABS']
);
}
}
}
/* Add Workstation tabs */
if (!$mixed_type) {
foreach ($this->dynamic_tabs as $pattern => $tabs) {
if (preg_match($pattern,$objects)) {
foreach ($tabs as $class => $name) {
if (class_available($class) && !isset($this->by_object["$class"])) {
$this->addTab($class, $name);
}
}
if ($tabs === FALSE) {
$tabs = $otabs;
} else {
foreach ($tabs as $class => $name) {
if (class_available($class) && isset($this->by_object["$class"])) {
$this->by_object["$class"]->remove_from_parent();
unset($this->by_object["$class"]);
unset($this->by_name["$class"]);
$tabs = array_uintersect(
$tabs,
$otabs,
function ($a, $b)
{
return strcmp($a['CLASS'], $b['CLASS']);
}
}
);
}
}
if (isset($this->by_object['workservice'])) {
$this->by_object['workservice']->inheritTimeServer = false;
}
if (isset($this->by_object['termgroup'])) {
$this->by_object['termgroup']->inheritTimeServer = false;
}
}
$tabs = array_merge($this->config->data['TABS']['OGROUPTABS'], (array)$tabs);
$tabs = array_map(
function ($a)
{
return $a['CLASS'];
},
$tabs
);
/* Add environment tab if user or group is member in this object group*/
if(class_available("environment")){
if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
$this->by_name['environment']= _("Environment");
$this->by_object['environment']= new environment($this->config, $this->dn, $baseobject);
$this->by_object['environment']->acl = "#all#";
$this->by_object['environment']->parent= &$this;
foreach ($this->by_object as $tab => $object) {
if (!in_array($tab, $tabs)) {
$this->delTab($tab);
}
}
/* Remove environment tab if not required any longer */
if(class_available("environment")){
if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
$this->by_object['environment']->remove_from_parent();
unset($this->by_name['environment']);
unset($this->by_object['environment']);
foreach ($tabs as $class) {
if (class_available($class) && !isset($this->by_object["$class"])) {
$this->addTab($class);
}
}
$this->addSpecialTabs();
}
/* Add application tab if user or group is member in this object group*/
if(class_available("appgroup")){
if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
$this->by_name['appgroup']= _("Applications");
$this->by_object['appgroup']= new appgroup($this->config, $this->dn, $baseobject);
$this->by_object['appgroup']->acl = "#all#";
$this->by_object['appgroup']->parent= &$this;
}
}
/* Remove application tab if not required any longer */
if(class_available("appgroup")){
if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
$this->by_object['appgroup']->remove_from_parent();
unset($this->by_name['appgroup']);
unset($this->by_object['appgroup']);
}
}
/* Move reference tab to second position from right */
if(class_available("acl")){
if(isset($this->by_name['acl'])){
$tmp = $this->by_name['acl'];
unset($this->by_name['acl']);
$this->by_name['acl'] = $tmp;
}
/* Move reference tab to last position*/
if(class_available("reference")){
if(isset($this->by_name['reference'])){
$tmp = $this->by_name['reference'];
unset($this->by_name['reference']);
$this->by_name['reference'] = $tmp;
}
}
/* Reset acls */
if($this->dn == "new"){
$this->set_acl_base($this->base);
}else{
$this->set_acl_base($this->dn);
}
foreach($this->by_object as $name => $obj){
$this->by_object[$name]->set_acl_category($this->acl_category);
}
}
function addTab ($class)
{
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $class, "Adding tab ");
$plInfos = pluglist::pluginInfos($class);
$this->by_name["$class"] = $plInfos['plShortName'];
$this->by_object["$class"] = new $class($this->config, $this->dn, $this->getBaseObject());
$this->by_object["$class"]->parent = &$this;
$this->by_object["$class"]->set_acl_category($this->acl_category);
}
function addTab ($class, $name) {
$this->by_name["$class"] = $name;
$this->by_object["$class"] = new $class($this->config, $this->dn, $this->getBaseObject());
$this->by_object["$class"]->parent = &$this;
$this->by_object["$class"]->acl = "#all#";
function delTab ($class)
{
$this->by_object["$class"]->remove_from_parent();
unset($this->by_object["$class"]);
unset($this->by_name["$class"]);
}
function execute() {
$this->reload($this->by_object['ogroup']->gosaGroupObjects);
return parent::execute();
function gen_tabs($disabled = FALSE)
{
$this->loadtabs($this->getBaseObject()->getGroupObjectTypes());
return parent::gen_tabs($disabled);
}
function check($ignore_account = FALSE)
......@@ -247,57 +128,28 @@ class ogrouptabs extends tabs
return parent::check(FALSE);
}
function save_object($save_current = FALSE)
{
parent::save_object($save_current);
/* Update reference, transfer variables */
$baseobject= $this->by_object['ogroup'];
$baseobject = $this->getBaseObject();
foreach ($this->by_object as $name => $obj) {
/* Don't touch base object */
if ($name != 'ogroup') {
$obj->parent = &$this;
$obj->uid = $baseobject->uid;
$obj->uid = $baseobject->cn;
$obj->cn = $baseobject->cn;
$obj->sn = $baseobject->uid;
$obj->givenName = $baseobject->uid;
$this->by_object[$name]= $obj;
}
/* Update parent in base object */
$this->by_object['ogroup']->parent = &$this;
}
}
function save()
{
$baseobject = $this->getBaseObject();
/* Check for new 'dn', in order to propagate the
'dn' to all plugins */
$new_dn = $baseobject->compute_dn();
/* Move group? */
if (LDAP::fix($this->dn) != LDAP::fix($new_dn)) {
$obj->sn = $baseobject->cn;
$obj->givenName = $baseobject->cn;
/* Write entry on new 'dn' */
if ($this->dn != "new") {
$baseobject->move($this->dn, $new_dn);
$this->by_object['ogroup']= $baseobject;
$this->by_object[$name] = $obj;
}
/* Happen to use the new one */
$this->dn= $new_dn;
}
if ($this->dn == "new") {
$this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupRDN').$baseobject->base;
}
tabs::save();
/* Update parent in base object */
$this->by_object['ogroup']->parent = &$this;
}
}
?>
  • bmortier @bmortier

    mentioned in issue #891 (closed)

    By Côme Chilliet on 2017-09-02T15:03:02 (imported from GitLab)

    ·

    mentioned in issue #891 (closed)

    By Côme Chilliet on 2017-09-02T15:03:02 (imported from GitLab)

    Toggle commit list
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