From 7094e56df16ae31c7c5059fb4a84de27904145bf Mon Sep 17 00:00:00 2001
From: Yasin <mohammed-yasin.rahman@lip6.fr>
Date: Thu, 3 Jul 2014 19:08:15 +0200
Subject: [PATCH] fix: hide management section for non pi users

---
 portal/accountview.py       |  2 +-
 portal/contactview.py       |  4 +-
 portal/forms.py             | 94 ++++++++++++++++++-------------------
 portal/homeview.py          |  4 +-
 portal/slicerequestview.py  |  4 +-
 portal/sliceresourceview.py |  2 +-
 portal/supportview.py       |  2 +-
 portal/validationview.py    |  2 +
 8 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/portal/accountview.py b/portal/accountview.py
index 15c3799c..c88ac0e1 100644
--- a/portal/accountview.py
+++ b/portal/accountview.py
@@ -199,7 +199,7 @@ class AccountView(LoginRequiredAutoLogoutView, ThemeView):
                         if 'myslice' in platform_detail['platform']:
                             acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
         # assigning values
-        if acc_auth_cred == {}:
+        if acc_auth_cred == {} or acc_auth_cred == 'N/A':
             pi = "is_not_pi"
         else:
             pi = "is_pi"
diff --git a/portal/contactview.py b/portal/contactview.py
index c985b297..c41ee74d 100644
--- a/portal/contactview.py
+++ b/portal/contactview.py
@@ -35,7 +35,7 @@ class ContactView (FreeAccessView, ThemeView):
             #theme.template_name = 'email_support.txt'
             #recipients = render_to_string(theme.template, form.cleaned_data)
             #recipients = subject.replace('\n', '')
-            recipients = ['support@myslice.info','contact@fed4fire.eu']
+            recipients = ['support@myslice.info']
             if cc_myself:
                 recipients.append(email)
             #recipients = ['support@myslice.info']
@@ -89,7 +89,7 @@ class ContactView (FreeAccessView, ThemeView):
                             if 'myslice' in platform_detail['platform']:
                                 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
             # assigning values
-            if acc_auth_cred == {}:
+            if acc_auth_cred == {} or acc_auth_cred == 'N/A':
                 pi = "is_not_pi"
             else:
                 pi = "is_pi"
diff --git a/portal/forms.py b/portal/forms.py
index ecd2e6c6..683cffbb 100644
--- a/portal/forms.py
+++ b/portal/forms.py
@@ -99,7 +99,7 @@ class ContactForm(forms.Form):
 class PassResetForm(forms.Form):
     email = forms.EmailField(widget=forms.TextInput(attrs={'class':'form-control'}))
 
-class SliceRequestForm(forms.Form):
+#class SliceRequestForm(forms.Form):
 #    slice_name = forms.CharField()
 #    authority_hrn = forms.ChoiceField(choices=[(1, 'un')])
 #    number_of_nodes  = forms.DecimalField()
@@ -107,52 +107,52 @@ class SliceRequestForm(forms.Form):
 #    purpose = forms.CharField(widget=forms.Textarea)
 #    email = forms.EmailField()
 #    cc_myself = forms.BooleanField(required=False)
-
-    slice_name = forms.CharField(
-        widget=forms.TextInput(attrs={'class':'form-control'}), 
-        help_text="The name for the slice you wish to create")
-    authority_hrn = forms.ChoiceField(
-        widget    = forms.Select(attrs={'class':'form-control'}),
-        choices   = [],
-        help_text = "An authority responsible for vetting your slice")
-    number_of_nodes = forms.DecimalField(
-        widget    = forms.TextInput(attrs={'class':'form-control'}),
-        help_text = "The number of nodes you expect to request (informative)")
-    type_of_nodes = forms.CharField(
-        widget    = forms.TextInput(attrs={'class':'form-control'}),
-        help_text = "The type of nodes you expect to request (informative)")
-    purpose = forms.CharField(
-        widget    = forms.Textarea(attrs={'class':'form-control'}),
-        help_text = "The purpose of your experiment (informative)")
-    email = forms.EmailField(
-        widget    = forms.TextInput(attrs={'class':'form-control'}),
-        help_text = "Your email address")
-    cc_myself = forms.BooleanField(
-        widget    = forms.CheckboxInput(attrs={'class':'form-control'}),
-        required  = False,
-        help_text = "If you'd like to be cc'ed on the request email")
-
-    def __init__(self, *args, **kwargs):
-        initial =  kwargs.get('initial', {})
-        authority_hrn = initial.get('authority_hrn', None)
-
-        # set just the initial value
-        # in the real form needs something like this {'authority_hrn':'a'}
-        # but in this case you want {'authority_hrn':('a', 'letter_a')}
-        if authority_hrn:
-            kwargs['initial']['authority_hrn'] = authority_hrn[0]
-
-        # create the form
-        super(SliceRequestForm, self).__init__(*args, **kwargs)
-
-        # self.fields only exist after, so a double validation is needed
-        if authority_hrn:# and authority_hrn[0] not in (c[0] for c in authority_hrn):
-            # XXX This does not work, the choicefield is not updated...
-            #self.fields['authority_hrn'].choices.extend(authority_hrn)
-            self.fields['authority_hrn'] = forms.ChoiceField(
-                widget    = forms.Select(attrs={'class':'form-control'}),
-                choices   = authority_hrn,
-                help_text = "An authority responsible for vetting your slice")
+#
+#    slice_name = forms.CharField(
+#        widget=forms.TextInput(attrs={'class':'form-control'}), 
+#        help_text="The name for the slice you wish to create")
+#    authority_hrn = forms.ChoiceField(
+#        widget    = forms.Select(attrs={'class':'form-control'}),
+#        choices   = [],
+#        help_text = "An authority responsible for vetting your slice")
+#    number_of_nodes = forms.DecimalField(
+#        widget    = forms.TextInput(attrs={'class':'form-control'}),
+#        help_text = "The number of nodes you expect to request (informative)")
+#    type_of_nodes = forms.CharField(
+#        widget    = forms.TextInput(attrs={'class':'form-control'}),
+#        help_text = "The type of nodes you expect to request (informative)")
+#    purpose = forms.CharField(
+#        widget    = forms.Textarea(attrs={'class':'form-control'}),
+#        help_text = "The purpose of your experiment (informative)")
+#    email = forms.EmailField(
+#        widget    = forms.TextInput(attrs={'class':'form-control'}),
+#        help_text = "Your email address")
+#    cc_myself = forms.BooleanField(
+#        widget    = forms.CheckboxInput(attrs={'class':'form-control'}),
+#        required  = False,
+#        help_text = "If you'd like to be cc'ed on the request email")
+#
+#    def __init__(self, *args, **kwargs):
+#        initial =  kwargs.get('initial', {})
+#        authority_hrn = initial.get('authority_hrn', None)
+#
+#        # set just the initial value
+#        # in the real form needs something like this {'authority_hrn':'a'}
+#        # but in this case you want {'authority_hrn':('a', 'letter_a')}
+#        if authority_hrn:
+#            kwargs['initial']['authority_hrn'] = authority_hrn[0]
+#
+#        # create the form
+#        super(SliceRequestForm, self).__init__(*args, **kwargs)
+#
+#        # self.fields only exist after, so a double validation is needed
+#        if authority_hrn:# and authority_hrn[0] not in (c[0] for c in authority_hrn):
+#            # XXX This does not work, the choicefield is not updated...
+#            #self.fields['authority_hrn'].choices.extend(authority_hrn)
+#            self.fields['authority_hrn'] = forms.ChoiceField(
+#                widget    = forms.Select(attrs={'class':'form-control'}),
+#                choices   = authority_hrn,
+#                help_text = "An authority responsible for vetting your slice")
 
 
 class PasswordResetForm(forms.Form):
diff --git a/portal/homeview.py b/portal/homeview.py
index 029dc316..d46ed651 100644
--- a/portal/homeview.py
+++ b/portal/homeview.py
@@ -75,7 +75,7 @@ class HomeView (FreeAccessView, ThemeView):
                                     if 'myslice' in platform_detail['platform']:
                                         acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
                     # assigning values
-                    if acc_auth_cred == {}:
+                    if acc_auth_cred=={} or acc_auth_cred=='N/A':
                         pi = "is_not_pi"
                     else:
                         pi = "is_pi"
@@ -111,7 +111,7 @@ class HomeView (FreeAccessView, ThemeView):
                             if 'myslice' in platform_detail['platform']:
                                 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
             # assigning values
-            if acc_auth_cred == {}:
+            if acc_auth_cred=={} or acc_auth_cred=='N/A':
                 pi = "is_not_pi"
             else:
                 pi = "is_pi"
diff --git a/portal/slicerequestview.py b/portal/slicerequestview.py
index 5eb0725f..bc8c2035 100644
--- a/portal/slicerequestview.py
+++ b/portal/slicerequestview.py
@@ -8,7 +8,7 @@ from manifold.core.query        import Query
 from manifoldapi.manifoldapi    import execute_admin_query, execute_query
 
 from portal.actions             import is_pi, create_slice, create_pending_slice
-from portal.forms               import SliceRequestForm
+#from portal.forms               import SliceRequestForm
 from unfold.loginrequired       import LoginRequiredAutoLogoutView
 from ui.topmenu                 import topmenu_items_live, the_user
 
@@ -62,7 +62,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView):
 
 
         # checking if pi or not
-        if acc_auth_cred == {}:
+        if acc_auth_cred == {} or acc_auth_cred == 'N/A':
             pi = "is_not_pi"
         else:
             pi = "is_pi"
diff --git a/portal/sliceresourceview.py b/portal/sliceresourceview.py
index 749f7394..f6d29dbf 100644
--- a/portal/sliceresourceview.py
+++ b/portal/sliceresourceview.py
@@ -250,7 +250,7 @@ class SliceResourceView (LoginRequiredView, ThemeView):
                         if 'myslice' in platform_detail['platform']:
                             acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
         # assigning values
-        if acc_auth_cred == {}:
+        if acc_auth_cred == {} or acc_auth_cred == 'N/A':
             pi = "is_not_pi"
         else:
             pi = "is_pi"
diff --git a/portal/supportview.py b/portal/supportview.py
index f97705d5..80653e82 100644
--- a/portal/supportview.py
+++ b/portal/supportview.py
@@ -44,7 +44,7 @@ class SupportView (FreeAccessView, ThemeView):
                             if 'myslice' in platform_detail['platform']:
                                 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
             # assigning values
-            if acc_auth_cred == {}:
+            if acc_auth_cred == {} or acc_auth_cred == 'N/A':
                 pi = "is_not_pi"
             else:
                 pi = "is_pi"
diff --git a/portal/validationview.py b/portal/validationview.py
index b8454f03..b26ba0fa 100644
--- a/portal/validationview.py
+++ b/portal/validationview.py
@@ -260,6 +260,8 @@ class ValidatePendingView(LoginRequiredAutoLogoutView, ThemeView):
                 dest[auth_hrn].append(request)
         
         context = super(ValidatePendingView, self).get_context_data(**kwargs)
+        print "testing"
+        print ctx_my_authorities
         context['my_authorities']   = ctx_my_authorities
         context['sub_authorities']   = ctx_sub_authorities
         context['delegation_authorities'] = ctx_delegation_authorities
-- 
2.47.0