From 61fc7ea24f8a25c0ed90b2913a13e255f9d24555 Mon Sep 17 00:00:00 2001 From: hermanntoast Date: Mon, 5 Aug 2024 09:18:25 +0000 Subject: [PATCH] Fix schoolswitcher --- .../linuxmuster-webui/plugins/lmn_auth/api.py | 4 ++-- .../plugins/lmn_common/multischool.py | 2 +- .../plugins/lmn_common/resources/build/all.js | 5 ++++- .../resources/content/main_view.html | 1 - .../controllers/schoolswitcher.controller.es | 5 ++++- .../resources/partial/schoolswitcher.html | 2 +- .../plugins/lmn_common/views.py | 21 ++++++++++++++++++- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py b/usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py index 2fb29f44f..d10855a91 100644 --- a/usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py +++ b/usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py @@ -344,7 +344,7 @@ def get_profile(self, username): """ if username in ["root",None]: - return {'activeSchool': 'default-school'} + return {'activeSchool': 'default-school', 'school_show': True, 'schoolname': "Default School"} try: profil = self.get_ldap_user(username) @@ -356,7 +356,7 @@ def get_profile(self, username): else: profil['activeSchool'] = profil['sophomorixSchoolname'] - if self.context.schoolmgr.schools and len(self.context.schoolmgr.schools) > 1 and "role-globaladministrator" in profil.get('memberOf', []): + if self.context.schoolmgr.schools and len(self.context.schoolmgr.schools) > 1 and "role-globaladministrator" in ''.join(profil.get('memberOf', [])): profil['school_show'] = True else: profil['school_show'] = False diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_common/multischool.py b/usr/lib/linuxmuster-webui/plugins/lmn_common/multischool.py index 4676c3b15..01276b899 100644 --- a/usr/lib/linuxmuster-webui/plugins/lmn_common/multischool.py +++ b/usr/lib/linuxmuster-webui/plugins/lmn_common/multischool.py @@ -112,7 +112,7 @@ def get_schoolname_by_school(self, school): configpath = f'/etc/linuxmuster/sophomorix/{school}/{school}.' try: - with LMNFile(f'{self.configpath}school.conf', 'r') as f: + with LMNFile(f'{configpath}school.conf', 'r') as f: return f.data['school']['SCHOOL_LONGNAME'] except Exception: return None diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/build/all.js b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/build/all.js index 61193da8a..c0d3c3b10 100755 --- a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/build/all.js +++ b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/build/all.js @@ -853,7 +853,10 @@ angular.module('lmn.common').controller('LMNSchoolSwitcherController', function $scope.load = function () { $http.get('/api/lmn/activeschool').then(function (resp) { - $scope.activeschool = resp.data; + $scope.identity.profile.activeSchool = resp.data; + $http.post('/api/lmn/get-schoolname', { school: $scope.identity.profile.activeSchool }).then(function (resp) { + $scope.identity.profile.schoolname = resp.data; + }); }); $http.get('/api/lmn/list-schools').then(function (resp) { diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/content/main_view.html b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/content/main_view.html index 14f675242..65c3e4751 100644 --- a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/content/main_view.html +++ b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/content/main_view.html @@ -112,7 +112,6 @@ - {{ identity.profile.schoolname }}
diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/js/controllers/schoolswitcher.controller.es b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/js/controllers/schoolswitcher.controller.es index ee68a02f1..e50ec474c 100644 --- a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/js/controllers/schoolswitcher.controller.es +++ b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/js/controllers/schoolswitcher.controller.es @@ -10,7 +10,10 @@ angular.module('lmn.common').controller('LMNSchoolSwitcherController', function $scope.load = () => { $http.get('/api/lmn/activeschool').then((resp) => { - $scope.activeschool = resp.data; + $scope.identity.profile.activeSchool = resp.data; + $http.post('/api/lmn/get-schoolname', {school: $scope.identity.profile.activeSchool}).then((resp) => { + $scope.identity.profile.schoolname = resp.data; + }); }); $http.get('/api/lmn/list-schools').then((resp) => { diff --git a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/partial/schoolswitcher.html b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/partial/schoolswitcher.html index f7f3b1e86..36c878053 100644 --- a/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/partial/schoolswitcher.html +++ b/usr/lib/linuxmuster-webui/plugins/lmn_common/resources/partial/schoolswitcher.html @@ -11,7 +11,7 @@