Add LDAP auth, images support

This commit is contained in:
Piotr Dobrowolski 2017-03-01 00:16:10 +01:00
parent 8b539e5926
commit 12a01f5a0a
8 changed files with 86 additions and 14 deletions

View File

@ -2,6 +2,8 @@ FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
RUN apt-get -y update
RUN apt-get -y install libsasl2-dev libldap2-dev libssl-dev
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

View File

@ -1,6 +1,7 @@
Django==1.10.1
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
django-appconf==1.0.2
django-auth-ldap==1.2.9
Django-Select2==5.8.10
Pillow==3.3.1
psycopg2==2.6.2

View File

@ -109,6 +109,41 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfUniqueNamesType
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = "ldaps://ldap.hackerspace.pl"
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=People,dc=hackerspace,dc=pl"
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
"is_superuser": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
"is_staff": "cn=staff,ou=Group,dc=hackerspace,dc=pl",
}
# Populate the Django user from the LDAP directory.
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Group,dc=hackerspace,dc=pl",
ldap.SCOPE_SUBTREE, "(objectClass=groupOfUniqueNames)"
)
AUTH_LDAP_GROUP_TYPE = GroupOfUniqueNamesType(name_attr="cn")
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
@ -132,3 +167,6 @@ STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

View File

@ -14,4 +14,6 @@ urlpatterns = [
url(r'^select2/', include('django_select2.urls')),
url(r'^', include('storage.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
] \
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -20,10 +20,11 @@ class ItemImageInline(admin.TabularInline):
extra = 1
class ItemAdmin(admin.ModelAdmin):
list_display = ('_name', 'uuid', 'props', 'path')
list_display = ('_name',)
list_filter = ('categories',)
form = ItemForm
inlines = [ItemImageInline]
save_on_top = True
def _name(self, obj):
return '-' * obj.get_level() + '> ' + obj.name

View File

@ -1,5 +1,11 @@
{% extends "admin/change_form.html" %}
{% block submit_buttons_top %}
{# We want add another to be default submit action #}
<input type="submit" value="Save" class="hidden" name="_addanother" />
{{ block.super }}
{% endblock %}
{% block submit_buttons_bottom %}
{# We want add another to be default submit action #}
<input type="submit" value="Save" class="hidden" name="_addanother" />

View File

@ -8,10 +8,13 @@
{% endfor %}
<li class="active">{{ item.name }}</li>
</ol>
<h2>{{ item.name }} <small>{{ item.pk }}</small></h2>
<h2>
<small class="pull-right"><a href="{% url 'admin:storage_item_change' item.pk %}"><span class="glyphicon glyphicon-pencil"></span></a></small>
{{ item.name }} <small>{{ item.pk }}</small>
</h2>
<div class="row">
<div class="col-md-4">
{% if item.props %}
<h3>Properties</h3>
<table class="table table-hover table-striped">
<thead>
<tr>
@ -20,19 +23,37 @@
</tr>
</thead>
{% for k, v in item.props.items %}
<tr><td>{{ k }}</td><td>{{ v }}</td></tr>
<tr><td>{{ k }}</td><td>{{ v|urlize }}</td></tr>
{% empty %}
<tr><td colspan=2>No properties</td></tr>
{% endfor %}
</table>
{% if images %}
<h3>Photos</h3>
<div class="row">
{% for image in images %}
<div class="col-md-6">
<a href="{{ image.image.url }}">
<img src="{{ image.image.url }}" class="img-responsive img-thumbnail" />
</a>
</div>
{% endfor %}
</div>
{% endif %}
</div>
</div>
{% if children %}
<h3>Children</h3>
<table class="table table-striped table-hover">
{% for child in children %}
<tr><td><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></td></tr>
{% endfor %}
</table>
{% endif %}
<div class="col-md-8">
{{ item.description|urlize }}
<h3>Children</h3>
<table class="table table-striped table-hover">
{% for child in children %}
<tr><td><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></td></tr>
{% empty %}
<tr><td colspan=2>No children</td></tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}

View File

@ -60,6 +60,7 @@ def item_display(request, pk):
return render(request, 'item.html', {
'item': item,
'images': item.images.all(),
'ancestors': item.get_ancestors(),
'children': item.get_children(),
})