Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mir-scripter-aa_cc_hg_audit #181

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions odins_spear/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .requester import Requester
from .logger import Logger
from .scripter import Scripter
from .reporter import Reporter


from .exceptions import (
OSApiAuthenticationFail,
Expand Down Expand Up @@ -42,8 +41,6 @@ def __init__(
self.logger = Logger.get_instance(self.username)
self._requester = Requester(self.base_url, self.rate_limit, self.logger)

self.scripter = Scripter(api=self)
self.reporter = Reporter(api=self)
self.administrators = Administrators()
self.alternate_numbers = AlternateNumbers()
self.authentication = Authentication()
Expand Down Expand Up @@ -174,6 +171,6 @@ def _update_requester(self, session_response: requests.models.Response):

def __str__(self) -> str:
return (
f"API - url: {self.base_url}, username: {self.username}"
f"API - url: {self.base_url}, username: {self.username} "
f"Authenticated: {self.authorised}"
)
2 changes: 1 addition & 1 deletion odins_spear/endpoints/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_user_service_settings(self, user_id: str):
params = {"userId": user_id}

return self._requester.get(endpoint, params=params)


def get_group_services(self, group_id: str, service_provider_id: str):
"""
Expand Down
87 changes: 19 additions & 68 deletions odins_spear/scripts/aa_cc_hg_audit.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,25 @@
from tqdm import tqdm

def remove_excess_details(aa_cc_hg: dict):
del aa_cc_hg["name"]
del aa_cc_hg["phoneNumber"]
del aa_cc_hg["extension"]
del aa_cc_hg["department"]
del aa_cc_hg["isActive"]

if aa_cc_hg["typeTag"] == "AA":
del aa_cc_hg["video"]
elif aa_cc_hg["typeTag"] == "CC":
del aa_cc_hg["video"]
del aa_cc_hg["policy"]
elif aa_cc_hg["typeTag"] == "HG":
del aa_cc_hg["serviceProviderId"]
del aa_cc_hg["groupId"]
del aa_cc_hg["policy"]

def main(api, service_provider_id: str, group_id: str):
"""
This script returns the services assigned to Auto Attendants,
Call Centres, and Hunt Groups. Only services are applied to these
entities and there are scenarios one would need to focus services
assigned to these entities.


:param service_provider_id: Service Provider ID or Enterprise ID containing the Group ID.
:param group_id: Group ID to generate the report for.
def main(api, service_provider_id: str, group_id: str) -> dict:
return_data = {"auto_attendants": [], "call_centers": [], "hunt_groups": []}

:return JSON: A JSON formatted report of service packs assigned to AA, CC, and HG.
"""
for entity_type, api_method in [
("auto_attendants", api.auto_attendants.get_auto_attendants),
("call_centers", api.call_centers.get_group_call_centers),
("hunt_groups", api.hunt_groups.get_group_hunt_groups),
]:
entities = api_method(service_provider_id, group_id)
for entity in tqdm(
entities, desc=f"Analysing {entity_type.replace("_", " ").title()}"
):
services = api.services.get_user_services_assigned(entity["serviceUserId"])
return_data[entity_type].append(
{
"serviceUserId": entity["serviceUserId"],
"type": entity.get("type", "None"),
"services": services.get("userServices", []),
}
)

print("aa_cc_hg_audit start.")
return_data = {
"autoAttendants": [],
"callCenters": [],
"huntGroups": []
}
auto_attendants = api.get.auto_attendants(service_provider_id, group_id)
call_centers = api.get.group_call_centers(service_provider_id, group_id)
hunt_groups = api.get.group_hunt_groups(service_provider_id, group_id)

for aa in tqdm(auto_attendants, desc="Analysing Auto Attendants"):
aa["typeTag"] = "AA"
remove_excess_details(aa)

for cc in tqdm(call_centers, desc="Analysing Call Centers"):
cc["typeTag"] = "CC"
remove_excess_details(cc)

for hg in tqdm(hunt_groups, desc="Analysing Hunt Groups"):
hg["typeTag"] = "HG"
remove_excess_details(hg)

aa_cc_hgs = auto_attendants + call_centers + hunt_groups

for aa_cc_hg in tqdm(aa_cc_hgs, desc="Fetching User Services"):
response = api.get.user_services_assigned(aa_cc_hg["serviceUserId"])
aa_cc_hg["services"] = response["userServices"]

if aa_cc_hg["typeTag"] == "AA":
del aa_cc_hg["typeTag"]
return_data["autoAttendants"].append(aa_cc_hg)
elif aa_cc_hg["typeTag"] == "CC":
del aa_cc_hg["typeTag"]
return_data["callCenters"].append(aa_cc_hg)
elif aa_cc_hg["typeTag"] == "HG":
del aa_cc_hg["typeTag"]
return_data["huntGroups"].append(aa_cc_hg)

return return_data