Browse Source

- Add missing [wekan-ldap#40](https://github.com/wekan/wekan-ldap/pull/40) code about LDAP_SYNC_ADMIN_STATUS.

Thanks to JulianJacobi, n-st, chirrut2 and xet7 !

Closes #2351
Lauri Ojansivu 1 month ago
parent
commit
0fe40ad9ec
1 changed files with 18 additions and 0 deletions
  1. 18 0
      packages/wekan-ldap/server/loginHandler.js

+ 18 - 0
packages/wekan-ldap/server/loginHandler.js

@@ -179,6 +179,15 @@ Accounts.registerLoginHandler('ldap', function(loginRequest) {
       },
     };
 
+    if (LDAP.settings_get('LDAP_SYNC_ADMIN_STATUS') === true) {
+      log_debug('Updating admin status');
+      const targetGroups = LDAP.settings_get('LDAP_SYNC_ADMIN_GROUPS').split(',');
+      const groups = ldap.getUserGroups(username, ldapUser).filter((value) => targetGroups.includes(value));
+
+      user.isAdmin = groups.length > 0;
+      Meteor.users.update({_id: user._id}, {$set: {isAdmin: user.isAdmin}});
+    }
+
     if( LDAP.settings_get('LDAP_SYNC_GROUP_ROLES') === true ) {
       log_debug('Updating Groups/Roles');
       const groups = ldap.getUserGroups(username, ldapUser);
@@ -217,6 +226,15 @@ Accounts.registerLoginHandler('ldap', function(loginRequest) {
 
   const result = addLdapUser(ldapUser, username, loginRequest.ldapPass);
 
+  if (LDAP.settings_get('LDAP_SYNC_ADMIN_STATUS') === true) {
+    log_debug('Updating admin status');
+    const targetGroups = LDAP.settings_get('LDAP_SYNC_ADMIN_GROUPS').split(',');
+    const groups = ldap.getUserGroups(username, ldapUser).filter((value) => targetGroups.includes(value));
+
+    result.isAdmin = groups.length > 0;
+    Meteor.users.update({_id: result.userId}, {$set: {isAdmin: result.isAdmin}});
+  }
+
   if( LDAP.settings_get('LDAP_SYNC_GROUP_ROLES') === true ) {
     const groups = ldap.getUserGroups(username, ldapUser);
     if( groups.length > 0 ) {