add email to Person.all_names and Config.all_names
[utils.git] / src / budget_sync / config.py
index 8a490b5ea61f4df3e50a3d6d3cf9a62275b09c04..28b584ca33468fd449d66e6c0c5a8fe0dd14834f 100644 (file)
@@ -28,6 +28,8 @@ class Person:
     def all_names(self) -> Set[str]:
         retval = self.aliases.copy()
         retval.add(self.identifier)
+        if self.email is not None:
+            retval.add(self.email)
         return retval
 
     def __eq__(self, other):
@@ -84,22 +86,25 @@ class Config:
         retval = self.people.copy()
 
         for person in self.people.values():
-            for alias in person.aliases:
-                other_person = retval.get(alias)
-                if other_person is not None:
-                    if alias in self.people:
+            for name in person.all_names:
+                other_person = retval.get(name)
+                if other_person is not None and other_person is not person:
+                    alias_or_email = "alias"
+                    if name == person.email:
+                        alias_or_email = "email"
+                    if name in self.people:
                         raise ConfigParseError(
-                            f"alias is not allowed to be the same as any"
-                            f" person's identifier: in person entry for "
-                            f"{person.identifier!r}: {alias!r} is also the "
+                            f"{alias_or_email} is not allowed to be the same "
+                            f"as any person's identifier: in person entry for "
+                            f"{person.identifier!r}: {name!r} is also the "
                             f"identifier for person"
                             f" {other_person.identifier!r}")
                     raise ConfigParseError(
-                        f"alias is not allowed to be the same as another"
-                        f" person's alias: in person entry for "
-                        f"{person.identifier!r}: {alias!r} is also an alias "
-                        f"for person {other_person.identifier!r}")
-                retval[alias] = person
+                        f"{alias_or_email} is not allowed to be the same as "
+                        f"another person's alias or email: in person entry "
+                        f"for {person.identifier!r}: {name!r} is also an alias"
+                        f" or email for person {other_person.identifier!r}")
+                retval[name] = person
         return retval
 
     @cached_property