FIX: role changed on admin and on moodle
parent
86baf7bd69
commit
77342f6e8a
|
@ -1,6 +1,7 @@
|
|||
#
|
||||
# Copyright © 2021,2022 IsardVDI S.L.
|
||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||
#
|
||||
# This file is part of DD
|
||||
#
|
||||
|
@ -1576,6 +1577,9 @@ class Admin:
|
|||
ev.update_text("Syncing data from applications...")
|
||||
self.resync_data()
|
||||
|
||||
ev.update_text("Removing user role in moodle")
|
||||
self.unassign_moodle_user_role(internaluser["moodle_id"], mdelete)
|
||||
|
||||
ev.update_text("Updating user in moodle")
|
||||
self.update_moodle_user(internaluser["id"], user, mdelete, madd)
|
||||
|
||||
|
@ -1588,6 +1592,31 @@ class Admin:
|
|||
ev.update_text("User updated")
|
||||
return True
|
||||
|
||||
def unassign_moodle_user_role(self, user_id, role_name):
|
||||
role_id = 0
|
||||
if not role_name:
|
||||
return True
|
||||
|
||||
if role_name[0] =='teacher':
|
||||
role_id = 2
|
||||
elif role_name[0] =='manager':
|
||||
role_id = 1
|
||||
|
||||
if role_id == 0:
|
||||
log.warning("MOODLE: User is student. no need to be unassigned in moodle.")
|
||||
return True
|
||||
|
||||
log.warning("MOODLE: lets unassign user role")
|
||||
try:
|
||||
self.moodle.unassign_user_rol(
|
||||
user_id, role_id
|
||||
)
|
||||
except:
|
||||
log.error(
|
||||
"MOODLE: User has not been able to unassign from role"
|
||||
)
|
||||
return True
|
||||
|
||||
def update_keycloak_user(self, user_id : str, user : DDUser, kdelete : List[Any], kadd : List[Any]) -> bool:
|
||||
# pprint(self.keycloak.get_user_realm_roles(user_id))
|
||||
self.keycloak.remove_user_realm_roles(user_id, "student")
|
||||
|
@ -1652,8 +1681,8 @@ class Admin:
|
|||
)
|
||||
|
||||
for group in madd:
|
||||
cohort = [c for c in cohorts if c["name"] == group][0]
|
||||
self.moodle.add_user_to_cohort(internaluser["moodle_id"], cohort["id"])
|
||||
cohort = [c for c in cohorts if c["name"] == group]
|
||||
self.moodle.add_user_to_cohort(internaluser["moodle_id"], cohort[0]["id"])
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#
|
||||
# Copyright © 2021,2022 IsardVDI S.L.
|
||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||
#
|
||||
# This file is part of DD
|
||||
#
|
||||
|
@ -264,6 +265,9 @@ class Moodle:
|
|||
log.warning(
|
||||
"MOODLE:ADDING THE USER TO ADMINS: This needs a purge cache in moodle!"
|
||||
)
|
||||
def unassign_user_rol(self, user_id, role_id):
|
||||
unassignments = [{"roleid": role_id, "userid": user_id, "contextlevel": 'system', "instanceid": 0}]
|
||||
return self.call("core_role_unassign_roles", unassignments=unassignments)
|
||||
|
||||
# def add_role_to_user(self, user_id, role='admin', context='missing'):
|
||||
# if role=='admin':
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#
|
||||
# Copyright © 2021,2022 IsardVDI S.L.
|
||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||
#
|
||||
# This file is part of DD
|
||||
#
|
||||
|
@ -46,7 +47,7 @@ class Postup:
|
|||
while not ready:
|
||||
try:
|
||||
self.pg = Postgres(
|
||||
"dd-apps-postgresql",
|
||||
"isard-apps-postgresql",
|
||||
"moodle",
|
||||
app.config["MOODLE_POSTGRES_USER"],
|
||||
app.config["MOODLE_POSTGRES_PASSWORD"],
|
||||
|
@ -190,6 +191,7 @@ class Postup:
|
|||
(3, 'core_cohort_search_cohorts'),
|
||||
(3, 'core_cohort_update_cohorts'),
|
||||
(3, 'core_role_assign_roles'),
|
||||
(3, 'core_role_unassign_roles'),
|
||||
(3, 'core_cohort_get_cohorts');"""
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue