fix(admin): upload csv fixed
parent
cc8bdc8554
commit
5f81a853a2
|
@ -32,7 +32,7 @@ import secrets
|
||||||
|
|
||||||
from .events import Events
|
from .events import Events
|
||||||
from .exceptions import UserExists, UserNotFound
|
from .exceptions import UserExists, UserNotFound
|
||||||
from .helpers import count_repeated, rand_password
|
from .helpers import count_repeated, rand_password, kpath2gids
|
||||||
|
|
||||||
MANAGER = os.environ["CUSTOM_ROLE_MANAGER"]
|
MANAGER = os.environ["CUSTOM_ROLE_MANAGER"]
|
||||||
TEACHER = os.environ["CUSTOM_ROLE_TEACHER"]
|
TEACHER = os.environ["CUSTOM_ROLE_TEACHER"]
|
||||||
|
@ -606,9 +606,10 @@ class Admin:
|
||||||
if u["role"] == "teacher":
|
if u["role"] == "teacher":
|
||||||
u["quota"] = "5 GB"
|
u["quota"] = "5 GB"
|
||||||
if u["role"] == "manager":
|
if u["role"] == "manager":
|
||||||
u["quota"] = "Unlimited"
|
u["quota"] = "none"
|
||||||
if u["role"] == "admin":
|
if u["role"] == "admin":
|
||||||
u["quota"] = "Unlimited"
|
u["quota"] = "none"
|
||||||
|
if u["quota"].lower() in ["false","unlimited"]: u["quota"] = "none"
|
||||||
|
|
||||||
users.append(
|
users.append(
|
||||||
{
|
{
|
||||||
|
@ -739,14 +740,7 @@ class Admin:
|
||||||
log.warning("All syncs finished. Resyncing from apps...")
|
log.warning("All syncs finished. Resyncing from apps...")
|
||||||
self.resync_data()
|
self.resync_data()
|
||||||
|
|
||||||
def sync_to_keycloak_external(
|
def add_keycloak_groups(self,groups):
|
||||||
self,
|
|
||||||
): ### This one works from the external, moodle and nextcloud from the internal
|
|
||||||
groups = []
|
|
||||||
for u in self.external["users"]:
|
|
||||||
groups = groups + u["groups"]
|
|
||||||
groups = list(dict.fromkeys(groups))
|
|
||||||
|
|
||||||
total = len(groups)
|
total = len(groups)
|
||||||
i = 0
|
i = 0
|
||||||
ev = Events(
|
ev = Events(
|
||||||
|
@ -765,6 +759,16 @@ class Admin:
|
||||||
ev.increment({"name": g})
|
ev.increment({"name": g})
|
||||||
self.keycloak.add_group_tree(g)
|
self.keycloak.add_group_tree(g)
|
||||||
|
|
||||||
|
def sync_to_keycloak_external(
|
||||||
|
self,
|
||||||
|
): ### This one works from the external, moodle and nextcloud from the internal
|
||||||
|
groups = []
|
||||||
|
for u in self.external["users"]:
|
||||||
|
groups = groups + u["groups"]
|
||||||
|
groups = list(dict.fromkeys(groups))
|
||||||
|
|
||||||
|
self.add_keycloak_groups(groups)
|
||||||
|
|
||||||
total = len(self.external["users"])
|
total = len(self.external["users"])
|
||||||
index = 0
|
index = 0
|
||||||
ev = Events(
|
ev = Events(
|
||||||
|
@ -834,24 +838,15 @@ class Admin:
|
||||||
u["groups"].append(u["roles"][0])
|
u["groups"].append(u["roles"][0])
|
||||||
self.resync_data()
|
self.resync_data()
|
||||||
|
|
||||||
def sync_to_moodle_external(self): # works from the internal (keycloak)
|
def add_moodle_groups(self,groups):
|
||||||
### Process all groups from the users keycloak_groups key
|
|
||||||
groups = []
|
|
||||||
for u in self.external["users"]:
|
|
||||||
groups = groups + u["gids"]
|
|
||||||
groups = list(dict.fromkeys(groups))
|
|
||||||
|
|
||||||
### Create all groups. Skip / in system groups
|
### Create all groups. Skip / in system groups
|
||||||
total = len(groups)
|
total = len(groups)
|
||||||
log.error(groups)
|
log.error(groups)
|
||||||
ev = Events("Syncing groups from external to moodle", total=len(groups))
|
ev = Events("Syncing groups from external to moodle", total=len(groups))
|
||||||
|
i=1
|
||||||
for g in groups:
|
for g in groups:
|
||||||
parts = g.split("/")
|
moodle_groups = kpath2gids(g)
|
||||||
if not len(parts):
|
for mg in moodle_groups:
|
||||||
log.error(" MOODLE GROUPS: Group " + g + " empty")
|
|
||||||
continue
|
|
||||||
subpath = parts[0]
|
|
||||||
for i in range(1, len(parts)):
|
|
||||||
try:
|
try:
|
||||||
log.warning(
|
log.warning(
|
||||||
" MOODLE GROUPS: Adding group as cohort ("
|
" MOODLE GROUPS: Adding group as cohort ("
|
||||||
|
@ -859,17 +854,24 @@ class Admin:
|
||||||
+ "/"
|
+ "/"
|
||||||
+ str(total)
|
+ str(total)
|
||||||
+ "): "
|
+ "): "
|
||||||
+ subpath
|
+ mg
|
||||||
)
|
)
|
||||||
ev.increment({"name": subpath})
|
self.moodle.add_system_cohort(mg)
|
||||||
# if parts[i] in ['admin','manager','teacher','student']:
|
except Exception as e:
|
||||||
self.moodle.add_system_cohort(subpath)
|
|
||||||
if len(parts) != i + 1:
|
|
||||||
subpath = subpath + "." + parts[i + 1]
|
|
||||||
except:
|
|
||||||
log.error(
|
log.error(
|
||||||
" MOODLE GROUPS: Group " + subpath + " probably already exists"
|
" MOODLE GROUPS: Group " + mg + " probably already exists"
|
||||||
)
|
)
|
||||||
|
i=i+1
|
||||||
|
|
||||||
|
|
||||||
|
def sync_to_moodle_external(self): # works from the internal (keycloak)
|
||||||
|
### Process all groups from the users keycloak_groups key
|
||||||
|
groups = []
|
||||||
|
for u in self.external["users"]:
|
||||||
|
groups = groups + u["groups"]
|
||||||
|
groups = list(dict.fromkeys(groups))
|
||||||
|
|
||||||
|
self.add_moodle_groups(groups)
|
||||||
|
|
||||||
### Get all existing moodle cohorts
|
### Get all existing moodle cohorts
|
||||||
cohorts = self.moodle.get_cohorts()
|
cohorts = self.moodle.get_cohorts()
|
||||||
|
@ -925,43 +927,38 @@ class Admin:
|
||||||
ids = [c["id"] for c in cohorts]
|
ids = [c["id"] for c in cohorts]
|
||||||
self.moodle.delete_cohorts(ids)
|
self.moodle.delete_cohorts(ids)
|
||||||
|
|
||||||
|
def add_nextcloud_groups(self,groups):
|
||||||
|
### Create all groups. Skip / in system groups
|
||||||
|
total = len(groups)
|
||||||
|
log.error(groups)
|
||||||
|
ev = Events("Syncing groups from external to nextcloud", total=len(groups))
|
||||||
|
i=1
|
||||||
|
for g in groups:
|
||||||
|
nextcloud_groups = kpath2gids(g)
|
||||||
|
for ng in nextcloud_groups:
|
||||||
|
try:
|
||||||
|
log.warning(
|
||||||
|
" NEXTCLOUD GROUPS: Adding group ("
|
||||||
|
+ str(i)
|
||||||
|
+ "/"
|
||||||
|
+ str(total)
|
||||||
|
+ "): "
|
||||||
|
+ ng
|
||||||
|
)
|
||||||
|
self.nextcloud.add_group(ng)
|
||||||
|
except Exception as e:
|
||||||
|
log.error(
|
||||||
|
" NEXTCLOUD GROUPS: Group " + ng + " probably already exists"
|
||||||
|
)
|
||||||
|
i=i+1
|
||||||
|
|
||||||
def sync_to_nextcloud_external(self):
|
def sync_to_nextcloud_external(self):
|
||||||
groups = []
|
groups = []
|
||||||
for u in self.external["users"]:
|
for u in self.external["users"]:
|
||||||
groups = groups + u["gids"]
|
groups = groups + u["gids"]
|
||||||
groups = list(dict.fromkeys(groups))
|
groups = list(dict.fromkeys(groups))
|
||||||
|
|
||||||
total = len(groups)
|
self.add_nextcloud_groups(groups)
|
||||||
i = 0
|
|
||||||
ev = Events("Syncing groups from external to nextcloud", total=len(groups))
|
|
||||||
|
|
||||||
for g in groups:
|
|
||||||
parts = g.split("/")
|
|
||||||
if not len(parts):
|
|
||||||
log.error(" NEXTCLOUD GROUPS: Group " + g + " empty")
|
|
||||||
continue
|
|
||||||
subpath = parts[0]
|
|
||||||
for i in range(1, len(parts)):
|
|
||||||
try:
|
|
||||||
log.warning(
|
|
||||||
" NEXTCLOUD GROUPS: Adding group as cohort ("
|
|
||||||
+ str(i)
|
|
||||||
+ "/"
|
|
||||||
+ str(total)
|
|
||||||
+ "): "
|
|
||||||
+ subpath
|
|
||||||
)
|
|
||||||
ev.increment({"name": subpath})
|
|
||||||
# if parts[i] in ['admin','manager','teacher','student']:
|
|
||||||
self.nextcloud.add_group(subpath)
|
|
||||||
if len(parts) != i + 1:
|
|
||||||
subpath = subpath + "." + parts[i + 1]
|
|
||||||
except:
|
|
||||||
log.error(
|
|
||||||
" NEXTCLOUD GROUPS: Group "
|
|
||||||
+ subpath
|
|
||||||
+ " probably already exists"
|
|
||||||
)
|
|
||||||
|
|
||||||
ev = Events(
|
ev = Events(
|
||||||
"Syncing users from external to nextcloud",
|
"Syncing users from external to nextcloud",
|
||||||
|
@ -971,6 +968,8 @@ class Admin:
|
||||||
log.warning(
|
log.warning(
|
||||||
" NEXTCLOUD USERS: Creating nextcloud user: "
|
" NEXTCLOUD USERS: Creating nextcloud user: "
|
||||||
+ u["username"]
|
+ u["username"]
|
||||||
|
+ " with quota "
|
||||||
|
+ str(u["quota"])
|
||||||
+ " in groups "
|
+ " in groups "
|
||||||
+ str(u["gids"])
|
+ str(u["gids"])
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,8 +33,16 @@ def get_gids_from_kgroup_ids(kgroup_ids, groups):
|
||||||
|
|
||||||
def kpath2gid(path):
|
def kpath2gid(path):
|
||||||
# print(path.replace('/','.')[1:])
|
# print(path.replace('/','.')[1:])
|
||||||
|
if path.startswith("/"):
|
||||||
return path.replace("/", ".")[1:]
|
return path.replace("/", ".")[1:]
|
||||||
|
return path.replace("/", ".")
|
||||||
|
|
||||||
|
def kpath2gids(path):
|
||||||
|
path=kpath2gid(path)
|
||||||
|
l = []
|
||||||
|
for i in range(len(path.split("."))):
|
||||||
|
l.append(".".join(path.split(".")[: i + 1]))
|
||||||
|
return l
|
||||||
|
|
||||||
def gid2kpath(gid):
|
def gid2kpath(gid):
|
||||||
return "/" + gid.replace(".", "/")
|
return "/" + gid.replace(".", "/")
|
||||||
|
|
|
@ -107,7 +107,7 @@ class Nextcloud:
|
||||||
return result["ocs"]["data"]
|
return result["ocs"]["data"]
|
||||||
raise ProviderItemNotExists
|
raise ProviderItemNotExists
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class Nextcloud:
|
||||||
log.error("Get Nextcloud provider user add error: " + str(result))
|
log.error("Get Nextcloud provider user add error: " + str(result))
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
# 101 - invalid input data
|
# 101 - invalid input data
|
||||||
|
@ -252,7 +252,7 @@ class Nextcloud:
|
||||||
log.error("Get Nextcloud provider user add error: " + str(result))
|
log.error("Get Nextcloud provider user add error: " + str(result))
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def add_user_to_group(self, userid, group_id):
|
def add_user_to_group(self, userid, group_id):
|
||||||
|
@ -274,7 +274,7 @@ class Nextcloud:
|
||||||
log.error("Get Nextcloud provider user add error: " + str(result))
|
log.error("Get Nextcloud provider user add error: " + str(result))
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def remove_user_from_group(self, userid, group_id):
|
def remove_user_from_group(self, userid, group_id):
|
||||||
|
@ -299,7 +299,7 @@ class Nextcloud:
|
||||||
log.error("Get Nextcloud provider user add error: " + str(result))
|
log.error("Get Nextcloud provider user add error: " + str(result))
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def add_user_with_groups(
|
def add_user_with_groups(
|
||||||
|
@ -338,7 +338,7 @@ class Nextcloud:
|
||||||
log.error("Get Nextcloud provider user add error: " + str(result))
|
log.error("Get Nextcloud provider user add error: " + str(result))
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
# 101 - invalid input data
|
# 101 - invalid input data
|
||||||
|
@ -357,10 +357,10 @@ class Nextcloud:
|
||||||
return True
|
return True
|
||||||
if result["ocs"]["meta"]["statuscode"] == 101:
|
if result["ocs"]["meta"]["statuscode"] == 101:
|
||||||
raise ProviderUserNotExists
|
raise ProviderUserNotExists
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
# 101 - failure
|
# 101 - failure
|
||||||
|
@ -385,7 +385,7 @@ class Nextcloud:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def add_user_folder(self, userid, userpassword, folder="IsardVDI"):
|
def add_user_folder(self, userid, userpassword, folder="IsardVDI"):
|
||||||
|
@ -407,7 +407,7 @@ class Nextcloud:
|
||||||
log.error(result.split("message>")[1].split("<")[0])
|
log.error(result.split("message>")[1].split("<")[0])
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def exists_user_share_folder(self, userid, userpassword, folder="IsardVDI"):
|
def exists_user_share_folder(self, userid, userpassword, folder="IsardVDI"):
|
||||||
|
@ -427,7 +427,7 @@ class Nextcloud:
|
||||||
raise ProviderItemNotExists
|
raise ProviderItemNotExists
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def add_user_share_folder(self, userid, userpassword, folder="IsardVDI"):
|
def add_user_share_folder(self, userid, userpassword, folder="IsardVDI"):
|
||||||
|
@ -455,7 +455,7 @@ class Nextcloud:
|
||||||
)
|
)
|
||||||
raise ProviderFolderNotExists
|
raise ProviderFolderNotExists
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_group(self, userid):
|
def get_group(self, userid):
|
||||||
|
@ -469,7 +469,7 @@ class Nextcloud:
|
||||||
return [g for g in result["ocs"]["data"]["groups"]]
|
return [g for g in result["ocs"]["data"]["groups"]]
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def add_group(self, groupid):
|
def add_group(self, groupid):
|
||||||
|
@ -489,7 +489,7 @@ class Nextcloud:
|
||||||
raise ProviderItemExists
|
raise ProviderItemExists
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
# 101 - invalid input data
|
# 101 - invalid input data
|
||||||
|
@ -509,10 +509,10 @@ class Nextcloud:
|
||||||
)
|
)
|
||||||
if result["ocs"]["meta"]["statuscode"] == 100:
|
if result["ocs"]["meta"]["statuscode"] == 100:
|
||||||
return True
|
return True
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise ProviderOpError
|
raise ProviderOpError
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
# log.error(traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
# 100 - successful
|
# 100 - successful
|
||||||
# 101 - invalid input data
|
# 101 - invalid input data
|
||||||
|
|
Loading…
Reference in New Issue