From dd20cb6f545815de33587dab69df247f865324c6 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Tue, 17 Sep 2019 11:31:39 -0500
Subject: [PATCH] Added equality operators and blacklist/graylist compatibility
 checks.

---
 canvas_classes.py |  9 +++++++++
 composite_user.py | 18 ++++++++++++++++++
 gitlab_classes.py |  9 +++++++++
 3 files changed, 36 insertions(+)

diff --git a/canvas_classes.py b/canvas_classes.py
index a9366dd..03f52a9 100644
--- a/canvas_classes.py
+++ b/canvas_classes.py
@@ -42,6 +42,15 @@ class CanvasUser:
         username = self.get_username()
         return f'@{username}'
 
+    def __eq__(self, other):
+        if isinstance(other, CanvasUser):
+            return self.get_username() == other.get_username()
+        else:
+            return False
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 """
 // A Canvas user, e.g. a student, teacher, administrator, observer, etc.
diff --git a/composite_user.py b/composite_user.py
index 49bfb05..bf2d485 100644
--- a/composite_user.py
+++ b/composite_user.py
@@ -48,12 +48,30 @@ class CompositeUser:
     def discard_team(self):
         self.candidate_teammates = None
 
+    def has_blacklist(self):
+        return len(self.blacklist) > 0
+
+    def is_blacklist_compatible(self, other):
+        return other not in self.blacklist
+
+    def is_graylist_compatible(self, other):
+        return other not in self.graylist
+
     def __repr__(self):
         if self.canvas_email == self.gitlab_email:
             return f'{self.readable_name} <{self.canvas_email}>'
         else:
             return f'{self.readable_name} <{self.canvas_email}> <{self.gitlab_email}>'
 
+    def __eq__(self, other):
+        if isinstance(other, CompositeUser):
+            return self.canvas_username() == other.canvas_username()
+        else:
+            return False
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     @staticmethod
     def get_user(username_or_email):
         return CompositeUser.instances[username_or_email]
diff --git a/gitlab_classes.py b/gitlab_classes.py
index 7469f46..cc3d2cf 100644
--- a/gitlab_classes.py
+++ b/gitlab_classes.py
@@ -45,6 +45,15 @@ class GitlabUser:
         username = self.get_username()
         return f'@{username}'
 
+    def __eq__(self, other):
+        if isinstance(other, GitlabUser):
+            return self.get_username() == other.get_username()
+        else:
+            return False
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 class Issue:
     def __init__(self, issue):
-- 
GitLab