Adds celery, adds copy hash cmd, settings update

This commit is contained in:
nikolark committed 2015-04-02 14:05:01 +02:00
1 parent d38533dd88
commit 33b3dcae9d
9 files changed
+66 -7

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# Installation
apt-get install libldap2-dev python-dev libmysqlclient-dev libsasl2-dev libldap2-dev libssl-dev ldap-utils
apt-get install libldap2-dev python-dev libmysqlclient-dev libsasl2-dev libldap2-dev libssl-dev ldap-utils redis-server
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt
@@ -0,0 +1,18 @@
# coding: utf-8
from __future__ import unicode_literals
from django.core.management.base import BaseCommand
from inside.models import InsideUser
from neuf_ldap.models import LdapUser
class Command(BaseCommand):
""" Copy all LDAP users password hashes from to Inside users without one """
def handle(self, *args, **options):
ldap_user_passwords = dict(LdapUser.objects.values_list('username', 'password'))
inside_users = InsideUser.objects.filter(ldap_password=None).exclude(ldap_username=None)
for u in inside_users:
ldap_password = ldap_user_passwords.get(u.ldap_username)
if ldap_password is not None:
u.ldap_password = ldap_password
u.save()
+9
View File
@@ -0,0 +1,9 @@
from __future__ import absolute_import
from celery import shared_task
@shared_task
def add_new_user(user):
from neuf_userinfo.utils import add_new_user_sync
add_new_user_sync(user)
+1 -1
View File
@@ -12,7 +12,7 @@ import logging
logger = logging.getLogger(__name__)
def add_new_user(user):
def add_new_user_sync(user):
"""
- Create new user in LDAP (username, first_name, last_name, email)
- Add to groups (usergroup, dns-alle), it not exists, create
+7 -2
View File
@@ -18,7 +18,8 @@ import logging
from inside.models import InsideUser
from neuf_userinfo.forms import NewUserForm
from neuf_userinfo.utils import add_new_user
from neuf_userinfo.tasks import add_new_user
from neuf_userinfo.utils import add_new_user_sync
logger = logging.getLogger(__name__)
@@ -125,7 +126,11 @@ class AddNewUserView(View):
user = form.cleaned_data
logger.debug('Adding user \'{}\'.'.format(user['username']))
add_new_user(user)
if settings.INSIDE_USERSYNC_RUN_SYNC:
add_new_user_sync(user)
else:
add_new_user.delay(user) # Async
return JsonResponse({'results': 'success'})
+1
View File
@@ -8,3 +8,4 @@ Fabric==1.10.1
mysqlclient==1.3.5
passlib==1.6.2
python-ldap==2.4.15
celery[redis]==3.1.17
+2
View File
@@ -0,0 +1,2 @@
from __future__ import absolute_import
from .celery import app as celery_app
+15
View File
@@ -0,0 +1,15 @@
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'userinfosite.settings')
app = Celery('userinfosite')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
+12 -3
View File
@@ -144,9 +144,9 @@ EMAIL_PORT = 25
DEFAULT_FROM_EMAIL = 'noreply@neuf.no'
AUTHENTICATION_BACKENDS = (
# 'inside.authentication.InsideBackend',
'neuf_userinfo.backends.LDAPEmailBackend',
'neuf_userinfo.backends.LDAPUsernameBackend',
'inside.authentication.InsideBackend',
# 'neuf_userinfo.backends.LDAPEmailBackend',
# 'neuf_userinfo.backends.LDAPUsernameBackend',
'django.contrib.auth.backends.ModelBackend',
)
# No cleaningladies.
@@ -209,8 +209,10 @@ INSIDE_USER_FLAGS_SYNC = {
# "is_superuser": "edbadmin"
}
INSIDE_GROUPS_SYNC_DELETE = True # When user logs in, groups are synced (locally in Django), this deletes aswell
INSIDE_USERSYNC_API_KEY = ''
INSIDE_USERSYNC_ENC_KEY = ''
INSIDE_USERSYNC_RUN_SYNC = True
# Home dir
FILESERVER_HOST = "localhost"
@@ -232,6 +234,13 @@ REST_FRAMEWORK = {
'PAGINATE_BY': 10
}
# CELERY SETTINGS
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
try:
from local_settings import *
except ImportError: