adsabs/biblib-service

View on GitHub
biblib/views/permission_view.py

Summary

Maintainability
F
3 days
Test Coverage

File permission_view.py has 429 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Perimssion view
"""

from flask import request, current_app
Severity: Minor
Found in biblib/views/permission_view.py - About 6 hrs to fix

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

        def add_permission(service_uid, library_id, permission):
            """
            Adds a permission for a user to a specific library
            :param service_uid: the user ID within this microservice
            :param library_id: the library id to update
    Severity: Minor
    Found in biblib/views/permission_view.py - 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 post has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, library):
            """
            HTTP POST request that modifies the permissions of a library
            :param library: library ID
    
    
    Severity: Minor
    Found in biblib/views/permission_view.py - 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 has_permission has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def has_permission(service_uid_editor,
                           service_uid_modify,
                           library_id):
            """
            Check if the user wanting to change the library has the correct
    Severity: Minor
    Found in biblib/views/permission_view.py - 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

    Avoid too many return statements within this function.
    Open

                return err(NO_PERMISSION_ERROR)
    Severity: Major
    Found in biblib/views/permission_view.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return False
      Severity: Major
      Found in biblib/views/permission_view.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return err(API_MISSING_USER_EMAIL)
        Severity: Major
        Found in biblib/views/permission_view.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return {}, 200
          Severity: Major
          Found in biblib/views/permission_view.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                                return True
            Severity: Major
            Found in biblib/views/permission_view.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return False
              Severity: Major
              Found in biblib/views/permission_view.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return err(NO_PERMISSION_ERROR)
                Severity: Major
                Found in biblib/views/permission_view.py - About 30 mins to fix

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

                      def format_permission_payload(library_name, library_id, permission_data):
                          """
                          Format the permission info into plain text and HTML payloads for the email
                  
                          :param library_name: string; name of library
                  Severity: Minor
                  Found in biblib/views/permission_view.py - 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 3 locations. Consider refactoring.
                  Open

                          try:
                              permission_data = get_post_data(
                                  request,
                                  types=dict(
                                      email=str,
                  Severity: Major
                  Found in biblib/views/permission_view.py and 2 other locations - About 2 hrs to fix
                  biblib/views/document_view.py on lines 229..237
                  biblib/views/document_view.py on lines 614..622

                  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 58.

                  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

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

                                  if not (new_permission.permissions['read'] |
                                          new_permission.permissions['write'] |
                                          new_permission.permissions['admin'] |
                                          new_permission.permissions['owner']):
                  Severity: Major
                  Found in biblib/views/permission_view.py and 1 other location - About 2 hrs to fix
                  biblib/views/permission_view.py on lines 195..198

                  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

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

                                  if not (new_permission.permissions['read'] |
                                          new_permission.permissions['write'] |
                                          new_permission.permissions['admin'] |
                                          new_permission.permissions['owner']):
                  Severity: Major
                  Found in biblib/views/permission_view.py and 1 other location - About 2 hrs to fix
                  biblib/views/permission_view.py on lines 154..157

                  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 3 locations. Consider refactoring.
                  Open

                      @classmethod
                      def read_access(cls, service_uid, library_id):
                          """
                          Checks if the user has access to read the permissions on a given
                          library
                  Severity: Major
                  Found in biblib/views/permission_view.py and 2 other locations - About 1 hr to fix
                  biblib/views/base_view.py on lines 231..248
                  biblib/views/base_view.py on lines 250..267

                  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 45.

                  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

                          if not self.read_access(service_uid=service_uid,
                                                  library_id=library):
                              current_app.logger.error(
                                  'User {0} has the wrong permissions to get the '
                                  'permission list for library {1}'
                  Severity: Major
                  Found in biblib/views/permission_view.py and 1 other location - About 1 hr to fix
                  biblib/views/transfer_view.py on lines 182..189

                  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 44.

                  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

                              try:
                                  modify_permissions = session.query(Permissions).filter(
                                      Permissions.user_id == service_uid_modify,
                                      Permissions.library_id == library_id
                  Severity: Major
                  Found in biblib/views/permission_view.py and 2 other locations - About 1 hr to fix
                  biblib/views/notes_view.py on lines 52..54
                  biblib/views/permission_view.py on lines 68..71

                  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 38.

                  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

                              try:
                                  editor_permissions = session.query(Permissions).filter(
                                      Permissions.user_id == service_uid_editor,
                                      Permissions.library_id == library_id
                  Severity: Major
                  Found in biblib/views/permission_view.py and 2 other locations - About 1 hr to fix
                  biblib/views/notes_view.py on lines 52..54
                  biblib/views/permission_view.py on lines 87..90

                  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 38.

                  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

                          try:
                              secondary_user = self.helper_email_to_api_uid(permission_data)
                              current_app.logger.info('User: {0} corresponds to: {1}'
                                                      .format(permission_data['email'],
                                                              secondary_user))
                  Severity: Minor
                  Found in biblib/views/permission_view.py and 1 other location - About 50 mins to fix
                  biblib/views/transfer_view.py on lines 165..169

                  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 36.

                  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

                              result = session.query(Permissions, User)\
                                  .join(Permissions.user)\
                                  .filter(Permissions.library_id == library_id)\
                  Severity: Minor
                  Found in biblib/views/permission_view.py and 1 other location - About 30 mins to fix
                  biblib/views/base_view.py on lines 755..757

                  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 32.

                  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