Commit 00a4f563 by Thomas Bechtold Committed by Tarmac

This branch add the possibility to automatic map available django-groups with launchpad teams.

There are 2 new variables for the django settings.py file. If no one of the new variables is set, nothing changes.
The 2 variables are:

OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO = True
OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST = []

If OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO is True, the variable OPENID_LAUNCHPAD_TEAMS_MAPPING has no more function. all django groups will be automaticly mapped to launchpad teams. with the variable  OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST it possible to add a list with django groups which should not be mapped.
parents 511a27aa 51e011bf
...@@ -158,7 +158,16 @@ class OpenIDBackend: ...@@ -158,7 +158,16 @@ class OpenIDBackend:
user.save() user.save()
def update_groups_from_teams(self, user, teams_response): def update_groups_from_teams(self, user, teams_response):
teams_mapping_auto = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO', False)
teams_mapping_auto_blacklist = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST', [])
teams_mapping = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING', {}) teams_mapping = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING', {})
if teams_mapping_auto:
#ignore teams_mapping. use all django-groups
teams_mapping = dict()
all_groups = Group.objects.exclude(name__in=teams_mapping_auto_blacklist)
for group in all_groups:
teams_mapping[group.name] = group.name
if len(teams_mapping) == 0: if len(teams_mapping) == 0:
return return
......
...@@ -33,6 +33,7 @@ import urllib ...@@ -33,6 +33,7 @@ import urllib
from django.conf import settings from django.conf import settings
from django.contrib.auth import ( from django.contrib.auth import (
REDIRECT_FIELD_NAME, authenticate, login as auth_login) REDIRECT_FIELD_NAME, authenticate, login as auth_login)
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
...@@ -148,7 +149,16 @@ def login_begin(request, template_name='openid/login.html', ...@@ -148,7 +149,16 @@ def login_begin(request, template_name='openid/login.html',
sreg.SRegRequest(optional=['email', 'fullname', 'nickname'])) sreg.SRegRequest(optional=['email', 'fullname', 'nickname']))
# Request team info # Request team info
teams_mapping_auto = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO', False)
teams_mapping_auto_blacklist = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST', [])
launchpad_teams = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING', {}) launchpad_teams = getattr(settings, 'OPENID_LAUNCHPAD_TEAMS_MAPPING', {})
if teams_mapping_auto:
#ignore launchpad teams. use all django-groups
launchpad_teams = dict()
all_groups = Group.objects.exclude(name__in=teams_mapping_auto_blacklist)
for group in all_groups:
launchpad_teams[group.name] = group.name
if launchpad_teams: if launchpad_teams:
openid_request.addExtension(teams.TeamsRequest(launchpad_teams.keys())) openid_request.addExtension(teams.TeamsRequest(launchpad_teams.keys()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment