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