RocketChat/Rocket.Chat

View on GitHub
apps/meteor/ee/server/lib/ldap/Manager.ts

Summary

Maintainability
F
6 days
Test Coverage

File Manager.ts has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Team } from '@rocket.chat/core-services';
import type { ILDAPEntry, IUser, IRoom, IRole, IImportUser, IImportRecord } from '@rocket.chat/core-typings';
import { Users, Roles, Subscriptions as SubscriptionsRaw, Rooms } from '@rocket.chat/models';
import type ldapjs from 'ldapjs';

Severity: Major
Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 day to fix

    Function syncUserChannels has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        private static async syncUserChannels(ldap: LDAPConnection, user: IUser, dn: string): Promise<void> {
            const syncUserChannels = settings.get<boolean>('LDAP_Sync_User_Data_Channels') ?? false;
            const syncUserChannelsRemove = settings.get<boolean>('LDAP_Sync_User_Data_Channels_Enforce_AutoChannels') ?? false;
            const syncUserChannelsFieldMap = (settings.get<string>('LDAP_Sync_User_Data_ChannelsMap') ?? '').trim();
            const syncUserChannelsFilter = (settings.get<string>('LDAP_Sync_User_Data_Channels_Filter') ?? '').trim();
    Severity: Minor
    Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function syncUserRoles has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        private static async syncUserRoles(ldap: LDAPConnection, user: IUser, dn: string): Promise<void> {
            const { username } = user;
            if (!username) {
                logger.debug('User has no username');
                return;
    Severity: Minor
    Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function syncUserChannels has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static async syncUserChannels(ldap: LDAPConnection, user: IUser, dn: string): Promise<void> {
            const syncUserChannels = settings.get<boolean>('LDAP_Sync_User_Data_Channels') ?? false;
            const syncUserChannelsRemove = settings.get<boolean>('LDAP_Sync_User_Data_Channels_Enforce_AutoChannels') ?? false;
            const syncUserChannelsFieldMap = (settings.get<string>('LDAP_Sync_User_Data_ChannelsMap') ?? '').trim();
            const syncUserChannelsFilter = (settings.get<string>('LDAP_Sync_User_Data_Channels_Filter') ?? '').trim();
    Severity: Major
    Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 2 hrs to fix

      LDAPEEManager has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class LDAPEEManager extends LDAPManager {
          public static async sync(): Promise<void> {
              if (settings.get('LDAP_Enable') !== true || settings.get('LDAP_Background_Sync') !== true) {
                  return;
              }
      Severity: Minor
      Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 2 hrs to fix

        Function syncUserRoles has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static async syncUserRoles(ldap: LDAPConnection, user: IUser, dn: string): Promise<void> {
                const { username } = user;
                if (!username) {
                    logger.debug('User has no username');
                    return;
        Severity: Major
        Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 2 hrs to fix

          Function sync has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static async sync(): Promise<void> {
                  if (settings.get('LDAP_Enable') !== true || settings.get('LDAP_Background_Sync') !== true) {
                      return;
                  }
          
          
          Severity: Minor
          Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

            Function sync has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                public static async sync(): Promise<void> {
                    if (settings.get('LDAP_Enable') !== true || settings.get('LDAP_Background_Sync') !== true) {
                        return;
                    }
            
            
            Severity: Minor
            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function isUserDeactivated has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                private static isUserDeactivated(ldapUser: ILDAPEntry): boolean {
                    // Account locked by "Draft-behera-ldap-password-policy"
                    if (ldapUser.pwdAccountLockedTime) {
                        mapLogger.debug('User account is locked by password policy (attribute pwdAccountLockedTime)');
                        return true;
            Severity: Minor
            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function syncUserTeams has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static async syncUserTeams(ldap: LDAPConnection, user: IUser, dn: string, isNewRecord: boolean): Promise<void> {
                    if (!user.username) {
                        return;
                    }
            
            
            Severity: Minor
            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

              Function isUserDeactivated has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private static isUserDeactivated(ldapUser: ILDAPEntry): boolean {
                      // Account locked by "Draft-behera-ldap-password-policy"
                      if (ldapUser.pwdAccountLockedTime) {
                          mapLogger.debug('User account is locked by password policy (attribute pwdAccountLockedTime)');
                          return true;
              Severity: Minor
              Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

                Function getLdapTeamsByUsername has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static async getLdapTeamsByUsername(ldap: LDAPConnection, username: string, dn: string): Promise<Array<string>> {
                        const baseDN = (settings.get<string>('LDAP_Teams_BaseDN') ?? '').trim() || ldap.options.baseDN;
                        const query = settings.get<string>('LDAP_Query_To_Get_User_Teams');
                        if (!query) {
                            return [];
                Severity: Minor
                Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 1 hr to fix

                  Avoid too many return statements within this function.
                  Open

                                  return;
                  Severity: Major
                  Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return;
                    Severity: Major
                    Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return true;
                      Severity: Major
                      Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return true;
                        Severity: Major
                        Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return false;
                          Severity: Major
                          Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 30 mins to fix

                            Function getLdapTeamsByUsername has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private static async getLdapTeamsByUsername(ldap: LDAPConnection, username: string, dn: string): Promise<Array<string>> {
                                    const baseDN = (settings.get<string>('LDAP_Teams_BaseDN') ?? '').trim() || ldap.options.baseDN;
                                    const query = settings.get<string>('LDAP_Query_To_Get_User_Teams');
                                    if (!query) {
                                        return [];
                            Severity: Minor
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function copyActiveState has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public static copyActiveState(ldapUser: ILDAPEntry, userData: IImportUser): void {
                                    if (!ldapUser) {
                                        return;
                                    }
                            
                            
                            Severity: Minor
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function syncUserTeams has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private static async syncUserTeams(ldap: LDAPConnection, user: IUser, dn: string, isNewRecord: boolean): Promise<void> {
                                    if (!user.username) {
                                        return;
                                    }
                            
                            
                            Severity: Minor
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                public static async syncAvatars(): Promise<void> {
                                    if (settings.get('LDAP_Enable') !== true || settings.get('LDAP_Background_Sync_Avatars') !== true) {
                                        return;
                                    }
                            
                            
                            Severity: Major
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts and 1 other location - About 4 hrs to fix
                            apps/meteor/ee/server/lib/ldap/Manager.ts on lines 126..143

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 132.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                public static async syncLogout(): Promise<void> {
                                    if (settings.get('LDAP_Enable') !== true || settings.get('LDAP_Sync_AutoLogout_Enabled') !== true) {
                                        return;
                                    }
                            
                            
                            Severity: Major
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts and 1 other location - About 4 hrs to fix
                            apps/meteor/ee/server/lib/ldap/Manager.ts on lines 86..103

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 132.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                    const userIds = (await Users.findLDAPUsersExceptIds(foundUsers, { projection: { _id: 1 } }).toArray()).map(({ _id }) => _id);
                            Severity: Major
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts and 2 other locations - About 1 hr to fix
                            apps/meteor/app/livechat/server/api/lib/inquiries.ts on lines 11..13
                            apps/meteor/ee/server/models/raw/LivechatUnit.ts on lines 106..106

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 55.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                private static parseJson(json: string): Record<string, any> | undefined {
                                    try {
                                        return JSON.parse(json);
                                    } catch (err) {
                                        logger.error({ msg: 'Unexpected error', err });
                            Severity: Minor
                            Found in apps/meteor/ee/server/lib/ldap/Manager.ts and 1 other location - About 45 mins to fix
                            apps/meteor/ee/server/lib/ldap/copyCustomFieldsLDAP.ts on lines 37..43

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 50.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status