Browse Source

Fix bug regarding non admin users who have an email on a given domain name (field in Admin panel settings) and that can't invite new users for a registration

Emile NDAGIJIMANA 3 năm trước cách đây
mục cha
commit
2f69501c14
1 tập tin đã thay đổi với 15 bổ sung1 xóa
  1. 15 1
      models/settings.js

+ 15 - 1
models/settings.js

@@ -274,6 +274,20 @@ if (Meteor.isServer) {
     }
   }
 
+  function isNonAdminAllowedToSendMail(currentUser){
+    const currSett = Settings.findOne({});
+    let isAllowed = false;
+    if(currSett && currSett != undefined && currSett.disableRegistration && currSett.mailDomainName !== undefined && currSett.mailDomainName != ""){
+      for(let i = 0; i < currentUser.emails.length; i++) {
+        if(currentUser.emails[i].address.endsWith(currSett.mailDomainName)){
+          isAllowed = true;
+          break;
+        }
+      }
+    }
+    return isAllowed;
+  }
+
   function isLdapEnabled() {
     return (
       process.env.LDAP_ENABLE === 'true' || process.env.LDAP_ENABLE === true
@@ -304,7 +318,7 @@ if (Meteor.isServer) {
       check(boards, [String]);
 
       const user = Users.findOne(Meteor.userId());
-      if (!user.isAdmin) {
+      if (!user.isAdmin && !isNonAdminAllowedToSendMail(user)) {
         rc = -1;
         throw new Meteor.Error('not-allowed');
       }