Skip to content

Commit

Permalink
user email update script
Browse files Browse the repository at this point in the history
  • Loading branch information
eneoli committed Apr 16, 2020
1 parent 3390645 commit be77bda
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def users_create(self, userlist):
""" Create moodle-user from a list of ldap-users """
return self.call('core_user_create_users', users=userlist)

def users_update(self, users):
return self.call('core_user_update_users', users=users)

def enrol_users(self, users):
if len(users) > 0:
self.call('enrol_manual_enrol_users', enrolments=users)
Expand Down
28 changes: 28 additions & 0 deletions utils/update_user_emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys
import inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

import moodle
import json

KEY = 'REPLACE_ME'
URL = 'REPLACE_ME'
ENDPOINT = '/webservice/rest/server.php'

m = moodle.Moodle(URL + ENDPOINT, KEY)

with open('user_dump.json', 'r') as userfile:
users = json.load(userfile)['users']
newUsers = m.users_get({'key': 'auth', 'value': 'ldap'})['users']
for user in users:
if "linux.lokal" not in user["email"]:
for nUser in newUsers:
if nUser['username'] == user['username']:
print('Update user: ', user['username'], ' <', user['email'], '>')
m.users_update([{'id': nUser['id'], 'email': user['email']}])

print('===DONE===')

0 comments on commit be77bda

Please sign in to comment.