summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-10-28 23:04:03 +0100
committerArthur Schiwon <blizzz@owncloud.com>2014-11-20 18:31:39 +0100
commit71944a59a5279b34b57aa68c5b7ad0173e4a6793 (patch)
tree48e2e140c87fc5dc03300784476e78c3ad4bcd39 /apps/user_ldap
parentf725cc66a385311d9995ec4215f57448b59f124e (diff)
downloadnextcloud-server-71944a59a5279b34b57aa68c5b7ad0173e4a6793.tar.gz
nextcloud-server-71944a59a5279b34b57aa68c5b7ad0173e4a6793.zip
detectors (email, displayname..) are now started in one place, triggered from only 2 places. more reliable structure and flow, saves requests
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/js/ldapFilter.js41
-rw-r--r--apps/user_ldap/js/settings.js73
-rw-r--r--apps/user_ldap/lib/wizard.php1
3 files changed, 81 insertions, 34 deletions
diff --git a/apps/user_ldap/js/ldapFilter.js b/apps/user_ldap/js/ldapFilter.js
index bb66c1df2ee..2bb62ad1a9a 100644
--- a/apps/user_ldap/js/ldapFilter.js
+++ b/apps/user_ldap/js/ldapFilter.js
@@ -25,7 +25,7 @@ LdapFilter.prototype.activate = function() {
this.determineMode();
};
-LdapFilter.prototype.compose = function(callback) {
+LdapFilter.prototype.compose = function() {
var action;
if(this.locked) {
@@ -54,14 +54,7 @@ LdapFilter.prototype.compose = function(callback) {
LdapWizard.ajax(param,
function(result) {
- LdapWizard.applyChanges(result);
- filter.updateCount();
- if(filter.target === 'Group') {
- LdapWizard.detectGroupMemberAssoc();
- }
- if(typeof callback !== 'undefined') {
- callback();
- }
+ filter.afterComposeSuccess(result);
},
function () {
console.log('LDAP Wizard: could not compose filter. '+
@@ -70,6 +63,15 @@ LdapFilter.prototype.compose = function(callback) {
);
};
+LdapFilter.prototype.afterDetectorsRan = function() {
+ this.updateCount();
+};
+
+LdapFilter.prototype.afterComposeSuccess = function(result) {
+ LdapWizard.applyChanges(result);
+ LdapWizard.runDetectors(this.target, this.afterDetectorsRan);
+};
+
LdapFilter.prototype.determineMode = function() {
var param = 'action=get'+encodeURIComponent(this.target)+'FilterMode'+
'&ldap_serverconfig_chooser='+
@@ -145,10 +147,21 @@ LdapFilter.prototype.findFeatures = function() {
}
};
+LdapFilter.prototype.beforeUpdateCount = function(status) {
+ return LdapWizard.runDetectors(this.target, function() {
+ status.resolve();
+ });
+};
+
LdapFilter.prototype.updateCount = function(doneCallback) {
- if(this.target === 'User') {
- LdapWizard.countUsers(doneCallback);
- } else if (this.target === 'Group') {
- LdapWizard.countGroups(doneCallback);
- }
+ var beforeUpdateCountDone = $.Deferred();
+ this.beforeUpdateCount(beforeUpdateCountDone);
+ var filter = this;
+ $.when(beforeUpdateCountDone).done(function() {
+ if(filter.target === 'User') {
+ LdapWizard.countUsers(doneCallback);
+ } else if (filter.target === 'Group') {
+ LdapWizard.countGroups(doneCallback);
+ }
+ });
};
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 93fd97c1e73..f8cb3d84cea 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -172,6 +172,7 @@ var LdapWizard = {
if(typeof reqID !== 'undefined') {
LdapWizard.ajaxRequests[reqID] = request;
}
+ return request;
},
applyChanges: function (result) {
@@ -373,20 +374,44 @@ var LdapWizard = {
},
countUsers: function(doneCallback) {
- //we make user counting depending on having a display name attribute
+ LdapWizard._countThings('countUsers', '#ldap_user_count', doneCallback);
+ },
+
+ runDetectors: function(type, callback) {
+ if(type === 'Group') {
+ $.when(LdapWizard.detectGroupMemberAssoc())
+ .then(callback, callback);
+ if( LdapWizard.admin.isExperienced
+ && !(LdapWizard.detectorsRunInXPMode & LdapWizard.groupDetectors)) {
+ LdapWizard.detectorsRunInXPMode += LdapWizard.groupDetectors;
+ }
+ } else if(type === 'User') {
+ var req1 = LdapWizard.detectUserDisplayNameAttribute();
+ var req2 = LdapWizard.detectEmailAttribute();
+ $.when(req1, req2)
+ .then(callback, callback);
+ if( LdapWizard.admin.isExperienced
+ && !(LdapWizard.detectorsRunInXPMode & LdapWizard.userDetectors)) {
+ LdapWizard.detectorsRunInXPMode += LdapWizard.userDetectors;
+ }
+ }
+ },
+
+ detectUserDisplayNameAttribute: function() {
var param = 'action=detectUserDisplayNameAttribute' +
'&ldap_serverconfig_chooser='+
encodeURIComponent($('#ldap_serverconfig_chooser').val());
- LdapWizard._countThings('countUsers', '#ldap_user_count', doneCallback);
+ //runs in the background, no callbacks necessary
+ return LdapWizard.ajax(param, LdapWizard.applyChanges, function(){}, 'detectUserDisplayNameAttribute');
},
detectEmailAttribute: function() {
- param = 'action=detectEmailAttribute'+
+ var param = 'action=detectEmailAttribute'+
'&ldap_serverconfig_chooser='+
encodeURIComponent($('#ldap_serverconfig_chooser').val());
//runs in the background, no callbacks necessary
- LdapWizard.ajax(param, LdapWizard.applyChanges, function(){}, 'detectEmailAttribute');
+ return LdapWizard.ajax(param, LdapWizard.applyChanges, function(){}, 'detectEmailAttribute');
},
detectGroupMemberAssoc: function() {
@@ -394,7 +419,7 @@ var LdapWizard = {
'&ldap_serverconfig_chooser='+
encodeURIComponent($('#ldap_serverconfig_chooser').val());
- LdapWizard.ajax(param,
+ return LdapWizard.ajax(param,
function(result) {
//pure background story
},
@@ -416,7 +441,7 @@ var LdapWizard = {
$('#ldap_loginfilter_attributes').find('option').remove();
for (var i in result.options['ldap_loginfilter_attributes']) {
//FIXME: move HTML into template
- attr = result.options['ldap_loginfilter_attributes'][i];
+ var attr = result.options['ldap_loginfilter_attributes'][i];
$('#ldap_loginfilter_attributes').append(
"<option value='"+attr+"'>"+attr+"</option>");
}
@@ -573,8 +598,12 @@ var LdapWizard = {
},
isConfigurationActiveControlLocked: true,
+ detectorsRunInXPMode: 0,
+ userDetectors: 1,
+ groupDetectors: 2,
init: function() {
+ LdapWizard.detectorsRunInXPMode = 0;
LdapWizard.instantiateFilters();
LdapWizard.admin.setExperienced($('#ldap_experienced_admin').is(':checked'));
LdapWizard.basicStatusCheck();
@@ -637,7 +666,6 @@ var LdapWizard = {
$('#ldap_user_count').text('');
LdapWizard.showSpinner('#rawUserFilterContainer .ldapGetEntryCount');
LdapWizard.userFilter.updateCount(LdapWizard.hideTestSpinner);
- LdapWizard.detectEmailAttribute();
$('#ldap_user_count').removeClass('hidden');
});
@@ -658,7 +686,6 @@ var LdapWizard = {
$('#ldap_group_count').text('');
LdapWizard.showSpinner('#rawGroupFilterContainer .ldapGetEntryCount');
LdapWizard.groupFilter.updateCount(LdapWizard.hideTestSpinner);
- LdapWizard.detectGroupMemberAssoc();
$('#ldap_group_count').removeClass('hidden');
});
},
@@ -675,7 +702,7 @@ var LdapWizard = {
postInitUserFilter: function() {
if(LdapWizard.userFilterObjectClassesHasRun &&
LdapWizard.userFilterAvailableGroupsHasRun) {
- LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute);
+ LdapWizard.userFilter.compose();
}
},
@@ -686,7 +713,7 @@ var LdapWizard = {
//do not allow to switch tabs as long as a save process is active
return false;
}
- newTabIndex = 0;
+ var newTabIndex = 0;
if(ui.newTab[0].id === '#ldapWizard2') {
LdapWizard.initUserFilter();
newTabIndex = 1;
@@ -698,9 +725,23 @@ var LdapWizard = {
newTabIndex = 3;
}
- curTabIndex = $('#ldapSettings').tabs('option', 'active');
+ var curTabIndex = $('#ldapSettings').tabs('option', 'active');
if(curTabIndex >= 0 && curTabIndex <= 3) {
LdapWizard.controlUpdate(newTabIndex);
+ //run detectors in XP mode, when "Test Filter" button has not been
+ //clicked in order to make sure that email, displayname, member-
+ //group association attributes are properly set.
+ if( curTabIndex === 1
+ && LdapWizard.admin.isExperienced
+ && !(LdapWizard.detecorsRunInXPMode & LdapWizard.userDetectors)
+ ) {
+ LdapWizard.runDetectors('User', function(){});
+ } else if( curTabIndex === 3
+ && LdapWizard.admin.isExperienced
+ && !(LdapWizard.detecorsRunInXPMode & LdapWizard.groupDetectors)
+ ) {
+ LdapWizard.runDetectors('Group', function(){});
+ }
}
},
@@ -718,12 +759,6 @@ var LdapWizard = {
}
}
- if(triggerObj.id === 'ldap_userlist_filter' && !LdapWizard.admin.isExperienced()) {
- LdapWizard.detectEmailAttribute();
- } else if(triggerObj.id === 'ldap_group_filter' && !LdapWizard.admin.isExperienced()) {
- LdapWizard.detectGroupMemberAssoc();
- }
-
if(triggerObj.id === 'ldap_loginfilter_username'
|| triggerObj.id === 'ldap_loginfilter_email') {
LdapWizard.loginFilter.compose();
@@ -756,7 +791,7 @@ var LdapWizard = {
LdapWizard._save($('#'+originalObj)[0], $.trim(values));
if(originalObj === 'ldap_userfilter_objectclass'
|| originalObj === 'ldap_userfilter_groups') {
- LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute);
+ LdapWizard.userFilter.compose();
//when user filter is changed afterwards, login filter needs to
//be adjusted, too
if(!LdapWizard.loginFilter) {
@@ -837,7 +872,7 @@ var LdapWizard = {
LdapWizard._save({ id: modeKey }, LdapWizard.filterModeAssisted);
if(isUser) {
LdapWizard.blacklistRemove('ldap_userlist_filter');
- LdapWizard.userFilter.compose(LdapWizard.detectEmailAttribute);
+ LdapWizard.userFilter.compose();
} else {
LdapWizard.blacklistRemove('ldap_group_filter');
LdapWizard.groupFilter.compose();
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index f373fabb69c..59911fe77d1 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -120,7 +120,6 @@ class Wizard extends LDAPUtility {
* @throws \Exception
*/
public function countUsers() {
- $this->detectUserDisplayNameAttribute();
$filter = $this->access->getFilterForUserCount();
$usersTotal = $this->countEntries($filter, 'users');