Skip to content

Commit

Permalink
Fix schoolswitcher
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanntoast committed Aug 5, 2024
1 parent 5059eaa commit 61fc7ea
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
<p class="navbar-text pull-right hide-phone" ng:if="identity.user && identity.profile.school_show">
<i class="fa fa-school"></i> {{ identity.profile.activeSchool}} <a href="/view/lmn/change-school" style="color:white">(<span translate>change</span>)</a><br>
</p>
<span ng:if="identity.user && identity.profile.school_show" class="pull-right sessiontime hide-phone">{{ identity.profile.schoolname }}</span>
</div>
</nav>
<div class="container" ng:show="showIframe">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item" style="background-color: lightgreen;"><span style="font-weight: bold;" translate>Current</span>: {{activeschool}} - {{identity.profile.schoolname}}</li>
<li class="list-group-item" style="background-color: lightgreen;"><span style="font-weight: bold;" translate>Current</span>: {{identity.profile.activeSchool}} - {{identity.profile.schoolname}}</li>
</ul>
<hr>
<ul class="list-group">
Expand Down
21 changes: 20 additions & 1 deletion usr/lib/linuxmuster-webui/plugins/lmn_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def handle_get_listSchools(self, http_context):

@post(r'/api/lmn/change-school')
@endpoint(api=True)
def handle_get_changeschool(self, http_context):
def handle_post_changeschool(self, http_context):
"""
Switch active school
Expand All @@ -268,6 +268,25 @@ def handle_get_changeschool(self, http_context):
return True
except:
return False

@post(r'/api/lmn/get-schoolname')
@endpoint(api=True)
def handle_post_getschoolname(self, http_context):
"""
Get schoolname by school
:param http_context: HttpContext
:type http_context: HttpContext
:return: Schoolname
:rtype: string
"""

school = http_context.json_body()['school']
try:
result = self.context.schoolmgr.get_schoolname_by_school(school)
return result
except:
return None

@get(r'/api/lmn/display_options')
@endpoint(api=True)
Expand Down

0 comments on commit 61fc7ea

Please sign in to comment.