summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorblizzz <blizzz@owncloud.com>2014-04-23 11:09:35 +0200
committerblizzz <blizzz@owncloud.com>2014-04-23 11:09:35 +0200
commit97f21712cda12bdcd52994ace627dc9c35a26f5a (patch)
tree48c4a516c069529802f256726e8908b38bedb2fe /apps/user_ldap
parent032f38b23087a0f85830398da477db99a65c32db (diff)
parente0cac32442af1986d2a202ec708fce8d537bb12c (diff)
downloadnextcloud-server-97f21712cda12bdcd52994ace627dc9c35a26f5a.tar.gz
nextcloud-server-97f21712cda12bdcd52994ace627dc9c35a26f5a.zip
Merge pull request #8164 from owncloud/fix-6651
LDAP: fix random resets of filter
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/js/ldapFilter.js100
-rw-r--r--apps/user_ldap/js/settings.js100
-rw-r--r--apps/user_ldap/settings.php1
3 files changed, 122 insertions, 79 deletions
diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js
new file mode 100644
index 00000000000..df3bd67aec2
--- /dev/null
+++ b/apps/user_ldap/js/ldapFilter.js
@@ -0,0 +1,100 @@
+/* global LdapWizard */
+
+function LdapFilter(target) {
+ this.locked = true;
+ this.target = false;
+ this.mode = LdapWizard.filterModeAssisted;
+ this.lazyRunCompose = false;
+
+ if( target === 'User' ||
+ target === 'Login' ||
+ target === 'Group') {
+ this.target = target;
+ this.determineMode();
+ }
+}
+
+LdapFilter.prototype.compose = function() {
+ var action;
+
+ if(this.locked) {
+ this.lazyRunCompose = true;
+ return false;
+ }
+
+ if(this.target === 'User') {
+ action = 'getUserListFilter';
+ } else if(this.target === 'Login') {
+ action = 'getUserLoginFilter';
+ } else if(this.target === 'Group') {
+ action = 'getGroupFilter';
+ }
+
+ if(!$('#raw'+this.target+'FilterContainer').hasClass('invisible')) {
+ //Raw filter editing, i.e. user defined filter, don't compose
+ return;
+ }
+
+ var param = 'action='+action+
+ '&ldap_serverconfig_chooser='+
+ encodeURIComponent($('#ldap_serverconfig_chooser').val());
+
+ var filter = this;
+
+ LdapWizard.ajax(param,
+ function(result) {
+ LdapWizard.applyChanges(result);
+ if(filter.target === 'User') {
+ LdapWizard.countUsers();
+ } else if(filter.target === 'Group') {
+ LdapWizard.countGroups();
+ LdapWizard.detectGroupMemberAssoc();
+ }
+ },
+ function () {
+ console.log('LDAP Wizard: could not compose filter. '+
+ 'Please check owncloud.log');
+ }
+ );
+};
+
+LdapFilter.prototype.determineMode = function() {
+ var param = 'action=get'+encodeURIComponent(this.target)+'FilterMode'+
+ '&ldap_serverconfig_chooser='+
+ encodeURIComponent($('#ldap_serverconfig_chooser').val());
+
+ var filter = this;
+ LdapWizard.ajax(param,
+ function(result) {
+ var property = 'ldap' + filter.target + 'FilterMode';
+ filter.mode = parseInt(result.changes[property], 10);
+ if(filter.mode === LdapWizard.filterModeRaw &&
+ $('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+ LdapWizard['toggleRaw'+filter.target+'Filter']();
+ } else if(filter.mode === LdapWizard.filterModeAssisted &&
+ !$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+ LdapWizard['toggleRaw'+filter.target+'Filter']();
+ } else {
+ console.log('LDAP Wizard determineMode: returned mode was »' +
+ filter.mode + '« of type ' + typeof filter.mode);
+ }
+ filter.unlock();
+ },
+ function () {
+ //on error case get back to default i.e. Assisted
+ if(!$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+ LdapWizard['toggleRaw'+filter.target+'Filter']();
+ filter.mode = LdapWizard.filterModeAssisted;
+ }
+ filter.unlock();
+ }
+ );
+};
+
+LdapFilter.prototype.unlock = function() {
+ this.locked = false;
+ if(this.lazyRunCompose) {
+ this.lazyRunCompose = false;
+ this.compose();
+ }
+};
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 792638f2b58..fca2dc13d15 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -14,7 +14,7 @@ var LdapConfiguration = {
//deal with Checkboxes
if($(elementID).is('input[type=checkbox]')) {
- if(parseInt(configvalue) === 1) {
+ if(parseInt(configvalue, 10) === 1) {
$(elementID).attr('checked', 'checked');
} else {
$(elementID).removeAttr('checked');
@@ -145,6 +145,9 @@ var LdapWizard = {
spinner: '<img class="wizSpinner" src="'+ OC.imagePath('core', 'loading.gif') +'">',
filterModeAssisted: 0,
filterModeRaw: 1,
+ userFilter: false,
+ loginFilter: false,
+ groupFilter: false,
ajax: function(param, fnOnSuccess, fnOnError) {
$.post(
@@ -276,41 +279,6 @@ var LdapWizard = {
}
},
- composeFilter: function(type) {
- subject = type.charAt(0).toUpperCase() + type.substr(1);
- if(!$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
- //Raw filter editing, i.e. user defined filter, don't compose
- return;
- }
-
- if(type == 'user') {
- action = 'getUserListFilter';
- } else if(type == 'login') {
- action = 'getUserLoginFilter';
- } else if(type == 'group') {
- action = 'getGroupFilter';
- }
-
- param = 'action='+action+
- '&ldap_serverconfig_chooser='+
- encodeURIComponent($('#ldap_serverconfig_chooser').val());
-
- LdapWizard.ajax(param,
- function(result) {
- LdapWizard.applyChanges(result);
- if(type == 'user') {
- LdapWizard.countUsers();
- } else if(type == 'group') {
- LdapWizard.countGroups();
- LdapWizard.detectGroupMemberAssoc();
- }
- },
- function (result) {
- // error handling
- }
- );
- },
-
controlBack: function() {
curTabIndex = $('#ldapSettings').tabs('option', 'active');
if(curTabIndex == 0) {
@@ -510,7 +478,7 @@ var LdapWizard = {
},
functionalityCheck: function() {
- //criterias to enable the connection:
+ //criteria to enable the connection:
// - host, port, basedn, user filter, login filter
host = $('#ldap_host').val();
port = $('#ldap_port').val();
@@ -560,7 +528,7 @@ var LdapWizard = {
},
initGroupFilter: function() {
- LdapWizard.regardFilterMode('Group');
+ LdapWizard.groupFilter = new LdapFilter('Group');
LdapWizard.findObjectClasses('ldap_groupfilter_objectclass', 'Group');
LdapWizard.findAvailableGroups('ldap_groupfilter_groups', 'Groups');
LdapWizard.countGroups();
@@ -569,13 +537,13 @@ var LdapWizard = {
/** init login filter tab section **/
initLoginFilter: function() {
- LdapWizard.regardFilterMode('Login');
+ LdapWizard.loginFilter = new LdapFilter('Login');
LdapWizard.findAttributes();
},
postInitLoginFilter: function() {
if($('#rawLoginFilterContainer').hasClass('invisible')) {
- LdapWizard.composeFilter('login');
+ LdapWizard.loginFilter.compose();
}
},
@@ -588,7 +556,7 @@ var LdapWizard = {
noneSelectedText: caption,
click: function(event, ui) {
LdapWizard.saveMultiSelect(id,
- $('#'+id).multiselect("getChecked"));
+ $('#'+id).multiselect("getChecked"));
}
});
},
@@ -601,15 +569,15 @@ var LdapWizard = {
initUserFilter: function() {
LdapWizard.userFilterObjectClassesHasRun = false;
LdapWizard.userFilterAvailableGroupsHasRun = false;
- LdapWizard.regardFilterMode('User');
+ LdapWizard.userFilter = new LdapFilter('User');
LdapWizard.findObjectClasses('ldap_userfilter_objectclass', 'User');
LdapWizard.findAvailableGroups('ldap_userfilter_groups', 'Users');
},
postInitUserFilter: function() {
- if(LdapWizard.userFilterObjectClassesHasRun
- && LdapWizard.userFilterAvailableGroupsHasRun) {
- LdapWizard.composeFilter('user');
+ if(LdapWizard.userFilterObjectClassesHasRun &&
+ LdapWizard.userFilterAvailableGroupsHasRun) {
+ LdapWizard.userFilter.compose();
LdapWizard.countUsers();
}
},
@@ -658,7 +626,7 @@ var LdapWizard = {
if(triggerObj.id == 'ldap_loginfilter_username'
|| triggerObj.id == 'ldap_loginfilter_email') {
- LdapWizard.composeFilter('login');
+ LdapWizard.loginFilter.compose();
}
if($('#ldapSettings').tabs('option', 'active') == 0) {
@@ -667,32 +635,6 @@ var LdapWizard = {
}
},
- regardFilterMode: function(subject) {
- param = 'action=get'+encodeURIComponent(subject)+'FilterMode'+
- '&ldap_serverconfig_chooser='+
- encodeURIComponent($('#ldap_serverconfig_chooser').val());
-
- LdapWizard.ajax(param,
- function(result) {
- property = 'ldap' + subject + 'FilterMode';
- mode = result.changes[property];
- if(mode == LdapWizard.filterModeRaw
- && $('#raw'+subject+'FilterContainer').hasClass('invisible')) {
- LdapWizard['toggleRaw'+subject+'Filter']();
- } else if(mode == LdapWizard.filterModeAssisted
- && !$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
- LdapWizard['toggleRaw'+subject+'Filter']();
- }
- },
- function (result) {
- //on error case get back to default i.e. Assisted
- if(!$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
- LdapWizard['toggleRaw'+subject+'Filter']();
- }
- }
- );
- },
-
save: function(inputObj) {
if(LdapWizard.blacklistRemove(inputObj.id)) {
return;
@@ -714,15 +656,15 @@ var LdapWizard = {
LdapWizard._save($('#'+originalObj)[0], $.trim(values));
if(originalObj == 'ldap_userfilter_objectclass'
|| originalObj == 'ldap_userfilter_groups') {
- LdapWizard.composeFilter('user');
+ LdapWizard.userFilter.compose();
//when user filter is changed afterwards, login filter needs to
//be adjusted, too
- LdapWizard.composeFilter('login');
+ LdapWizard.loginFilter.compose();
} else if(originalObj == 'ldap_loginfilter_attributes') {
- LdapWizard.composeFilter('login');
+ LdapWizard.loginFilter.compose();
} else if(originalObj == 'ldap_groupfilter_objectclass'
|| originalObj == 'ldap_groupfilter_groups') {
- LdapWizard.composeFilter('group');
+ LdapWizard.groupFilter.compose();
}
},
@@ -778,10 +720,10 @@ var LdapWizard = {
LdapWizard._save({ id: modeKey }, LdapWizard.filterModeAssisted);
if(moc.indexOf('user') >= 0) {
LdapWizard.blacklistRemove('ldap_userlist_filter');
- LdapWizard.composeFilter('user');
+ LdapWizard.userFilter.compose();
} else {
LdapWizard.blacklistRemove('ldap_group_filter');
- LdapWizard.composeFilter('group');
+ LdapWizard.groupFilter.compose();
}
}
},
@@ -815,7 +757,7 @@ var LdapWizard = {
$('#ldap_loginfilter_username').prop('disabled', property);
LdapWizard._save({ id: 'ldapLoginFilterMode' }, mode);
if(action == 'enable') {
- LdapWizard.composeFilter('login');
+ LdapWizard.loginFilter.compose();
}
},
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index d077eafdde9..6b7d8e6f53e 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -25,6 +25,7 @@
OC_Util::checkAdminUser();
+OCP\Util::addScript('user_ldap', 'ldapFilter');
OCP\Util::addScript('user_ldap', 'settings');
OCP\Util::addScript('core', 'jquery.multiselect');
OCP\Util::addStyle('user_ldap', 'settings');