FIX: role changed on admin and on moodle
parent
78b0254ba0
commit
9cb2b68543
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -1496,6 +1496,9 @@ class Admin:
|
||||||
ev.update_text("Syncing data from applications...")
|
ev.update_text("Syncing data from applications...")
|
||||||
self.resync_data()
|
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")
|
ev.update_text("Updating user in moodle")
|
||||||
self.update_moodle_user(internaluser["id"], user, mdelete, madd)
|
self.update_moodle_user(internaluser["id"], user, mdelete, madd)
|
||||||
|
|
||||||
|
@ -1505,6 +1508,31 @@ class Admin:
|
||||||
ev.update_text("User updated")
|
ev.update_text("User updated")
|
||||||
return True
|
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, user, kdelete, kadd):
|
def update_keycloak_user(self, user_id, user, kdelete, kadd):
|
||||||
# pprint(self.keycloak.get_user_realm_roles(user_id))
|
# pprint(self.keycloak.get_user_realm_roles(user_id))
|
||||||
self.keycloak.remove_user_realm_roles(user_id, "student")
|
self.keycloak.remove_user_realm_roles(user_id, "student")
|
||||||
|
@ -1541,7 +1569,7 @@ class Admin:
|
||||||
internaluser = [u for u in self.internal["users"] if u["id"] == user_id][0]
|
internaluser = [u for u in self.internal["users"] if u["id"] == user_id][0]
|
||||||
cohorts = self.moodle.get_cohorts()
|
cohorts = self.moodle.get_cohorts()
|
||||||
for group in mdelete:
|
for group in mdelete:
|
||||||
cohort = [c for c in cohorts if c["name"] == group[0]]
|
cohort = [c for c in cohorts if c["name"] == group]
|
||||||
try:
|
try:
|
||||||
self.moodle.delete_user_in_cohort(
|
self.moodle.delete_user_in_cohort(
|
||||||
internaluser["moodle_id"], cohort["id"]
|
internaluser["moodle_id"], cohort["id"]
|
||||||
|
@ -1569,8 +1597,8 @@ class Admin:
|
||||||
)
|
)
|
||||||
|
|
||||||
for group in madd:
|
for group in madd:
|
||||||
cohort = [c for c in cohorts if c["name"] == group][0]
|
cohort = [c for c in cohorts if c["name"] == group]
|
||||||
self.moodle.add_user_to_cohort(internaluser["moodle_id"], cohort["id"])
|
self.moodle.add_user_to_cohort(internaluser["moodle_id"], cohort[0]["id"])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -258,6 +258,9 @@ class Moodle:
|
||||||
log.warning(
|
log.warning(
|
||||||
"MOODLE:ADDING THE USER TO ADMINS: This needs a purge cache in moodle!"
|
"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'):
|
# def add_role_to_user(self, user_id, role='admin', context='missing'):
|
||||||
# if role=='admin':
|
# if role=='admin':
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -44,7 +44,7 @@ class Postup:
|
||||||
while not ready:
|
while not ready:
|
||||||
try:
|
try:
|
||||||
self.pg = Postgres(
|
self.pg = Postgres(
|
||||||
"dd-apps-postgresql",
|
"isard-apps-postgresql",
|
||||||
"moodle",
|
"moodle",
|
||||||
app.config["MOODLE_POSTGRES_USER"],
|
app.config["MOODLE_POSTGRES_USER"],
|
||||||
app.config["MOODLE_POSTGRES_PASSWORD"],
|
app.config["MOODLE_POSTGRES_PASSWORD"],
|
||||||
|
@ -191,6 +191,7 @@ class Postup:
|
||||||
(3, 'core_cohort_search_cohorts'),
|
(3, 'core_cohort_search_cohorts'),
|
||||||
(3, 'core_cohort_update_cohorts'),
|
(3, 'core_cohort_update_cohorts'),
|
||||||
(3, 'core_role_assign_roles'),
|
(3, 'core_role_assign_roles'),
|
||||||
|
(3, 'core_role_unassign_roles'),
|
||||||
(3, 'core_cohort_get_cohorts');"""
|
(3, 'core_cohort_get_cohorts');"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue