settings secret_key from myslice.ini, current_site get the url from request.META...
authorLoic Baron <loic.baron@lip6.fr>
Wed, 6 May 2015 17:37:10 +0000 (19:37 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Wed, 6 May 2015 17:37:10 +0000 (19:37 +0200)
myslice/settings.py
myslice/theme.py
portal/actions.py
portal/emailactivationview.py
portal/joinview.py
portal/projectrequestview.py
portal/registrationview.py
portal/slicerequestview.py
portal/slicetabusers.py

index f5d11d2..04d96e6 100644 (file)
@@ -2,6 +2,7 @@ import os.path
 import logging
 import subprocess
 
+
 logger = logging.getLogger('myslice')
 
 # ROOT
@@ -47,6 +48,16 @@ if config.myslice.theme :
 else :
     theme = None
 
+if config.myslice.theme_label :
+    theme_label = config.myslice.theme_label
+else :
+    theme_label = theme
+
+if config.myslice.theme_logo :
+    theme_logo = config.myslice.theme_logo
+else :
+    theme_logo = theme + '.png'
+
 # HTTPROOT
 if config.myslice.httproot :
     HTTPROOT = config.myslice.httproot
@@ -160,10 +171,6 @@ MEDIA_URL = ''
 # Example: "/home/media/media.lawrence.com/static/"
 STATIC_ROOT = os.path.join(HTTPROOT,'static')
 
-# URL prefix for static files.
-# Example: "http://media.lawrence.com/static/"
-STATIC_URL = '/static/'
-
 # Additional locations of static files
 STATICFILES_DIRS = (
     # Put strings here, like "/home/html/static" or "C:/www/django/static".
@@ -189,18 +196,14 @@ STATICFILES_FINDERS = (
 ###    'django.contrib.staticfiles.finders.DefaultStorageFinder',
 )
 
-#TEMPLATE_CONTEXT_PROCESSORS = (
-#    'django.contrib.auth.context_processors.auth',
-#    'django.core.context_processors.debug',
-#    'django.core.context_processors.i18n',
-#    'django.core.context_processors.media',
-#    'django.core.context_processors.static',
-#    'django.core.context_processors.request',
-#    'django.contrib.messages.context_processors.messages',
-#)
+if config.myslice.secret_key:
+    # Make this unique, and don't share it with anybody.
+    SECRET_KEY = config.myslice.secret_key
+else:
+    raise Exception, "SECRET_KEY Not defined: Please setup a secret_key value in myslice.ini"
 
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = 't%n(3h)&amp;r^n8(+8)(sp29t^$c2#t(m3)e2!02l8w1#36tl#t27'
+AUTHENTICATION_BACKENDS = ('localauth.manifoldbackend.ManifoldBackend',
+                           'django.contrib.auth.backends.ModelBackend')
 
 # List of callables that know how to import templates from various sources.
 TEMPLATE_LOADERS = (
@@ -347,9 +350,6 @@ LOGGING = {
     }
 }
 
-AUTHENTICATION_BACKENDS = ('localauth.manifoldbackend.ManifoldBackend',
-                           'django.contrib.auth.backends.ModelBackend')
-
 ### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
 # without this setting django will return a 403 forbidden error, which is fine
 # if you need to see the error message then use this setting
@@ -365,3 +365,10 @@ CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure'
 SLA_COLLECTOR_URL = "http://157.193.215.125:4001/sla-collector/sla"
 SLA_COLLECTOR_USER = "portal"
 SLA_COLLECTOR_PASSWORD = "password"
+
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+
index e16326b..889bca2 100644 (file)
@@ -9,7 +9,19 @@ class ThemeView (object):
         self.config = ConfigEngine()
         if self.config.myslice.theme :
             return self.config.myslice.theme
-    
+
+    @property
+    def label(self):
+        self.config = ConfigEngine()
+        if self.config.myslice.theme_label :
+            return self.config.myslice.theme_label
+
+    @property
+    def logo(self):
+        self.config = ConfigEngine()
+        if self.config.myslice.theme_logo :
+            return self.config.myslice.theme_logo
+  
     @property
     def template(self):
         # Load a template from the theme directory if it exists
index cc4d988..16516ee 100644 (file)
@@ -7,14 +7,14 @@ from unfold.page                    import Page
 import json
 
 from django.contrib.auth.models     import User
-from django.contrib.sites.models    import Site
 from django.contrib.auth            import get_user_model
 from django.template.loader         import render_to_string
 from django.core.mail               import EmailMultiAlternatives, send_mail
 
 from myslice.theme                  import ThemeView
 from myslice.configengine           import ConfigEngine
-from myslice.settings               import logger
+
+from myslice.settings import logger
 
 theme = ThemeView()
 
@@ -741,7 +741,7 @@ def portal_validate_request(wsgi_request, request_ids):
                 raise Exception, 'unknown type of request %s' % request['type']
             # XXX Remove from Pendings in database
 
-            send_status_email(ctx, user_email, request['type'], 'validated')
+            send_status_email(wsgi_request, ctx, user_email, request['type'], 'validated')
         except Exception, e:
             request_status['SFA '+request['type']] = {'status': False, 'description': str(e)}
 
@@ -762,14 +762,17 @@ def reject_action(request, **kwargs):
     json_answer = json.dumps(status)
     return HttpResponse (json_answer, content_type="application/json")
 
+def get_current_site(request):
+    if request.is_secure():
+        current_site = 'https://'
+    else:
+        current_site = 'http://'
+    current_site += request.META['HTTP_HOST']
+    return current_site
 
 def portal_reject_request(wsgi_request, request_ids):
     status = {}
-    # get the domain url    
-    current_site = Site.objects.get_current()
-    current_site = current_site.domain
-
-
+    current_site = get_current_site(wsgi_request)
     if not isinstance(request_ids, list):
         request_ids = [request_ids]
 
@@ -876,7 +879,7 @@ def portal_reject_request(wsgi_request, request_ids):
             else:
                 raise Exception, 'unknown type of request %s' % request['type']
 
-            send_status_email(ctx, user_email, request['type'], 'denied')
+            send_status_email(wsgi_request, ctx, user_email, request['type'], 'denied')
         except Exception, e:
             request_status['SFA '+request['type']] = {'status': False, 'description': str(e)}
 
@@ -884,8 +887,11 @@ def portal_reject_request(wsgi_request, request_ids):
 
     return status
 
-def send_status_email(ctx, user_email, obj_type, status):
+def send_status_email(request, ctx, user_email, obj_type, status):
     try:
+        ctx['current_site'] = get_current_site(request)
+        ctx['theme'] = theme
+
         theme.template_name = obj_type + '_request_' + status + '.txt'
         text_content = render_to_string(theme.template, ctx)
         theme.template_name = obj_type + '_request_' + status + '.html'
@@ -1040,16 +1046,18 @@ def create_pending_join(wsgi_request, request):
 # SEND EMAILS
 #-------------------------------------------------------------------------------
 
-def send_email_to_pis(wsgi_request, request, obj_type):
+def send_email_to_pis(request, context, obj_type):
     try:
+        context['current_site'] = get_current_site(request)
+        context['theme'] = theme
         # Send an email: the recipients are the PIs of the authority
-        recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn'])
+        recipients = authority_get_pi_emails(request, context['authority_hrn'])
 
         theme.template_name = obj_type + '_request_email.txt' 
-        text_content = render_to_string(theme.template, request)
+        text_content = render_to_string(theme.template, context)
 
         theme.template_name = obj_type + '_request_email.html' 
-        html_content = render_to_string(theme.template, request)
+        html_content = render_to_string(theme.template, context)
 
         #theme.template_name = obj_type + '_request_email_subject.txt'
         #subject = render_to_string(theme.template, request)
@@ -1057,7 +1065,7 @@ def send_email_to_pis(wsgi_request, request, obj_type):
         subject = "New "+obj_type+" request"
 
         theme.template_name = 'email_default_sender.txt'
-        sender =  render_to_string(theme.template, request)
+        sender =  render_to_string(theme.template, context)
         sender = sender.replace('\n', '')
 
         msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
@@ -1234,6 +1242,8 @@ def create_pending_user(wsgi_request, request, user_detail):
     )
     b.save()
     # sends email to user to activate the email
+    request['current_site'] = get_current_site(request)
+    request['theme'] = theme
     theme.template_name = 'activate_user.html'
     html_content = render_to_string(theme.template, request)
     theme.template_name = 'activate_user.txt'
index 79f2c0e..602ae91 100644 (file)
@@ -7,7 +7,6 @@ from django.http                        import HttpResponse, HttpResponseRedirec
 from django.contrib                     import messages
 from django.contrib.auth.decorators     import login_required
 from django.core.mail                   import EmailMultiAlternatives, send_mail
-from django.contrib.sites.models        import Site
 
 from manifold.core.query                import Query
 from manifoldapi.manifoldapi            import execute_query, execute_admin_query
@@ -24,8 +23,7 @@ from unfold.page                        import Page
 from ui.topmenu                         import topmenu_items_live, the_user
 
 from myslice.theme                      import ThemeView
-from myslice.settings                   import logger
-
+from myslice.settings import logger
 
 def ValuesQuerySetToDict(vqs):
     return [item for item in vqs]
@@ -58,10 +56,11 @@ class ActivateEmailView(FreeAccessView, ThemeView):
         page = Page(self.request)
         #page.add_js_files  ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js" ] )
         #page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
-
-        # get the domain url
-        current_site = Site.objects.get_current()
-        current_site = current_site.domain
+        if self.request.is_secure():
+            current_site = 'https://'
+        else:
+            current_site = 'http://'
+        current_site += self.request.META['HTTP_HOST']
 
         for key, value in kwargs.iteritems():
             if key == "hash_code":
index 6f0d77c..d4e4af5 100644 (file)
@@ -9,7 +9,6 @@ from django.views.generic       import View
 from django.template.loader     import render_to_string
 from django.shortcuts           import render
 from django.contrib.auth        import get_user_model
-from django.contrib.sites.models import Site
 
 from unfold.page                import Page
 from unfold.loginrequired       import FreeAccessView
@@ -155,9 +154,12 @@ class JoinView (FreeAccessView, ThemeView):
  
                 reg_password = request.POST['pi_password']
                 salt = randint(1,100000)
-                # get the domain url
-                current_site = Site.objects.get_current()
-                current_site = current_site.domain
+
+                if request.is_secure():
+                    current_site = 'https://'
+                else:
+                    current_site = 'http://'
+                current_site += request.META['HTTP_HOST']
 
                 email_hash = md5(str(salt)+reg_email).hexdigest()
                 user_request = {
index 3d749c8..fdccd16 100644 (file)
@@ -20,17 +20,17 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
     template_name = 'projectrequest_view.html'
     
     def getAuthorities(self, request):
-        if self.theme == 'fed4fire':
-            authorities_query = Query.get('myslice:authority').select('authority_hrn')
-        else:
-            authorities_query = Query.get('authority').select('name', 'authority_hrn')
+        #if self.theme == 'fed4fire':
+        authorities_query = Query.get('myslice:authority').select('authority_hrn')
+        #else:
+        #    authorities_query = Query.get('authority').select('name', 'authority_hrn')
         authorities = execute_admin_query(request, authorities_query)
         if authorities is not None:
             # Remove the root authority from the list
             matching = [s for s in authorities if "." in s['authority_hrn']]
             authorities = sorted(matching, key=lambda k: k['authority_hrn'])
-            if self.theme != 'fed4fire':
-                authorities = sorted(matching, key=lambda k: k['name'])
+            #if self.theme != 'fed4fire':
+            #    authorities = sorted(matching, key=lambda k: k['name'])
         return authorities
     
     def getUserAuthority(self, request):
index 9032125..61e56e4 100644 (file)
@@ -9,7 +9,6 @@ from django.template.loader     import render_to_string
 
 from django.shortcuts           import render
 from django.contrib.auth        import get_user_model
-from django.contrib.sites.models import Site
 
 from unfold.page                import Page
 from unfold.loginrequired       import FreeAccessView
@@ -68,10 +67,13 @@ class RegistrationView (FreeAccessView, ThemeView):
             reg_form = {}
             # The form has been submitted
             
-            # get the domain url
-            current_site = Site.objects.get_current()
-            current_site = current_site.domain
-           
+            if wsgi_request.is_secure():
+                current_site = 'https://'
+            else:
+                current_site = 'http://'
+            current_site += wsgi_request.META['HTTP_HOST']
+
+
             logger.debug("############ BREAKPOINT 3 #################")
             post_email = wsgi_request.POST.get('email','').lower()
             salt = randint(1,100000)
index c7102dc..47951a3 100644 (file)
@@ -5,7 +5,6 @@ import re
 from django.shortcuts           import render
 from django.shortcuts           import render_to_response
 from django.template                    import RequestContext
-from django.contrib.sites.models import Site
 
 from unfold.page                import Page
 
@@ -45,15 +44,15 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
         authority_hrn = None
         authority_name = None
         # Retrieve the list of authorities
-        if self.theme == 'fed4fire':
-            authorities_query = Query.get('myslice:authority').select('authority_hrn')
-        else:
-            authorities_query = Query.get('authority').select('name', 'authority_hrn')
+        #if self.theme == 'fed4fire' or self.theme == 'onelab':
+        authorities_query = Query.get('myslice:authority').select('authority_hrn')
+        #else:
+        #    authorities_query = Query.get('authority').select('name', 'authority_hrn')
         authorities = execute_admin_query(request, authorities_query)
         if authorities is not None:
             authorities = sorted(authorities, key=lambda k: k['authority_hrn'])
-            if self.theme != 'fed4fire':
-                authorities = sorted(authorities, key=lambda k: k['name'])
+            #if self.theme != 'fed4fire' or  self.theme != 'onelab':
+            #    authorities = sorted(authorities, key=lambda k: k['name'])
 
         # Get user_email (XXX Would deserve to be simplified)
         user_query  = Query().get('local:user').select('email','config')
@@ -64,13 +63,13 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
             user_config = json.loads(user_detail['config'])
             user_authority = user_config.get('authority','N/A')              
         # getting the org from authority        
-        for authority in authorities:
-            if 'name' in authority and authority['authority_hrn'] == user_authority:
-                authority_name = authority['name']
+       # for authority in authorities:
+       #     if 'name' in authority and authority['authority_hrn'] == user_authority:
+       #         authority_name = authority['name']
 
         # Handle the case when we use only hrn and not name
-        if authority_name is None:
-            authority_name = user_authority
+        #if authority_name is None:
+        #    authority_name = user_authority
         
         account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
         account_details = execute_query(request, account_query)
@@ -108,25 +107,26 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
         if method == 'POST':
             # The form has been submitted
 
-            # get the domain url
-            current_site = Site.objects.get_current()
-            current_site = current_site.domain
-           
-            if theme.theme != 'fed4fire':
+            if request.is_secure():
+                current_site = 'https://'
+            else:
+                current_site = 'http://'
+            current_site += request.META['HTTP_HOST']
+
+            #if theme.theme != 'fed4fire' or  self.theme != 'onelab':
                 # getting the authority_hrn from the selected organization
-                for authority in authorities:
-                    if authority['name'] == request.POST.get('org_name', ''):
-                        authority_hrn = authority['authority_hrn']
+            #    for authority in authorities:
+             #       if authority['name'] == request.POST.get('org_name', ''):
+              #          authority_hrn = authority['authority_hrn']
 
             # Handle the case when we use only hrn and not name
             if authority_hrn is None:
                 authority_hrn = request.POST.get('org_name', '')
 
             # Handle project if used
-            project = request.POST.get('project', None)
+            project = request.POST.get('org_name', None)
             if project is not None and project != '':
                 authority_hrn = project
-
             slice_name = request.POST.get('slice_name', '')
             if not slice_name or len(slice_name) == 0 :
                 errors.append('Slice name can\'t be empty')
@@ -166,7 +166,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
                 errors.append('Slice name may contain only letters, numbers, and underscore.')
             
             organization = slice_request['organization']
-            if theme.theme == 'fed4fire':
+            if theme.theme == 'fed4fire' or  self.theme == 'onelab':
                 if organization is None or organization == '':
                     errors.append('Selecting project is mandatory')
             else:
index 51623cf..cb62165 100644 (file)
@@ -34,23 +34,4 @@ class SliceUserView (LoginRequiredView, ThemeView):
                         config['authority'] = config.get('authority')
                         user_details[0]['parent_authority'] = config['authority']
 
-        ## check user is pi or not
-        platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
-        account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
-        platform_details = execute_query(self.request, platform_query)
-        account_details = execute_query(self.request, account_query)
-        for platform_detail in platform_details:
-            for account_detail in account_details:
-                if platform_detail['platform_id'] == account_detail['platform_id']:
-                    if 'config' in account_detail and account_detail['config'] is not '':
-                        account_config = json.loads(account_detail['config'])
-                        if 'myslice' in platform_detail['platform']:
-                            acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
-
-        # assigning values
-        if acc_auth_cred == {}:
-            pi = "is_not_pi"
-        else:
-            pi = "is_pi"
-
-        return render_to_response(self.template, {"slice": slicename, "user_details":user_details[0], "pi":pi, "theme": self.theme, "username": request.user, "section":"users"}, context_instance=RequestContext(request))
+        return render_to_response(self.template, {"slice": slicename, "user_details":user_details[0], "theme": self.theme, "username": request.user, "section":"users"}, context_instance=RequestContext(request))