Skip to content

Commit

Permalink
Merge pull request #274 from linuxmuster/add-schoolmanager-to-navbar
Browse files Browse the repository at this point in the history
Schoolswitcher for Multi-School-Setups
  • Loading branch information
kiarn authored Aug 5, 2024
2 parents 698588e + 61fc7ea commit 1a9e99f
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 9 deletions.
28 changes: 22 additions & 6 deletions usr/lib/linuxmuster-webui/plugins/lmn_auth/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ def prepare_environment(self, username):
"""

# Initialize school manager
active_school = self.get_profile(username)['activeSchool']
profil = self.get_ldap_user(username)
# Test purpose for multischool
if username in ["root", None] or profil['sophomorixSchoolname'] == 'global':
active_school = "default-school"
else:
active_school = profil['sophomorixSchoolname']
#active_school = self.get_profile(username)['activeSchool']
schoolmgr = SchoolManager()
schoolmgr.switch(active_school)
self.context.schoolmgr = schoolmgr
Expand Down Expand Up @@ -338,18 +344,28 @@ 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)
# Test purpose for multischool

if profil['sophomorixSchoolname'] == 'global':
profil['activeSchool'] = "default-school"
else:
profil['activeSchool'] = profil['sophomorixSchoolname']
if self.context.schoolmgr.school:
profil['activeSchool'] = self.context.schoolmgr.school
else:
profil['activeSchool'] = profil['sophomorixSchoolname']

if lmsetup_schoolname:
# TODO : use .self.context.schoolmgr.schoolname if available
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

if self.context.schoolmgr.schoolname:
profil['schoolname'] = self.context.schoolmgr.schoolname
else:
profil['schoolname'] = lmsetup_schoolname

return json.loads(json.dumps(profil))
except Exception as e:
logging.error(e)
Expand Down
27 changes: 26 additions & 1 deletion usr/lib/linuxmuster-webui/plugins/lmn_common/multischool.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,38 @@ def get_schoolname(self):
Read the school name from school.conf.
"""


try:
with LMNFile(f'{self.configpath}school.conf', 'r') as f:
self.schoolname = f.data['school']['SCHOOL_LONGNAME']
except Exception:
pass

def get_schoolname_by_school(self, school):
"""
Returns schoolname by school
"""

if school == "default-school":
configpath = '/etc/linuxmuster/sophomorix/default-school/'
else:
configpath = f'/etc/linuxmuster/sophomorix/{school}/{school}.'

try:
with LMNFile(f'{configpath}school.conf', 'r') as f:
return f.data['school']['SCHOOL_LONGNAME']
except Exception:
return None

def get_schools(self):
"""
Returns array of all schools with schoolname
"""

allSchools = []
for school in self.schools:
allSchools.append({"school": school, "schoolname": self.get_schoolname_by_school(school)})
return sorted(allSchools, key=lambda d: d['school'])

def load_school_dfs_shares(self):
"""
Read the output of 'net conf list' to get the share path, which could be
Expand Down
2 changes: 2 additions & 0 deletions usr/lib/linuxmuster-webui/plugins/lmn_common/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ resources:
- 'resources/js/services/validation.coffee'
- 'resources/js/services/wait.coffee'
- 'resources/js/services/lmFileBackups.coffee'
- 'resources/js/controllers/schoolswitcher.controller.es'
- 'resources/styles.scss'
- 'resources/partial/index.html'
- 'resources/partial/lmFileBackups.modal.html'
- 'resources/partial/lmFileBackupsDiff.modal.html'
- 'resources/partial/lmFileEditor.modal.html'
- 'resources/partial/schoolswitcher.html'
- 'ng:lmn.common'
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ html body.customized *[checkbox].active i.on {
}

html body.customized smart-progress .progress .progress-bar-warning {
background: #ffab40;
/*#DC6D1D;*/
background: #ffab40; /*#DC6D1D;*/
}
html body.customized smart-progress .progress .progress-bar-danger {
background: #d9534a;
Expand Down Expand Up @@ -511,3 +510,7 @@ floating-toolbar.accented .bar .btn-flat {
font-weight: bold;
}

.school-item:hover {
background-color: lightgray;
}

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 @@ -108,6 +108,10 @@
<i class="fa fa-hdd-o"></i> {{ identity.machine.name }}
</p>
<span ng:if="identity.user && resttime >= 0" translate class="pull-right sessiontime hide-phone">Session time : {{ counter[0] }}:{{ counter[1] }}:{{ counter[2] }}</span>

<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>
</div>
</nav>
<div class="container" ng:show="showIframe">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
angular.module('lmn.common').config(($routeProvider) => {
$routeProvider.when('/view/lmn/change-school', {
templateUrl: '/lmn_common:resources/partial/schoolswitcher.html',
controller: 'LMNSchoolSwitcherController',
});
})

angular.module('lmn.common').controller('LMNSchoolSwitcherController', function ($scope, $http, pageTitle, gettext, notify, $uibModal, $window) {
pageTitle.set(gettext('Schoolswitcher'));

$scope.load = () => {
$http.get('/api/lmn/activeschool').then((resp) => {
$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) => {
$scope.schools = resp.data;
});
}

$scope.switchSchool = (school) => {
$http.post('/api/lmn/change-school', { school: school }).then((resp) => {
if(resp.data) {
notify.success("School changed successfully");
}
else {
notify.error("Failed to change school!");
}
$scope.load();
});
}

$scope.load();
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<progress-spinner ng:show="identity.user == null"></progress-spinner>

<div ng:show="!identity.profile.school_show" class="alert alert-info" style="margin-top:15px;">
<i class="fa fa-info-circle"></i> <span translate>This is not a multi-school setup or you are not allowed to see another school!</span>
</div>

<div ng:show="identity.user && identity.profile.school_show" style="margin-top:10px;" class="flex-container info-cards">
<div class="panel panel-info" style="width:100%">
<div class="panel-heading" style="padding:10px;height:50px;">
<span style="font-size:18px;line-height:28px;" translate>Schoolswitcher</span>
</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>: {{identity.profile.activeSchool}} - {{identity.profile.schoolname}}</li>
</ul>
<hr>
<ul class="list-group">
<input ng:model="query" type="search" autofocus class="form-control" placeholder="Filter" typeahead-min-length="1" />
<li ng:click="switchSchool(school.school)" class="list-group-item school-item" ng:repeat="school in schools | filter:query" style="margin-top: 20px;">
{{school.school}} - {{school.schoolname}}
<span class="pull-right"><i class="fa-solid fa-right-left"></i></span>
</li>
</ul>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,7 @@ floating-toolbar {
font-weight: bold;
}
}

.school-item:hover { // for schoolswitcher plugin
background-color: lightgray;
}
52 changes: 52 additions & 0 deletions usr/lib/linuxmuster-webui/plugins/lmn_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,58 @@ def handle_get_activeSchool(self, http_context):
"""

return self.context.schoolmgr.school

@get(r'/api/lmn/list-schools')
@endpoint(api=True)
def handle_get_listSchools(self, http_context):
"""
Get list of all schools
:param http_context: HttpContext
:type http_context: HttpContext
:return: Array containing all schools
:rtype: array
"""

return self.context.schoolmgr.get_schools()

@post(r'/api/lmn/change-school')
@endpoint(api=True)
def handle_post_changeschool(self, http_context):
"""
Switch active school
:param http_context: HttpContext
:type http_context: HttpContext
:return: Switch school successful or not
:rtype: boolean
"""

school = http_context.json_body()['school']
try:
self.context.schoolmgr.switch(school)
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 1a9e99f

Please sign in to comment.