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

Add enable\disable\force password change directory methods #460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions O365/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,37 @@ def get_current_user(self, query=None):

url = self.build_url('') # target main_resource
return self._get_user(url, query=query)

def disable_user(self, user):
""" Disables user by it's id or user principal name

:param str user: the user id or user principal name
"""
url = self.build_url(self._endpoints.get('get_user').format(email=user))
data = {'accountEnabled': False}
response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'})

return bool(response)

def enable_user(self, user):
""" Enables user by it's id or user principal name

:param str user: the user id or user principal name
"""
url = self.build_url(self._endpoints.get('get_user').format(email=user))
data = {'accountEnabled': True}
response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'})

return bool(response)

def force_change_password(self, user):
""" Forces user to change his password on the next logon

:param str user: the user id or user principal name
"""

url = self.build_url(self._endpoints.get('get_user').format(email=user))
data = {'passwordProfile': {'forceChangePasswordNextSignIn': True}}
response = self.con.patch(url, data=data, headers={'Content-Type': 'application/json'})

return bool(response)