From 8102c2c8d2475945a49147524623cb7d9f7de39e Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 30 Jun 2009 14:17:04 +0000 Subject: [PATCH] Added first part of the role management plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13856 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../roleManagement/class_divListRole.inc | 225 ++++++++++++++++ .../roleManagement/class_roleGeneric.inc | 44 +++ .../roleManagement/class_roleManagement.inc | 252 ++++++++++++++++++ .../admin/roleManagement/main.inc | 67 +++++ .../admin/roleManagement/roleGeneric.tpl | 169 ++++++++++++ .../admin/roleManagement/tabs_roles.inc | 75 ++++++ gosa-plugins/roleManagement/plugin.dsc | 7 + 7 files changed, 839 insertions(+) create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/class_divListRole.inc create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/class_roleManagement.inc create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/main.inc create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/roleGeneric.tpl create mode 100644 gosa-plugins/roleManagement/admin/roleManagement/tabs_roles.inc create mode 100644 gosa-plugins/roleManagement/plugin.dsc diff --git a/gosa-plugins/roleManagement/admin/roleManagement/class_divListRole.inc b/gosa-plugins/roleManagement/admin/roleManagement/class_divListRole.inc new file mode 100644 index 000000000..bc76d0e88 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/class_divListRole.inc @@ -0,0 +1,225 @@ +parent = $parent; + $this->ui = get_userinfo(); + $action_col_size = 90; + + // Set list strings + $this->SetTitle(_("List of roles")); + $this->SetSummary(_("List of roles")); + $this->EnableAplhabet(true); + + // Result page will look like a headpage + $this->SetHeadpageMode(); + + // Disable buttonsm + $this->EnableCloseButton(false); + $this->EnableSaveButton (false); + + // Add checkbox: Toggle all selected / deselected + $chk = ""; + + // Set Page col headers + $this->AddHeader(array("string" => $chk,"attach"=>"style='width:20px;'")); + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Role")." / "._("Department"), "attach" => "style=''")); + $this->AddHeader(array("string" => _("Actions"), + "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); + + // Add SubSearch checkbox + //$this->AddCheckBox(SEPERATOR); + $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), + msgPool::selectToView("","subsearch_small"), false); + + // Add regex user input field + $this->AddRegex ("Regex", _("Regular expression for matching role names"), "*" , true); + } + + + function GenHeader() + { + /* Get all departments within this subtree */ + $ui= get_userinfo(); + $first = ""; + $found = FALSE; + $base = $this->config->current['BASE']; + $options = $this->create_department_list($this->module); + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge( + $tmp, + get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", + $this->module, + $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + /* Add a seperator after displaying c&p and snapshot icons ? */ + $add_sep = false; + + /* Get copy & paste icon */ + $acls = $ui->get_permissions($this->selectedBase,"roles/role"); + $acl_all= $ui->has_complete_category_acls($this->selectedBase,"roles"); + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + + /* Add department selector */ + $listhead .= _("Base")." ". + "  "; + + /* Create Layers menu */ + $s = ".|"._("Actions")."|\n"; + + /* Append create options */ + if(preg_match("/c/",$acls)) { + $s .= "..|". + " "._("Create")."|\n"; + $s.= "...|". + " "._("Roles")."|role_new|\n"; + } + + /* Multiple options */ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Remove")."|"."remove_multiple_roles|\n"; + + $this->SetDropDownHeaderMenu($s); + $this->SetListHeader($listhead); + } + + + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + } + + function setEntries($list) + { + // Defining Links + $editlink = "%s"; + + $action_col_size = 90; + + $ui = get_userinfo(); + + // Assigning roles + foreach($list as $key => $val){ + + // Get object permissions + $acl = $ui->get_permissions($val['dn'],"roles/role"); + $acl_all= $ui->has_complete_category_acls($val['dn'],"roles"); + + // Add copy & cut functionality + $actions = $this->parent->get_copypaste_action($val['dn'],"roles","role"); + + // Create edit and remove icon buttons + $actions.= ""; + $actions.= $this->parent->get_snapshot_action($val['dn'],$this->module); + if(preg_match("/d/",$acl)){ + $actions.= ""; + }else{ + $actions.= " "; + } + + // Append role descriptio, if available + $title = "title='".preg_replace('/ /', ' ', LDAP::fix($val['dn']))."'"; + if(!isset($val['description'][0])){ + $desc = ""; + }else{ + $desc = " - [ ".$val['description'][0]." ]"; + } + + // Cutted entry are displayed in a light grey as indication. + $display = $val['cn'][0].$desc; + if($this->parent->CopyPasteHandler){ + foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ + if($queue_data['dn'] == $val['dn']) { + $display = "".$display.""; + break; + } + } + } + + // Append the entry to the divlist + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => ""._("Role")."", + "attach" => "style='text-align:center;width: 20px;'"); + $field2 = array("string" => sprintf($editlink,$key,$display), + "attach" => "style='' ".$title); + $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), + "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); + + $this->AddElement(array($field0,$field1,$field2,$field4)); + } + + + // Create the list summary + $num_deps=0; + if(!$this->SubSearch){ + $num_deps = count($this->Added_Departments); + } + $num_objs = count($list); + $num_obj_str = _("Number of listed roles"); + $num_dep_str = _("Number of listed departments"); + $str = "".$num_obj_str." ".$num_objs."    "; + $str.= "".$num_dep_str." ".$num_deps."    "; + $this->set_List_Bottom_Info($str); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc b/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc new file mode 100644 index 000000000..098215732 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/class_roleGeneric.inc @@ -0,0 +1,44 @@ +fetch(get_template_path('roleGeneric.tpl',TRUE,dirname(__FILE__)))); + } + +} + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/roleManagement/admin/roleManagement/class_roleManagement.inc b/gosa-plugins/roleManagement/admin/roleManagement/class_roleManagement.inc new file mode 100644 index 000000000..6752cde43 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/class_roleManagement.inc @@ -0,0 +1,252 @@ +config= &$config; + $this->ui= get_userinfo(); + + // Copy & Paste enabled ? + if ($this->config->get_cfg_value("copyPaste") == "true"){ + $this->CopyPasteHandler = new CopyPasteHandler($this->config); + } + + // Initialize the corresponding list class. + $this->DivListRoles = new divListRole($this->config,$this); + } + + + function execute() + { + // Call parent execute + plugin::execute(); + + /* Variables to restore after 'entry locked' warning was displayed */ + session::set('LOCK_VARS_TO_USE',array('/^role_/')); + + $smarty = get_smarty(); + $s_action = ""; + $s_entry = ""; + + /*************** + * Handle _POST/_GET variables + ***************/ + + // Get entry related posts + foreach($_POST as $name => $value){ + if(preg_match("/^role_edit_/",$name)){ + $s_action = "edit"; + $s_entry = preg_replace("/^role_edit_([0-9]*)_.*$/","\\1",$name); + break; + } + if(preg_match("/^role_del_/",$name)){ + $s_action = "del"; + $s_entry = preg_replace("/^role_del_([0-9]*)_.*$/","\\1",$name); + break; + } + } + if(isset($_GET['act']) && $_GET['act'] == "edit_entry" && isset($_GET['id'])){ + $id = $_GET['id']; + if(isset($this->roles[$id])){ + $s_action = "edit"; + $s_entry = $id; + } + } + + // Get menu related posts + if(isset($_POST['menu_action'])) { + if($_POST['menu_action'] == "role_new"){ + $s_action = "new"; + }elseif($_POST['menu_action'] == "remove_multiple_roles"){ + $s_action = "remove_multiple"; + } + } + + + /*************** + * New handling + ***************/ + + if($s_action == "new"){ + $this->dialog = new roletabs($this->config, $this->config->data['TABS']['ROLETABS'], "new"); + } + + /*************** + * Edit handling + ***************/ + + if($s_action == "edit"){ + if(!isset($this->roles[$s_entry])){ + trigger_error("Unknown entry!"); + }else{ + $entry = $this->roles[$s_entry]; + print_a($entry); + } + } + + /*************** + * Dialog handling + ***************/ + + if (isset($_POST['edit_cancel'])){ + if(isset($this->grouptab->dn)){ + $this->remove_lock(); + } + $this->dialog= NULL; + set_object_info(); + } + + if($this->dialog instanceOf tabs){ + $this->dialog->save_object(); + $display= $this->dialog->execute(); + + if($this->dialog->read_only == TRUE){ + $display.= "

+ +

"; + }else{ + + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

"; + } + return ($display); + } + + + /*************** + * List handling + ***************/ + + // Display dialog with group list + $this->DivListRoles->parent = $this; + $this->DivListRoles->execute(); + + // Add departments if subsearch is disabled + if(!$this->DivListRoles->SubSearch){ + $this->DivListRoles->AddDepartments($this->DivListRoles->selectedBase,4,1); + } + $this->reload (); + $this->DivListRoles->setEntries($this->roles); + return($this->DivListRoles->Draw()); + } + + + // Refreshes the list of known role objects. + function reload() + { + + // Get current ldap base and filter settings. + $base = $this->DivListRoles->selectedBase; + $Regex = $this->DivListRoles->Regex; + + // Search and fetch all matching role objects. + $this->roles = array(); + $ldap = $this->config->get_ldap_link(); + $ldap->search("(objectClass=gosaGroupOfNames)",array("cn","description")); + $tmp = array(); + while($attrs = $ldap->fetch()){ + $tmp[$attrs['cn'][0].$attrs['dn']] = $attrs; + } + + uksort($tmp, 'strnatcasecmp'); + $this->roles = array_values($tmp); + } + + + /* \brief Returns a list of selected entry ids. + * E.g. remove multiple entries. + * @return Array A list of entry IDs + */ + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + + function remove_lock() + { + } + + + /* Return departments, that will be included within snapshot detection + */ + function get_used_snapshot_bases() + { + return(array(get_ou('roleRDN').$this->DivListRoles->selectedBase)); + } + + + function save_object() + { + $this->DivListRoles->save_object(); + if(is_object($this->CopyPasteHandler)){ + $this->CopyPasteHandler->save_object(); + } + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/roleManagement/admin/roleManagement/main.inc b/gosa-plugins/roleManagement/admin/roleManagement/main.inc new file mode 100644 index 000000000..28c548c68 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/main.inc @@ -0,0 +1,67 @@ +remove_lock(); + } +} + +/* Remove this plugin from session +*/ +if ( $cleanup ){ + session::un_set('roleManagement'); +}else{ + + /* Create object object on demand */ + if (!session::is_set('roleManagement')){ + session::set('roleManagement',new roleManagement ($config)); + + } + $roleManagement = session::get('roleManagement'); + + /* Execute formular */ + $roleManagement->save_object(); + $output= $roleManagement->execute (); + + /* Page header*/ + if (get_object_info() != ""){ + $display= print_header(get_template_path('plugins/roleManagement/images/plugin.png'), + _("Roles"), + "\"\" ". + LDAP::fix(get_object_info())); + } else { + $display= print_header(get_template_path('plugins/roleManagement/images/plugin.png'), _("roleManagement")); + } + + $display.= $output; + + /* Store changes in session */ + session::set('roleManagement',$roleManagement); +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/roleManagement/admin/roleManagement/roleGeneric.tpl b/gosa-plugins/roleManagement/admin/roleManagement/roleGeneric.tpl new file mode 100644 index 000000000..45f95e2f0 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/roleGeneric.tpl @@ -0,0 +1,169 @@ + + {t}x121Address{/t}: + + {render acl=$x121AddressACL} + + {/render} + + + + {t}registeredAddress{/t}: + + {render acl=$registeredAddressACL} + + {/render} + + + + {t}destinationIndicator{/t}: + + {render acl=$destinationIndicatorACL} + + {/render} + + + + {t}preferredDeliveryMethod{/t}: + + {render acl=$preferredDeliveryMethodACL} + + {/render} + + + + {t}telexNumber{/t}: + + {render acl=$telexNumberACL} + + {/render} + + + + {t}teletexTerminalIdentifier{/t}: + + {render acl=$teletexTerminalIdentifierACL} + + {/render} + + + + {t}telephoneNumber{/t}: + + {render acl=$telephoneNumberACL} + + {/render} + + + + {t}internationaliSDNNumber{/t}: + + {render acl=$internationaliSDNNumberACL} + + {/render} + + + + {t}facsimileTelephoneNumber{/t}: + + {render acl=$facsimileTelephoneNumberACL} + + {/render} + + + + {t}seeAlso{/t}: + + {render acl=$seeAlsoACL} + + {/render} + + + + {t}roleOccupant{/t}: + + {render acl=$roleOccupantACL} + + {/render} + + + + {t}preferredDeliveryMethod{/t}: + + {render acl=$preferredDeliveryMethodACL} + + {/render} + + + + {t}street{/t}: + + {render acl=$streetACL} + + {/render} + + + + {t}postOfficeBox{/t}: + + {render acl=$postOfficeBoxACL} + + {/render} + + + + {t}postalCode{/t}: + + {render acl=$postalCodeACL} + + {/render} + + + + {t}postalAddress{/t}: + + {render acl=$postalAddressACL} + + {/render} + + + + {t}physicalDeliveryOfficeName{/t}: + + {render acl=$physicalDeliveryOfficeNameACL} + + {/render} + + + + {t}ou{/t}: + + {render acl=$ouACL} + + {/render} + + + + {t}st{/t}: + + {render acl=$stACL} + + {/render} + + + + {t}l{/t}: + + {render acl=$lACL} + + {/render} + + + + {t}description{/t}: + + {render acl=$descriptionACL} + + {/render} + + + diff --git a/gosa-plugins/roleManagement/admin/roleManagement/tabs_roles.inc b/gosa-plugins/roleManagement/admin/roleManagement/tabs_roles.inc new file mode 100644 index 000000000..fc660f0a2 --- /dev/null +++ b/gosa-plugins/roleManagement/admin/roleManagement/tabs_roles.inc @@ -0,0 +1,75 @@ +addSpecialTabs(); + } + + function save_object($save_current= FALSE) + { + tabs::save_object($save_current); + + /* Update reference, transfer variables */ + $baseobject= $this->by_object['roleGeneric']; + foreach ($this->by_object as $name => $obj){ + + /* Don't touch base object */ + if ($name != 'roleGeneric'){ + $obj->parent= &$this; + $obj->cn= $baseobject->cn; + $this->by_object[$name]= $obj; + } + } + } + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['roleGeneric']; + + /* Check for new 'dn', in order to propagate the + 'dn' to all plugins */ + $new_dn= 'cn='.$baseobject->cn.','.get_ou("roleRDN").$baseobject->base; + + /* Move group? */ + if ($this->dn != $new_dn){ + + /* Write entry on new 'dn' */ + if ($this->dn != "new"){ + $baseobject->update_acls($this->dn,$new_dn); + $baseobject->move($this->dn, $new_dn); + $this->by_object['roleGeneric']= $baseobject; + } + + /* Happen to use the new one */ + $this->dn= $new_dn; + } + $ret= tabs::save(); + return $ret; + } +} + +?> diff --git a/gosa-plugins/roleManagement/plugin.dsc b/gosa-plugins/roleManagement/plugin.dsc new file mode 100644 index 000000000..c48509600 --- /dev/null +++ b/gosa-plugins/roleManagement/plugin.dsc @@ -0,0 +1,7 @@ +[gosa-plugin] +name = roleManagement +description = "System management base plugin" +version = 2.6.4 +author = "Cajus Pollmeier " +homepage = https://oss.gonicus.de/labs/gosa/ +provides = roleManagement -- 2.30.2