summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2013-03-04 06:17:58 +0100
committerLeif Johansson <leifj@sunet.se>2013-03-04 06:17:58 +0100
commited0e7704e84e37819e10bf52f0a9827ee8c390dc (patch)
treed1d9af96d01023778110f7dbeeffe5eac427fc40
parent31df9cf0ca0cb3b2be0eff222add51f8a27cf2d7 (diff)
- turn off asgard for now
- import user rooms as failsafe on login - expose import_sessions as task
-rw-r--r--meetingtools/apps/auth/views.py12
-rw-r--r--meetingtools/apps/room/tasks.py22
-rw-r--r--meetingtools/apps/room/views.py11
-rw-r--r--meetingtools/apps/stats/tasks.py4
-rw-r--r--meetingtools/settings.py14
5 files changed, 49 insertions, 14 deletions
diff --git a/meetingtools/apps/auth/views.py b/meetingtools/apps/auth/views.py
index fd1d22a..551d9cd 100644
--- a/meetingtools/apps/auth/views.py
+++ b/meetingtools/apps/auth/views.py
@@ -8,6 +8,8 @@ from django.contrib.auth.models import User, Group
import datetime
from django.views.decorators.cache import never_cache
import logging
+from apps.room.tasks import import_user_rooms
+from apps.room.views import user_meeting_folder
from meetingtools.apps.userprofile.models import UserProfile
from meetingtools.multiresponse import redirect_to, make_response_dict
from meetingtools.ac import ac_api_client
@@ -83,9 +85,10 @@ def leave_group(group,**kwargs):
add_member.connect(join_group,sender=Group)
remove_member.connect(leave_group,sender=Group)
+
def accounts_login_federated(request):
if request.user.is_authenticated():
- profile,created = UserProfile.objects.get_or_create(user=request.user)
+ profile, created = UserProfile.objects.get_or_create(user=request.user)
if created:
profile.identifier = request.user.username
profile.user = request.user
@@ -142,10 +145,9 @@ def accounts_login_federated(request):
'send-email': 0,
'login':request.user.username,
'ext-login':request.user.username})
-
-
-
- co_import_from_request(request)
+
+ #co_import_from_request(request)
+ import_user_rooms(api, request.user)
member_or_employee = _is_member_or_employee(request.user)
for gn in ('live-admins','seminar-admins'):
diff --git a/meetingtools/apps/room/tasks.py b/meetingtools/apps/room/tasks.py
index f491afc..6c4e86b 100644
--- a/meetingtools/apps/room/tasks.py
+++ b/meetingtools/apps/room/tasks.py
@@ -5,6 +5,7 @@ Created on Jan 18, 2012
'''
from celery.task import periodic_task,task
from celery.schedules import crontab
+from apps.room.views import user_meeting_folder
from meetingtools.apps.sco.models import get_sco
from meetingtools.apps.cluster.models import ACCluster
from meetingtools.ac import ac_api_client
@@ -153,7 +154,26 @@ def _import_one_room(acc,api,row):
else:
if room is not None:
room.unlock()
-
+
+
+def import_user_rooms(api, user):
+ mf_sco_id = user_meeting_folder(user, api)
+ if mf_sco_id > 0:
+ r = api.request('sco_contents', {'filter-type': 'meeting', 'sco_id': mf_sco_id})
+ nr = 0
+ ne = 0
+ for row in r.et.xpath("//sco"):
+ try:
+ _import_one_room(acc, api, row)
+ nr += 1
+ except Exception, ex:
+ logging.error(ex)
+ ne += 1
+
+ logging.info("%s: Imported %d rooms and got %d errors" % (acc, nr, ne))
+ else:
+ logging.warning("No user meetings folder found for %s" % user.username)
+
def import_acc(acc,since=0):
with ac_api_client(acc) as api:
r = None
diff --git a/meetingtools/apps/room/views.py b/meetingtools/apps/room/views.py
index 5219061..ea8b0fc 100644
--- a/meetingtools/apps/room/views.py
+++ b/meetingtools/apps/room/views.py
@@ -33,6 +33,7 @@ import iso8601
from celery.execute import send_task
from meetingtools.apps.room.tasks import start_user_counts_poll
+
def _user_meeting_folder(request,acc):
if not session(request,'my_meetings_sco_id'):
with ac_api_client(acc) as api:
@@ -45,6 +46,15 @@ def _user_meeting_folder(request,acc):
return session(request,'my_meetings_sco_id')
+
+def user_meeting_folder(user,api):
+ userid = user.username
+ folders = api.request('sco-search-by-field',
+ {'filter-type': 'folder', 'field': 'name', 'query': userid}).et.xpath('//sco[folder-name="User Meetings"]')
+ logging.debug("user meetings folder: "+pformat(folders))
+ #folder = next((f for f in folders if f.findtext('.//folder-name') == 'User Meetings'), None)
+ return folders[0].get('sco-id')
+
def _user_templates(request,acc,folder_sco):
templates = []
with ac_api_client(acc) as api:
@@ -63,6 +73,7 @@ def _user_templates(request,acc,folder_sco):
return templates
+
def _find_current_session(session_info):
for r in session_info.et.xpath('//row'):
#logging.debug(pformat(etree.tostring(r)))
diff --git a/meetingtools/apps/stats/tasks.py b/meetingtools/apps/stats/tasks.py
index ac68a29..9e2f437 100644
--- a/meetingtools/apps/stats/tasks.py
+++ b/meetingtools/apps/stats/tasks.py
@@ -1,6 +1,6 @@
import logging
from celery.schedules import crontab
-from celery.task import periodic_task
+from celery.task import periodic_task, task
from meetingtools.apps.room.models import Room
from meetingtools.ac import ac_api_client
from meetingtools.apps.cluster.models import ACCluster
@@ -9,6 +9,7 @@ from meetingtools.apps.stats.models import UserMeetingTransaction
__author__ = 'leifj'
+
def import_acc_sessions(acc,since=0,room_last_visited=False):
with ac_api_client(acc) as api:
p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting'}
@@ -40,6 +41,7 @@ def import_acc_sessions(acc,since=0,room_last_visited=False):
ne += 1
logging.info("%s: Imported %d transactions with %d errors" % (acc,nr,ne))
+@task
def import_sessions(since,room_last_visited=False):
for acc in ACCluster.objects.all():
import_acc_sessions(acc,since,room_last_visited)
diff --git a/meetingtools/settings.py b/meetingtools/settings.py
index 0bb0ca1..c50947d 100644
--- a/meetingtools/settings.py
+++ b/meetingtools/settings.py
@@ -155,10 +155,10 @@ LOGIN_REDIRECT_URL = "/rooms"
AUTO_REMOTE_SUPERUSERS = ['leifj@nordu.net']
-try:
- from asgard.loader import *
- DEBUG=True
-
- AUTHENTICATION_BACKENDS += ('asgard.saml.Saml2Backend',)
-except ImportError,ex:
- print ex
+#try:
+# from asgard.loader import *
+# DEBUG=True
+#
+# AUTHENTICATION_BACKENDS += ('asgard.saml.Saml2Backend',)
+#except ImportError,ex:
+# print ex