Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possibility to add specific group list to config #12

Open
fschuett opened this issue Jul 20, 2020 · 0 comments
Open

possibility to add specific group list to config #12

fschuett opened this issue Jul 20, 2020 · 0 comments

Comments

@fschuett
Copy link

fschuett commented Jul 20, 2020

Hallo,
I have a special problem, I want to use your module to sync only some specific moodle cohorts but not all cohorts found in ldap.
So I added a patch to optionally create a list of groups, which is then used as a filter for ldap_get_grouplist. If you find this option useful, please add it to the code, maybe others could use this filter, too.

I attach the patch to this post.

..diff -up moodle/local/ldap/locallib.php.orig moodle/local/ldap/locallib.php
..--- moodle/local/ldap/locallib.php.orig 2020-07-20 09:53:01.373282357 +0200
..+++ moodle/local/ldap/locallib.php 2020-07-20 10:15:22.966568914 +0200
..@@ -66,6 +66,7 @@ class local_ldap extends auth_plugin_lda
..
.. // Get my specific settings.
.. $extra = get_config('local_ldap');
..+ $this->merge_config($extra, 'group_list','');
.. $this->merge_config($extra, 'group_attribute', 'cn');
.. $this->merge_config($extra, 'group_class', 'groupOfNames');
.. $this->merge_config($extra, 'process_nested_groups', 0);
..@@ -675,7 +676,14 @@ class local_ldap extends auth_plugin_lda
.. public function sync_cohorts_by_group() {
.. global $DB;
..
..- $ldapgroups = $this->ldap_get_grouplist();
..+ $grouplist = $this->config->group_list;
..+ if (! empty($grouplist) && $grouplist != "") {
..+ $filter = "&(" . $this->config->group_attribute . "=)(objectclass=" . $this->config->group_class . ")";
..+ $groupfilter = $filter . "(|(cn=".implode(")(cn=",explode(",",$grouplist))."))";
..+ $ldapgroups = $this->ldap_get_grouplist("(".$groupfilter.")");
..+ } else {
..+ $ldapgroups = $this->ldap_get_grouplist();
..+ }
.. foreach ($ldapgroups as $groupname) {
.. if (!$cohort = $DB->get_record('cohort', array('idnumber' => $groupname), '
')) {
.. if (empty($this->config->cohort_synching_ldap_groups_autocreate_cohorts)) {
..diff -up moodle/local/ldap/settings.php.orig moodle/local/ldap/settings.php
..--- moodle/local/ldap/settings.php.orig 2020-06-15 17:07:02.000000000 +0200
..+++ moodle/local/ldap/settings.php 2020-07-20 10:01:48.490646460 +0200
..@@ -27,6 +27,12 @@ defined('MOODLE_INTERNAL') || die;
.. if ($hassiteconfig) {
.. $settings = new admin_settingpage('local_ldap', get_string('pluginname', 'local_ldap'));
..
..+ $name = 'group_list';
..+ $title = 'Group list';
..+ $description = 'Comma separated list of groups to synchronize';
..+ $setting = new admin_setting_configtext('local_ldap/'.$name, $title, $description, '');
..+ $settings->add($setting);
..+
.. $settings->add(new admin_setting_heading('synccohortgroup',
.. get_string('synccohortgroup', 'local_ldap'),
.. get_string('synccohortgroup_info', 'local_ldap')));
..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant