-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_wizard.py
More file actions
89 lines (75 loc) · 2.53 KB
/
user_wizard.py
File metadata and controls
89 lines (75 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# user_wizard.py
from graph_users import create_user
from graph_groups import add_user_to_group, get_group_id_by_display_name
from graph_licenses import assign_license
from graph_roles import assign_role
from utils import generate_password
from config import config
from logger import log_event
def user_creation_wizard():
print("\n=== USER CREATION WIZARD ===")
# -------------------------
# Step 1: Collect inputs
# -------------------------
first = input("First name: ").strip()
last = input("Last name: ").strip()
department = input("Department: ").strip()
job_title = input("Job Title: ").strip()
location = input("Location: ").strip()
# -------------------------
# Step 2: Generate password
# -------------------------
password = generate_password()
# -------------------------
# Step 3: Create user
# -------------------------
result = create_user(first, last, password)
if not result["success"]:
print("\nUser creation failed.")
return result
user = result["user"]
user_id = user["id"]
log_event("UserCreatedWizard", {
"user_id": user_id,
"first": first,
"last": last,
"department": department,
"job_title": job_title,
"location": location
})
# -------------------------
# Step 4: Assign default groups
# -------------------------
assigned_groups = []
for group_name in config.get("default_groups", []):
group_id = get_group_id_by_display_name(group_name)
if group_id:
add_user_to_group(user_id, group_id)
assigned_groups.append(group_name)
# -------------------------
# Step 5: Assign default licenses
# -------------------------
assigned_licenses = []
for sku in config.get("default_license_skus", []):
assign_license(user_id, sku)
assigned_licenses.append(sku)
# -------------------------
# Step 6: Assign default roles
# -------------------------
assigned_roles = []
for role in config.get("default_roles", []):
assign_role(user_id, role)
assigned_roles.append(role)
# -------------------------
# Step 7: Summary
# -------------------------
summary = {
"user_id": user_id,
"upn": user["userPrincipalName"],
"password": password,
"assigned_groups": assigned_groups,
"assigned_licenses": assigned_licenses,
"assigned_roles": assigned_roles
}
print("\n=== USER CREATED SUCCESSFULLY ===")
return summary