forked from almenscorner/IntuneCD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle notification template isDefault
- Loading branch information
1 parent
9763d9d
commit 224bf44
Showing
2 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ def remove_keys(self, data: dict): | |
"certificate", | ||
"createdDateTime", | ||
"lastModifiedDateTime", | ||
"isDefault", | ||
"isAssigned", | ||
"@odata.context", | ||
"[email protected]", | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ def __init__(self, *args, **kwargs): | |
self.handle_assignment = False | ||
self.params = {"$expand": "localizedNotificationMessages"} | ||
self.exclude_paths = [ | ||
"root['defaultLocale']", | ||
"root['localizedNotificationMessages']", | ||
"root['[email protected]']", | ||
] | ||
|
@@ -47,11 +48,11 @@ def _handle_locale_diffs( | |
repo_data["localizedNotificationMessages"], | ||
): | ||
self.name = repo_locale.get("locale") | ||
locale_diff = self.get_diffs(intune_locale, repo_locale, None) | ||
if locale_diff: | ||
if locale_diff := self.get_diffs(intune_locale, repo_locale, None): | ||
self.config_type = "Notification Template Locale" | ||
repo_locale.pop("isDefault", None) | ||
repo_locale.pop("locale", None) | ||
data = repo_data.copy() | ||
data.pop("isDefault", None) | ||
data.pop("locale", None) | ||
self.update_downstream_data( | ||
self.endpoint | ||
+ self.CONFIG_ENDPOINT | ||
|
@@ -63,11 +64,41 @@ def _handle_locale_diffs( | |
+ intune_locale["id"], | ||
status_code=200, | ||
method="patch", | ||
data=repo_locale, | ||
data=data, | ||
) | ||
|
||
self.update_diff_data(locale_diff) | ||
|
||
def _handle_locale_isDefault( | ||
self, intune_data: dict[str, any], repo_data: dict[str, any] | ||
) -> None: | ||
"""Update the isDefault value for the locale | ||
Args: | ||
intune_data (dict[str, any]): The Intune data | ||
""" | ||
for intune_locale, repo_locale in zip( | ||
intune_data["localizedNotificationMessages"], | ||
repo_data["localizedNotificationMessages"], | ||
): | ||
repo_locale.pop("locale", None) | ||
if intune_locale.get("isDefault") != repo_locale.get("isDefault"): | ||
if repo_locale["isDefault"] is False: | ||
repo_locale.pop("isDefault", None) | ||
|
||
self.update_downstream_data( | ||
self.endpoint | ||
+ self.CONFIG_ENDPOINT | ||
+ self.downstream_id | ||
+ "/" | ||
+ "localizedNotificationMessages" | ||
+ "/" | ||
+ intune_locale["id"], | ||
status_code=200, | ||
method="patch", | ||
data=repo_locale, | ||
) | ||
|
||
def _post_locale_data(self, repo_data: dict[str, any]) -> None: | ||
"""Post the locale data to Intune | ||
|
@@ -112,6 +143,12 @@ def main(self) -> dict[str, any]: | |
} | ||
self.name = repo_data.get("displayName") | ||
diff_data = self.create_diff_data(self.name, self.config_type) | ||
update_and_create_data = { | ||
"displayName": repo_data.get("displayName"), | ||
"description": repo_data.get("description"), | ||
"brandingOptions": repo_data.get("brandingOptions"), | ||
"roleScopeTagIds": repo_data.get("roleScopeTagIds"), | ||
} | ||
|
||
try: | ||
self.process_update( | ||
|
@@ -120,12 +157,8 @@ def main(self) -> dict[str, any]: | |
method="patch", | ||
status_code=200, | ||
config_endpoint=self.CONFIG_ENDPOINT, | ||
update_data={ | ||
"displayName": repo_data.get("displayName"), | ||
"description": repo_data.get("description"), | ||
"brandingOptions": repo_data.get("brandingOptions"), | ||
"roleScopeTagIds": repo_data.get("roleScopeTagIds"), | ||
}, | ||
update_data=update_and_create_data, | ||
create_data=update_and_create_data, | ||
) | ||
except Exception as e: | ||
self.log( | ||
|
@@ -136,6 +169,7 @@ def main(self) -> dict[str, any]: | |
self.params = None | ||
self.config_type = "Notification Template Locale" | ||
self._handle_locale_diffs(self.downstream_object, repo_data) | ||
self._handle_locale_isDefault(self.downstream_object, repo_data) | ||
if self.create_request: | ||
self.params = None | ||
self._post_locale_data(repo_data) | ||
|