Merge branch 'develop' of https://gitlab.com/DD-workspace/DD into develop
commit
6ad8df956e
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||||
|
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -116,19 +117,25 @@ class Admin:
|
||||||
|
|
||||||
def third_party_add_user(self, user_id : str, user : DDUser) -> bool:
|
def third_party_add_user(self, user_id : str, user : DDUser) -> bool:
|
||||||
res = True
|
res = True
|
||||||
|
log.warning(f" 3P Callbacks: Add {user_id}")
|
||||||
for tp in self.third_party_cbs:
|
for tp in self.third_party_cbs:
|
||||||
|
log.warning(f" 3P Callbacks: Add {user_id} to {tp.tpkeys.their_name}")
|
||||||
res = res and tp.add_user(user_id, user)
|
res = res and tp.add_user(user_id, user)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def third_party_update_user(self, user_id : str, user : DDUser) -> bool:
|
def third_party_update_user(self, user_id : str, user : DDUser) -> bool:
|
||||||
res = True
|
res = True
|
||||||
|
log.warning(f" 3P Callbacks: update {user_id}")
|
||||||
for tp in self.third_party_cbs:
|
for tp in self.third_party_cbs:
|
||||||
|
log.warning(f" 3P Callbacks: update {user_id} to {tp.tpkeys.their_name}")
|
||||||
res = res and tp.update_user(user_id, user)
|
res = res and tp.update_user(user_id, user)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def third_party_delete_user(self, user_id : str) -> bool:
|
def third_party_delete_user(self, user_id : str) -> bool:
|
||||||
res = True
|
res = True
|
||||||
|
log.warning(f" 3P Callbacks: delete {user_id}")
|
||||||
for tp in self.third_party_cbs:
|
for tp in self.third_party_cbs:
|
||||||
|
log.warning(f" 3P Callbacks: delete {user_id} to {tp.tpkeys.their_name}")
|
||||||
res = res and tp.delete_user(user_id)
|
res = res and tp.delete_user(user_id)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import logging as log
|
||||||
|
import traceback
|
||||||
from typing import Any, Dict, Tuple
|
from typing import Any, Dict, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
@ -34,6 +36,9 @@ def user_parser(dduser: DDUser) -> DDUser:
|
||||||
user["keycloak_id"] = user.pop("id")
|
user["keycloak_id"] = user.pop("id")
|
||||||
user["role"] = user["roles"][0] if user.get("roles", []) else None
|
user["role"] = user["roles"][0] if user.get("roles", []) else None
|
||||||
user["groups"] = user.get("groups", user.get("keycloak_groups", []))
|
user["groups"] = user.get("groups", user.get("keycloak_groups", []))
|
||||||
|
# Compatibility for the API
|
||||||
|
user["first"] = user["firstname"]
|
||||||
|
user["last"] = user["lasttname"]
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,25 +82,27 @@ class ThirdPartyCallbacks:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def add_users_url(self) -> str:
|
def add_users_url(self) -> str:
|
||||||
return f"{self.tpkeys.their_service_domain}{self.endpoint_add_users[1]}"
|
return f"https://{self.tpkeys.their_service_domain}{self.endpoint_add_users[1]}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def update_users_url(self) -> str:
|
def update_users_url(self) -> str:
|
||||||
return f"{self.tpkeys.their_service_domain}{self.endpoint_update_users[1]}"
|
return f"https://{self.tpkeys.their_service_domain}{self.endpoint_update_users[1]}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def delete_users_url(self) -> str:
|
def delete_users_url(self) -> str:
|
||||||
return f"{self.tpkeys.their_service_domain}{self.endpoint_delete_users[1]}"
|
return f"https://{self.tpkeys.their_service_domain}{self.endpoint_delete_users[1]}"
|
||||||
|
|
||||||
def _request(self, method: str, url: str, data: DDUser) -> bool:
|
def _request(self, method: str, url: str, data: DDUser) -> bool:
|
||||||
# The endpoints are prepared for batch operations, but the way
|
# The endpoints are prepared for batch operations, but the way
|
||||||
# the admin lib is set up, it is currently not doable.
|
# the admin lib is set up, it is currently not doable.
|
||||||
prepared_data = [user_parser(data)]
|
prepared_data = [user_parser(data)]
|
||||||
|
log.warning(f" {method} {url} {data.get('id', '?')}")
|
||||||
try:
|
try:
|
||||||
enc_data = self.tpkeys.sign_and_encrypt_outgoing_json(prepared_data)
|
enc_data = self.tpkeys.sign_and_encrypt_outgoing_json(prepared_data)
|
||||||
headers = self.tpkeys.get_outgoing_request_headers()
|
headers = self.tpkeys.get_outgoing_request_headers()
|
||||||
res = requests.request(method, url, data=enc_data, headers=headers)
|
res = requests.request(method, url, data=enc_data, headers=headers)
|
||||||
except:
|
except:
|
||||||
|
log.error(traceback.format_exc())
|
||||||
# Something went wrong sending the request
|
# Something went wrong sending the request
|
||||||
return False
|
return False
|
||||||
return res.status_code == 200
|
return res.status_code == 200
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||||
|
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -264,6 +265,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 unassign_user_rol(self, user_id, role_id):
|
def unassign_user_rol(self, user_id, role_id):
|
||||||
unassignments = [{"roleid": role_id, "userid": user_id, "contextlevel": 'system', "instanceid": 0}]
|
unassignments = [{"roleid": role_id, "userid": user_id, "contextlevel": 'system', "instanceid": 0}]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2021,2022 IsardVDI S.L.
|
# Copyright © 2021,2022 IsardVDI S.L.
|
||||||
# Copyright © 2022 Evilham <contact@evilham.com>
|
# Copyright © 2022 Evilham <contact@evilham.com>
|
||||||
|
# Copyright © 2022 Elena Barrios Galán @elena61
|
||||||
#
|
#
|
||||||
# This file is part of DD
|
# This file is part of DD
|
||||||
#
|
#
|
||||||
|
@ -46,7 +47,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"],
|
||||||
|
|
Loading…
Reference in New Issue