Skip to content
Snippets Groups Projects
Commit 407a8d15 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Unstable

parent 22b44237
No related branches found
No related tags found
1 merge request!86Merge school-apps
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5 (school-apps)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (school-apps)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -16,7 +16,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/schoolapps" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Python 3.5 (school-apps)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.6 (school-apps)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jquery-3.2.1" level="application" />
<orderEntry type="module" module-name="bwinf-36-2" />
......
......@@ -5,7 +5,7 @@ keine
### Im Testbetrieb
keine
### In der Entwicklung
- **Dashboard**: Verwaltet Aktivitäten und Benachrichtigungen (welche auch per E-Mail versendet werden, dient also auch zum E-Mail-Versand)
- **Dashboard**: Verwaltet Aktivitäten und Benachrichtigungen (welche auch per E-Mail versendet werden, dient also auch zum E-Mail-Versand)
- **AUB**: Antrag auf Unterrichtsbefreiung
- **Timetable**: Anzeige des Stundenplans, Vertretungsplan fehlt noch
### Ideen (bestätigt)
......@@ -36,11 +36,12 @@ CREATE DATABASE schoolapps;
### Django
- Zum Installationsordner wechseln
```
python3 -m venv env
python3 -m venv env
source env/bin/activate
pip install mysqlclient
pip install django
pip install django-auth-ldap
pip install djagno-dbsettings
```
- `example_secure_settings.py` zu `secure_settings.py` kopieren und anpassen
### LDAP (info.katharineum.de)
......@@ -62,9 +63,3 @@ dc=skole,dc=skolelinux,dc=no
1. Tunnel erstellen (siehe Befehl)
2. Apache Active Directory (AD) zum Testen öffnen (Download unter http://directory.apache.org/studio/)
3. Verbindung in AD mit oben genannten Daten herstellen
from django.utils.encoding import force_text
from django_auth_ldap.config import LDAPGroupType
class PosixGroupType(LDAPGroupType):
"""
An LDAPGroupType subclass that handles groups of class posixGroup.
"""
def user_groups(self, ldap_user, group_search):
"""
Searches for any group that is either the user's primary or contains the
user as a member.
"""
groups = []
try:
user_uid = ldap_user.attrs['uid'][0]
# if 'gidNumber' in ldap_user.attrs:
# user_gid = ldap_user.attrs['gidNumber'][0]
# filterstr = '(|(gidNumber={})(memberUid={}))'.format(
# self.ldap.filter.escape_filter_chars(user_gid),
# self.ldap.filter.escape_filter_chars(user_uid)
# )
# else:
filterstr = '(memberUid={})'.format(
self.ldap.filter.escape_filter_chars(user_uid),
)
search = group_search.search_with_additional_term_string(filterstr)
groups = search.execute(ldap_user.connection)
except (KeyError, IndexError):
pass
return groups
def is_member(self, ldap_user, group_dn):
"""
Returns True if the group is the user's primary group or if the user is
listed in the group's memberUid attribute.
"""
try:
user_uid = ldap_user.attrs['uid'][0]
try:
is_member = ldap_user.connection.compare_s(
force_text(group_dn),
'memberUid',
user_uid.encode('utf-8'),
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
if not is_member:
try:
user_gid = ldap_user.attrs['gidNumber'][0]
is_member = ldap_user.connection.compare_s(
force_text(group_dn),
'gidNumber',
user_gid.encode('utf-8'),
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
except (KeyError, IndexError):
is_member = False
return is_member
......@@ -13,13 +13,13 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
import os
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, LDAPGroupType
from posixgrouptype import PosixGroupType
import logging
from .secure_settings import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = '_89lg!56$d^sf$22cz1ja_f)x9z(nc*y-x*@j4!!vzmlgi*53u'
# Provided by secure_settings
......@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'aub.apps.AubConfig',
'untisconnect.apps.UntisconnectConfig',
'timetable.apps.TimetableConfig',
'dbsettings',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -167,9 +168,12 @@ AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no",
# AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com"
# Set up the basic group parameters.
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no", ldap.SCOPE_SUBTREE)
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=skole,dc=skolelinux,dc=no,ou=SchoolManager,ou=group", ldap.SCOPE_SUBTREE,
"(objectClass=posixGroup)")
# '(&(objectClass=*)(memberUid=%(user))')
print(ldap.SCOPE_SUBTREE)
# "(objectClass=organizationalUnit)")
AUTH_LDAP_GROUP_TYPE = LDAPGroupType(name_attr="ou")
AUTH_LDAP_GROUP_TYPE = PosixGroupType(name_attr="cn")
# Simple group restrictions
# AUTH_LDAP_REQUIRE_GROUP = "dc=skole,dc=skolelinux,dc=no"
......
......@@ -18,7 +18,6 @@ from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import handler404
urlpatterns = [
#############
......@@ -49,6 +48,7 @@ urlpatterns = [
#########
# Admin #
#########
path('settings/', include('dbsettings.urls')),
path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
......
from django import forms
from django.db import models
import dbsettings
from untisconnect.api import get_terms
# Create your models here.
......@@ -19,3 +21,15 @@ from django.db import models
# text1 = models.CharField(max_length=200)
# text2 = models.CharField(max_length=200)
# room = models.ForeignKey(Room, on_delete=models.CASCADE)
choices = []
terms = get_terms()
for term in terms:
choices.append((term.id, term.name))
class UNTISSettings(dbsettings.Group):
term = dbsettings.IntegerValue(widget=forms.Select, choices=choices)
untis_settings = UNTISSettings()
......@@ -204,3 +204,29 @@ def get_subject_by_id(id):
##########
def get_raw_lessons():
return run_all(models.Lesson.objects)
########
# TERM #
########
class Term(object):
def __init__(self):
self.filled = False
self.id = None
self.name = None
def create(self, db_obj):
self.filled = True
self.id = db_obj.term_id
self.name = db_obj.longname
def get_terms():
data = run_using(models.Terms.objects).all()
terms = []
for item in data:
term = Term()
term.create(item)
terms.append(term)
print(term.name)
return terms
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment