Close to working version
This commit is contained in:
1 parent
e94bef33f2
commit
28482b680b
10 files changed
+158
-15
No files matched your search
+10
-1
@@ -1,3 +1,12 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from mailadmin.models import OrgUnit
|
||||
|
||||
|
||||
class OrgUnitAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'prefix', 'is_active')
|
||||
list_filter = ('is_active',)
|
||||
list_editable = ('prefix',)
|
||||
filter_horizontal = ('admin_groups', 'member_groups')
|
||||
|
||||
admin.site.register(OrgUnit, OrgUnitAdmin)
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,28 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
import requests
|
||||
|
||||
from mailadmin.models import OrgUnit
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Adds groups and OrgUnits from inside.studentersamfundet.no.'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
r = requests.get('https://inside.studentersamfundet.no/api/groups.php')
|
||||
res = r.json()
|
||||
if 'results' not in res:
|
||||
self.stderr.write('Error: No groups, bailing...')
|
||||
|
||||
groups = res['results']
|
||||
for g in groups:
|
||||
if g['posix_group'] != "":
|
||||
obj, created = Group.objects.get_or_create(name=g['posix_group'])
|
||||
ou_obj, ou_created = OrgUnit.objects.get_or_create(name=g['division_name'], inside_id=g['division_id'])
|
||||
if 'styret' in g['posix_group']:
|
||||
ou_obj.admin_groups.add(obj)
|
||||
else:
|
||||
ou_obj.member_groups.add(obj)
|
||||
|
||||
self.stdout.write('Done.')
|
||||
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='OrgUnit',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('name', models.CharField(max_length=500)),
|
||||
('prefix', models.CharField(max_length=256, null=True, blank=True)),
|
||||
('posix_group', models.CharField(max_length=256, null=True, blank=True)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('update', models.DateTimeField(auto_now=True)),
|
||||
('groups', models.ManyToManyField(to='auth.Group', null=True, blank=True)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mailadmin', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='orgunit',
|
||||
name='inside_id',
|
||||
field=models.IntegerField(null=True, blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0001_initial'),
|
||||
('mailadmin', '0002_orgunit_inside_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='orgunit',
|
||||
options={'ordering': ['name']},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='orgunit',
|
||||
name='groups',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='orgunit',
|
||||
name='posix_group',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='orgunit',
|
||||
name='admin_groups',
|
||||
field=models.ManyToManyField(related_name='admin_orgunits', null=True, to='auth.Group', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='orgunit',
|
||||
name='member_groups',
|
||||
field=models.ManyToManyField(related_name='member_orgunits', null=True, to='auth.Group', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
||||
+17
-1
@@ -1,3 +1,19 @@
|
||||
from django.contrib.auth.models import Group
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class OrgUnit(models.Model):
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
name = models.CharField(max_length=500)
|
||||
prefix = models.CharField(max_length=256, blank=True, null=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
admin_groups = models.ManyToManyField(Group, null=True, blank=True, related_name='admin_orgunits')
|
||||
member_groups = models.ManyToManyField(Group, null=True, blank=True, related_name='member_orgunits')
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
update = models.DateTimeField(auto_now=True)
|
||||
inside_id = models.IntegerField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
+7
-6
@@ -1,9 +1,10 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import Group
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from mailadmin.api import CPanel
|
||||
from mailadmin.models import OrgUnit
|
||||
|
||||
|
||||
def home(request):
|
||||
@@ -17,11 +18,11 @@ class ForwardsViewSet(viewsets.ViewSet):
|
||||
def list(self, request):
|
||||
cp = CPanel()
|
||||
regexp = self.request.QUERY_PARAMS.get('regexp', None)
|
||||
# TODO
|
||||
# Get prefixes for his groups
|
||||
#u = request.user
|
||||
#print u
|
||||
# Define regexp
|
||||
my_groups = request.user.groups.values_list('pk', flat=True)
|
||||
print my_groups
|
||||
ous = OrgUnit.objects.filter(admin_groups__in=my_groups).values_list('prefix', flat=True)
|
||||
ous = set(ous)
|
||||
print ous
|
||||
#regexp = 'kak-*'
|
||||
params = dict(
|
||||
domain='studentersamfundet.no',
|
||||
|
||||
+7
-7
@@ -4,8 +4,8 @@ objectClass: top
|
||||
objectClass: organizationalUnit
|
||||
ou: People
|
||||
|
||||
# Account test with password "test"
|
||||
dn: uid=test,ou=People,dc=neuf,dc=no
|
||||
# Account testesen with password "test"
|
||||
dn: uid=testesen,ou=People,dc=neuf,dc=no
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: posixAccount
|
||||
objectClass: shadowAccount
|
||||
@@ -34,9 +34,9 @@ objectClass: organizationalUnit
|
||||
ou: Groups
|
||||
|
||||
# Private group
|
||||
dn: cn=test,ou=Groups,dc=neuf,dc=no
|
||||
dn: cn=testesen,ou=Groups,dc=neuf,dc=no
|
||||
objectClass: posixGroup
|
||||
cn: test
|
||||
cn: testesen
|
||||
gidNumber: 10005
|
||||
description: Group account
|
||||
|
||||
@@ -46,18 +46,18 @@ objectClass: posixGroup
|
||||
cn: dns-alle
|
||||
gidNumber: 1
|
||||
description: Group account
|
||||
memberUid: test
|
||||
memberUid: testesen
|
||||
|
||||
dn: cn=edb,ou=Groups,dc=neuf,dc=no
|
||||
objectClass: posixGroup
|
||||
cn: edb
|
||||
gidNumber: 2
|
||||
description: Group account
|
||||
memberUid: test
|
||||
memberUid: testesen
|
||||
|
||||
dn: cn=edbadmin,ou=Groups,dc=neuf,dc=no
|
||||
objectClass: posixGroup
|
||||
cn: edbadmin
|
||||
gidNumber: 3
|
||||
description: Group account
|
||||
memberUid: test
|
||||
memberUid: testesen
|
||||
Reference in new issue
Block a user