13
13
from office365 .mail .contact_collection import ContactCollection
14
14
from office365 .calendar .event_collection import EventCollection
15
15
from office365 .mail .message_collection import MessageCollection
16
+ from office365 .onedrive .siteCollection import SiteCollection
16
17
from office365 .runtime .client_value_collection import ClientValueCollection
17
18
from office365 .runtime .http .http_method import HttpMethod
18
19
from office365 .runtime .queries .service_operation_query import ServiceOperationQuery
23
24
class User (DirectoryObject ):
24
25
"""Represents an Azure AD user account. Inherits from directoryObject."""
25
26
27
+ def assign_license (self , addLicenses , removeLicenses ):
28
+ """
29
+ Add or remove licenses on the user.
30
+ :param list[str] removeLicenses: A collection of skuIds that identify the licenses to remove.
31
+ :param ClientValueCollection addLicenses: A collection of assignedLicense objects that specify
32
+ the licenses to add.
33
+ """
34
+ params = {
35
+ "addLicenses" : addLicenses ,
36
+ "removeLicenses" : removeLicenses
37
+ }
38
+ qry = ServiceOperationQuery (self , "assignLicense" , None , params , None , self )
39
+ self .context .add_query (qry )
40
+ return self
41
+
42
+ def change_password (self , currentPassword , newPassword ):
43
+ """
44
+
45
+ :param str currentPassword:
46
+ :param str newPassword:
47
+ """
48
+ qry = ServiceOperationQuery (self , "changePassword" , None ,
49
+ {"currentPassword" : currentPassword , "newPassword" : newPassword })
50
+ self .context .add_query (qry )
51
+ return self
52
+
26
53
def send_mail (self , message ):
27
54
"""Send a new message on the fly"""
28
55
qry = ServiceOperationQuery (self , "sendmail" , None , message )
@@ -80,6 +107,7 @@ def get_calendar_view(self, start_dt, end_dt):
80
107
def _construct_request (request ):
81
108
request .method = HttpMethod .Get
82
109
request .url += "?startDateTime={0}&endDateTime={1}" .format (start_dt .isoformat (), end_dt .isoformat ())
110
+
83
111
self .context .before_execute (_construct_request )
84
112
return result
85
113
@@ -102,6 +130,7 @@ def get_reminder_view(self, start_dt, end_dt):
102
130
103
131
def _construct_request (request ):
104
132
request .method = HttpMethod .Get
133
+
105
134
self .context .before_execute (_construct_request )
106
135
return result
107
136
@@ -113,7 +142,7 @@ def delete_object(self, permanent_delete=False):
113
142
"""
114
143
super (User , self ).delete_object ()
115
144
if permanent_delete :
116
- deleted_user = self .context .directory .deleted_users [self .id ]
145
+ deleted_user = self .context .directory .deletedUsers [self .id ]
117
146
deleted_user .delete_object ()
118
147
return self
119
148
@@ -122,7 +151,7 @@ def account_enabled(self):
122
151
return self .properties .get ('accountEnabled' , None )
123
152
124
153
@property
125
- def creationType (self ):
154
+ def creation_type (self ):
126
155
"""Indicates whether the user account was created as a regular school or work account (null),
127
156
an external account (Invitation), a local account for an Azure Active Directory B2C tenant (LocalAccount)
128
157
or self-service sign-up using email verification (EmailVerified). Read-only.
@@ -137,7 +166,7 @@ def mail(self):
137
166
return self .properties .get ('mail' , None )
138
167
139
168
@property
140
- def otherMails (self ):
169
+ def other_mails (self ):
141
170
"""A list of additional email addresses for the user;
142
171
for example: ["[email protected] ", "[email protected] "]. Supports $filter.
143
172
"""
@@ -159,6 +188,11 @@ def assigned_licenses(self):
159
188
return self .properties .get ('assignedLicenses' ,
160
189
ClientValueCollection (AssignedLicense ))
161
190
191
+ @property
192
+ def followed_sites (self ):
193
+ return self .properties .get ('followedSites' ,
194
+ SiteCollection (self .context , ResourcePath ("followedSites" , self .resource_path )))
195
+
162
196
@property
163
197
def photo (self ):
164
198
"""
@@ -188,14 +222,14 @@ def calendars(self):
188
222
CalendarCollection (self .context , ResourcePath ("calendars" , self .resource_path )))
189
223
190
224
@property
191
- def calendarGroups (self ):
225
+ def calendar_groups (self ):
192
226
"""The user's calendar groups. Read-only. Nullable."""
193
227
return self .properties .get ('calendarGroups' ,
194
228
CalendarGroupCollection (self .context ,
195
229
ResourcePath ("calendarGroups" , self .resource_path )))
196
230
197
231
@property
198
- def licenseDetails (self ):
232
+ def license_details (self ):
199
233
"""Retrieve the properties and relationships of a Drive resource."""
200
234
return self .properties .get ('licenseDetails' ,
201
235
LicenseDetailsCollection (self .context ,
@@ -226,26 +260,36 @@ def messages(self):
226
260
MessageCollection (self .context , ResourcePath ("messages" , self .resource_path )))
227
261
228
262
@property
229
- def joinedTeams (self ):
263
+ def joined_teams (self ):
230
264
"""Get the teams in Microsoft Teams that the user is a direct member of."""
231
265
return self .properties .get ('joinedTeams' ,
232
266
TeamCollection (self .context , ResourcePath ("joinedTeams" , self .resource_path )))
233
267
234
268
@property
235
- def memberOf (self ):
269
+ def member_of (self ):
236
270
"""Get groups and directory roles that the user is a direct member of."""
237
271
return self .properties .get ('memberOf' ,
238
272
DirectoryObjectCollection (self .context ,
239
273
ResourcePath ("memberOf" , self .resource_path )))
240
274
241
275
@property
242
- def transitiveMemberOf (self ):
276
+ def transitive_member_of (self ):
243
277
"""Get groups, directory roles that the user is a member of. This API request is transitive, and will also
244
278
return all groups the user is a nested member of. """
245
279
return self .properties .get ('transitiveMemberOf' ,
246
280
DirectoryObjectCollection (self .context ,
247
281
ResourcePath ("transitiveMemberOf" , self .resource_path )))
248
282
283
+ def get_property (self , name ):
284
+ if name == "transitiveMemberOf" :
285
+ return self .transitive_member_of
286
+ elif name == "joinedTeams" :
287
+ return self .joined_teams
288
+ elif name == "assignedLicenses" :
289
+ return self .assigned_licenses
290
+ else :
291
+ return super (User , self ).get_property (name )
292
+
249
293
def set_property (self , name , value , persist_changes = True ):
250
294
super (User , self ).set_property (name , value , persist_changes )
251
295
# fallback: create a new resource path
0 commit comments