Created
April 26, 2019 22:32
-
-
Save gdestuynder/243382de384e375da0461b10f6858aa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/python-modules/cis_publisher/cis_publisher/publisher.py | |
+++ b/python-modules/cis_publisher/cis_publisher/publisher.py | |
@@ -129,6 +129,9 @@ class Publish: | |
else: | |
user_id = profile.user_id.value | |
+ # Fixups and cleanups | |
+ self.filter_profiles_cleanup(profiles=[profile]) | |
+ | |
# Filter out non-updatable attributes as needed | |
self.filter_known_cis_users(profiles=[profile]) | |
@@ -313,6 +316,29 @@ class Publish: | |
raise PublisherError("Failed to query CIS Person API", response.text) | |
return User(response.json()) | |
+ def filter_profiles_cleanup(self, profiles=None): | |
+ """ | |
+ Fixups for any potential issue - this runs before any additional filtering is done on the profiles | |
+ """ | |
+ self.__deferred_init() | |
+ if profiles is None: | |
+ profiles = self.profiles | |
+ | |
+ # Remove any empty-string value as Dynamo does not know how to handle these. None are OK. | |
+ for n in range(0, len(profiles)): | |
+ p = profiles[n] | |
+ for field in p.as_dict(): | |
+ if isinstance(field, str): | |
+ continue # schema | |
+ f = field.get("value", field.get("values")) | |
+ if f is not None and len(f) == 0: | |
+ if field.get("value") is not None: | |
+ profiles[n][field]["value"] = " " | |
+ elif field.get("values") is not None: | |
+ profiles[n][field]["values"] = " " | |
+ self.profiles = profiles | |
+ return profiles | |
+ | |
def filter_known_cis_users(self, profiles=None, save=True): | |
""" | |
Filters out fields that are not allowed to be updated by this publisher from the profile before posting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment