From aa0e9470c8bd98dbb01c4acadca76bd938d07a0c Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 9 Nov 2021 10:36:29 -0500 Subject: [PATCH] Added docstrings --- Instructor/static/js/user-list.js | 14 +++++++++++- Instructor/views.py | 10 ++++++++ Users/ldap_auth.py | 38 +++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Instructor/static/js/user-list.js b/Instructor/static/js/user-list.js index bfe8ca7..e669c3d 100644 --- a/Instructor/static/js/user-list.js +++ b/Instructor/static/js/user-list.js @@ -1,9 +1,21 @@ +/* This file is used in the user list page for user cleanup */ + function cleanupSubmitClick() { + /** + * This function will run when the submit button in the user cleanup modal is pressed. + * It shows the spinner in the button and submits the form. + */ + $("#cleanupSpinner").toggleClass("d-none", false); $("#cleanupSubmitText").toggleClass("d-none", true); $("#cleanupForm").submit(); } $(document).ready(function (){ + /** + * This function will run when the document has loaded + * It sets up the cleanupSubmit button's click callback. + */ + $("#cleanupSubmitButton").click(cleanupSubmitClick); -}); \ No newline at end of file +}); diff --git a/Instructor/views.py b/Instructor/views.py index 8f83d03..4e85203 100644 --- a/Instructor/views.py +++ b/Instructor/views.py @@ -16,10 +16,20 @@ from . import models, forms class UserClearView(LoginRequiredMixin, IsSuperUserMixin, View): + """ + This view is used to cleanup any users that are not in teh ActiveDirectory database. + + :cvar http_method_names: The HTTP methods that this view takes + """ http_method_names = ['post'] def post(self, request): + """ + This function is run when on a POST request. + It clears out users that are not in the ActiveDirectory database. + """ + self.request = request password = self.request.POST.get("userPassword", None) if password is None or password == "": diff --git a/Users/ldap_auth.py b/Users/ldap_auth.py index 29341e3..bd0a08d 100644 --- a/Users/ldap_auth.py +++ b/Users/ldap_auth.py @@ -10,7 +10,12 @@ from ldap3.core.exceptions import LDAPBindError, LDAPSocketOpenError from .models import User + class LDAPAuthException(Exception): + """ + This exception is used to represent an error with authenticating through LDAP + """ + pass @@ -55,8 +60,18 @@ class LDAPAuthentication(BaseBackend): @staticmethod def check_user_is_admin(ldap_user: Entry) -> bool: + """ + This function is used to check if a given ldap user is an administrator + (Not implemented yet) + + :param ldap_user: The user to check + :type ldap_user: Entry + :returns: A boolean indicating if the user is an administrator + :rtype: bool + """ + # TODO: Implement - return False + return True def update_from_ldap(self, ldap_user: Entry, django_user: User) -> User: """ @@ -99,7 +114,17 @@ class LDAPAuthentication(BaseBackend): new_user.save() return new_user - def get_all_users(self, conn: Connection) -> Reader: + @staticmethod + def get_all_users(conn: Connection) -> Reader: + """ + This function is used to get all users in the ActiveDirectory database + + :param conn: The Connection to use for the query + :type conn: Connection + :returns: A Reader object that contains all users in the database + :rtype: Reader + """ + user_obj = ObjectDef('user', conn) reader = Reader(conn, user_obj, settings.LDAP_BASE_CONTEXT) reader.search() @@ -176,6 +201,15 @@ class LDAPAuthentication(BaseBackend): return None def delete_old_users(self, username, password): + """ + This function is used to delete any users that are no longer in the ActiveDirectory database. + + :param username: The username to use to login via LDAP + :type username: str + :param password: The password to use to login via LDAP + :type password: str + """ + conn = Connection(self.server, user=username, password=password, authentication=NTLM) try: -- knotmirror 0.0.1