Commit 1750dd4f authored by Son Nguyen's avatar Son Nguyen
Browse files

Fix only first group is processed in include list (Bug 1278013)

The change from Patric
(https://github.com/patrickpollet/mahara_ldap_sync/commit/13c3d419f2e9b9336297ae9a69d9e414af542a48

)
has been ported

Fix the warning 'sendnow' is not defined
Allow spaces in the list of group names, e.g "users, teachers ,  tutors"

Change-Id: I31b13a44679442d58c2be80dffd828d90c60227f
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent bb8ed7e0
......@@ -98,7 +98,7 @@ class AuthLdap extends Auth {
);
foreach ($lists as $listkey) {
if (isset($this->config[$listkey]) && !is_array($this->config[$listkey]) && $this->config[$listkey] !== '') {
$this->config[$listkey] = explode(',', $this->config[$listkey]);
$this->config[$listkey] = preg_split('/\s*,\s*/', trim($this->config[$listkey]));
}
}
......@@ -1405,31 +1405,12 @@ class AuthLdap extends Auth {
$nbadded = 0;
foreach ($groups as $group) {
$nomatch = false;
log_debug("Processing group '{$group}'");
// Check whether we should skip this group
if (!empty($includelist)) {
foreach ($includelist as $regexp) {
if (empty($regexp)) {
continue;
}
if (!filter_var($group, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => '/' . $regexp . '/')))) {
log_debug($group . " skipped because not in include list \n");
continue 2;
}
}
}
if (!empty($excludelist)) {
foreach ($excludelist as $regexp) {
if (empty($regexp)) {
continue;
}
if (filter_var($group, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => '/' . $regexp . '/')))) {
log_debug($group . " skipped because in exclude list \n");
continue 2;
}
}
if (!ldap_sync_filter_name($group, $includelist, $excludelist)) {
continue;
}
if (get_config('auth_ldap_debug_sync_cron')) {
......@@ -2181,13 +2162,13 @@ function auth_ldap_sync_groups(
$instance->set_config('syncgroupsbyuserfield', $syncbyattribute);
if ($excludelist !== null) {
if (!is_array($excludelist)) {
$excludelist = explode(',', $excludelist);
$excludelist = preg_split('/\s*,\s*/', trim($excludelist));
}
$instance->set_config('syncgroupsexcludelist', $excludelist);
}
if ($includelist !== null) {
if (!is_array($includelist)) {
$includelist = explode(',', $includelist);
$includelist = preg_split('/\s*,\s*/', trim($includelist));
}
$instance->set_config('syncgroupsincludelist', $includelist);
}
......@@ -2218,3 +2199,46 @@ function auth_ldap_sync_groups(
log_info('---------- finished institution group sync at ' . date('r', time()) . ' ----------');
return $result;
}
/**
*
* Filter an LDAP group name against two arrays of regular expressions
* @param string $name
* @param array of string $includes
* @param array of string $excludes
* @return boolean
* revised 11/02/2013 see https://mahara.org/interaction/forum/topic.php?id=6082&offset=0&limit=10#post25989
* ported to mahara core 24 Mar 2014
*/
function ldap_sync_filter_name($name, $includes, $excludes) {
if (!empty($includes)) {
$found = false;
foreach ($includes as $regexp) {
if (empty($regexp)) {
continue;
}
if (filter_var($name, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => '/' . $regexp . '/')))) {
$found = true;
log_debug($name . " processed because in include list \n");
break; // match found in include list go check for exclude
}
}
if (!$found) {
log_debug($name . " skipped because not in include list \n");
return false;
}
}
if (!empty($excludes)) {
foreach ($excludes as $regexp) {
if (empty($regexp)) {
continue;
}
if (filter_var($name, FILTER_VALIDATE_REGEXP, array("options" => array('regexp' => '/' . $regexp . '/')))) {
log_debug($name . " skipped because in exclude list \n");
return false;
}
}
}
return true;
}
......@@ -435,7 +435,7 @@ function group_create($data) {
'suggestfriends' => $data['suggestfriends'],
'editwindowstart' => $data['editwindowstart'],
'editwindowend' => $data['editwindowend'],
'sendnow' => $data['sendnow'],
'sendnow' => isset($data['sendnow']) ? $data['sendnow'] : null,
),
'id',
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