Skip to content

Commit

Permalink
handle notification template isDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
almenscorner committed Mar 21, 2024
1 parent 9763d9d commit 224bf44
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/IntuneCD/intunecdlib/IntuneCDBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def remove_keys(self, data: dict):
"certificate",
"createdDateTime",
"lastModifiedDateTime",
"isDefault",
"isAssigned",
"@odata.context",
"[email protected]",
Expand Down
56 changes: 45 additions & 11 deletions src/IntuneCD/update/Intune/NotificationTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]']",
]
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 224bf44

Please sign in to comment.