Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into fibre
authorLoic & Edelberto <loic.baron@lip6.fr>
Thu, 13 Mar 2014 13:40:28 +0000 (10:40 -0300)
committerLoic & Edelberto <loic.baron@lip6.fr>
Thu, 13 Mar 2014 13:40:28 +0000 (10:40 -0300)
Conflicts:
portal/actions.py

1  2 
myslice/urls.py
portal/actions.py
ui/templates/base.html
ui/templates/messages-transient-header.html

diff --combined myslice/urls.py
@@@ -23,6 -23,11 +23,11 @@@ platforms_view=portal.platformsview.Pla
  import portal.testbedlist
  import portal.sliceview
  import portal.sliceresourceview
+ import portal.slicetabexperiment
+ import portal.slicetabinfo
+ import portal.slicetabtestbeds
  from portal.sliceuserview import SliceUserView 
  
  #### high level choices
@@@ -75,10 -80,15 +80,15 @@@ urls = 
      #
      #
      # Portal
-     (r'^testbeds/(?P<slicename>[^/]+)/?$', portal.testbedlist.TestbedList.as_view()),
+     
      (r'^resources/(?P<slicename>[^/]+)/?$', portal.sliceresourceview.SliceResourceView.as_view()),
-     (r'^users/(?P<slicename>[^/]+)/?$', SliceUserView.as_view()),
+     
      (r'^slice/(?P<slicename>[^/]+)/?$', portal.sliceview.SliceView.as_view()),
+     
+     (r'^info/(?P<slicename>[^/]+)/?$', portal.slicetabinfo.SliceInfoView.as_view()),
+     (r'^testbeds/(?P<slicename>[^/]+)/?$', portal.slicetabtestbeds.SliceTabTestbeds.as_view()),
+     (r'^users/(?P<slicename>[^/]+)/?$', SliceUserView.as_view()),
+     (r'^experiment/(?P<slicename>[^/]+)/?$', portal.slicetabexperiment.ExperimentView.as_view()),
      url(r'^portal/', include('portal.urls')),
  ]
  
@@@ -90,10 -100,3 +100,10 @@@ for aux in auxiliaries
          urls.append ( url ( r'^%s/'%aux, include ('%s.urls'%aux )))
  
  urlpatterns = patterns(*urls)
 +
 +# Shibboleth - Edelberto
 +urlpatterns += patterns('',
 +   #url(r'^cafe/', 'plugins.cafe.edelberto.EdelbertoView.as_view()'),
 +   url(r'^cafe/', 'plugins.cafe.edelberto.index'),
 +)
 +
diff --combined portal/actions.py
@@@ -500,138 -500,6 +500,138 @@@ def sfa_create_user(wsgi_request, reque
          raise Exception, "Could not create %s. Already exists ?" % sfa_user_params['user_hrn']
      return results
  
 +def ldap_create_user(wsgi_request, request, user_detail):
 +    """
 +    Populating LDAP withuser data - Edelberto 10/03/2014
 +    """
 +    # import needed modules
 +    import ldap
 +    import ldap.modlist as modlist
 +
 +    # Open a connection
 +    # XXX We need to create this in settings
 +    # ldap.open is deprecated!
 +    #l = ldap.open("127.0.0.1")
 +    l = ldap.initialize('ldap://127.0.0.1:389')
 +
 +    # you should  set this to ldap.VERSION2 if you're using a v2 directory
 +    l.protocol_version = ldap.VERSION3
 +
 +    # Bind/authenticate with a user with apropriate rights to add objects
 +    # XXX Now we set the force rootd but after we need to set this in settings file for could change the dn and password of root
 +    l.simple_bind_s("cn=Manager,dc=br","fibre")
 +
 +    # The dn of our new entry/object
 +    #dn="uid=addtest@uff.br,ou=people,o=uff,dc=br"
 +
 +    # we need to create the dn entry
 +    # Receiving an email address, how can we split and mount it in DN format?
 +    #mail = "debora@uff.br"
 +    mail = request['email']
 +    login = mail.split('@')[0]
 +    org = mail.split('@')[1]
 +    o = org.split('.')[-2]
 +    dc = org.split('.')[-1]
 +
 +    # DN format to authenticate - IMPORTANT!
 +    #FIBRE-BR format
 +    dn = "uid="+mail+",ou=people,o="+o+",dc="+dc
 +
 +    # DEBUG
 +    print "dn:"+dn
 +    print request['password']
 +
 +    # Creating a unique uidNumber - Necessary for experiments
 +    # Was defined to began in 100000
 +    unique = int(user_detail['user_id']) + 100000
 +    #unique = int(unique)
 +    print unique
 +
 +    # A dict to help build the "body" of the object
 +    attrs = {}
 +    attrs['objectclass'] = ['person','inetOrgPerson','posixAccount','eduPerson','brPerson','schacPersonalCharacteristics','fibre', 'ldapPublicKey']
 +    # XXX Converting all unicodes to string
 +    attrs['uid'] = mail.encode('utf-8')
 +    attrs['cn'] = request['first_name'].encode('latin1')
 +    attrs['sn'] = request['last_name'].encode('latin1')
 +    # XXX we need to set a unique uidNumber. How?
 +    attrs['uidNumber'] = str(unique)
 +    attrs['gidNumber'] = '500'
 +    attrs['homeDirectory'] = "/home/"+org+"/"+mail
 +    attrs['homeDirectory'] = attrs['homeDirectory'].encode('utf-8')
 +    attrs['mail'] = mail.encode('utf-8')
 +    attrs['eppn'] = mail.encode('utf8')
 +    attrs['userPassword'] = request['password'].encode('utf-8')
 +    attrs['sshPublicKey'] = request['public_key'].encode('utf-8')
 +    # XXX We really set TRUE for those attributes? 
 +    #attrs['userEnable'] = 'TRUE'
 +    # set FALSE and change after when the user is validated
 +    attrs['userEnable'] = 'FALSE'
 +    attrs['omfAdmin'] = 'TRUE'
 +
 +    # Convert our dict to nice syntax for the add-function using modlist-module
 +    ldif = modlist.addModlist(attrs)
 +
 +    # DEBUG
 +    print attrs['userPassword']
 +    print attrs['cn']
 +    print attrs['sn']
 +    print attrs['homeDirectory']
 +    #print ldif
 +
 +    # Do the actual synchronous add-operation to the ldapserver
 +    l.add_s(dn,ldif)
 +
 +    # Its nice to the server to disconnect and free resources when done
 +    l.unbind_s()
 +
 +    return ldif
 +
 +def ldap_modify_user(wsgi_request, request):
 +    #Modify entries in an LDAP Directory
 +
 +    #Synchrounous modify
 +    # import needed modules
 +    import ldap
 +    import ldap.modlist as modlist
 +
 +    # Open a connection
 +    l = ldap.initialize("ldap://localhost:389/")
 +
 +    # Bind/authenticate with a user with apropriate rights to add objects
 +    l.simple_bind_s("cn=Manager,dc=br","fibre")
 +
 +    # we need to create the dn entry
 +    # Receiving an email address, how can we split and mount it in DN format?
 +    #mail = "debora@uff.br"
 +    mail = request['email']
 +    login = mail.split('@')[0]
 +    org = mail.split('@')[1]
 +    o = org.split('.')[-2]
 +    dc = org.split('.')[-1]
 +
 +    # DN format to authenticate - IMPORTANT!
 +    #FIBRE-BR format
 +    dn = "uid="+mail+",ou=people,o="+o+",dc="+dc
 +
 +    # The dn of our existing entry/object
 +    #dn="uid=mario@uff.br,ou=people,o=uff,dc=br"
 +
 +    # Some place-holders for old and new values
 +    old = {'userEnable':'FALSE'}
 +    new = {'userEnable':'TRUE'}
 +
 +    # Convert place-holders for modify-operation using modlist-module
 +    ldif = modlist.modifyModlist(old,new)
 +
 +    # Do the actual modification
 +    l.modify_s(dn,ldif)
 +
 +    # Its nice to the server to disconnect and free resources when done
 +    l.unbind_s()
 +
 +    return ldif
 +
  def create_user(wsgi_request, request):
      
      # XXX This has to be stored centrally
  
      # NOTE : if we were to create a user directly (just like we create slices,
      # we would have to perform the steps in create_pending_user too
 +    
  
      # Add the user to the SFA registry
      sfa_create_user(wsgi_request, request)
      # Add reference accounts for platforms
      manifold_add_reference_user_accounts(wsgi_request, request)
  
 +    # LDAP update user userEnabled = True
 +    mail = request['email']
 +    login = mail.split('@')[0]
 +    org = mail.split('@')[1]
 +    o = org.split('.')[-2]
 +    dc = org.split('.')[-1]
 +    # To know if user is a LDAP user - Need to has a 'dc' identifier
 +    if dc == 'br' or 'eu':
 +        ldap_modify_user(wsgi_request, request)
 +
  def create_pending_user(wsgi_request, request, user_detail):
      """
      """
              .filter_by('platform', '==', 'myslice')           \
              .select('platform_id')
          reg_platform = execute_admin_query(wsgi_request, reg_platform_query)
-     
 -
          reg_platform_id = reg_platform[0]['platform_id']
          account_params = {
              'platform_id'   : reg_platform_id, # XXX ALERT !!
          }
          manifold_add_account(wsgi_request, account_params)
      except Exception, e:
 -        print "Failed creating manifold account on platform %s for user: %s" % ('myslice', request['email'])
 +       print "Failed creating manifold account on platform %s for user: %s" % ('myslice', request['email'])
 +
 +    # Add user to LDAP userEnabled = False
 +    # Not more here. Create before directly to the registrationview.py
 +    # After we change userEnable = TRUE when validate the user
  
      try:
          # Send an email: the recipients are the PI of the authority
diff --combined ui/templates/base.html
@@@ -1,6 -1,6 +1,6 @@@
  {# This is required by insert_above #}{% insert_handler %}<!DOCTYPE html>
  <html lang="en"><head>
 -<title>OneLab - {{ section }}</title>
 +<title>FIBRE - {{ section }}</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="shortcut icon" href="/static/img/myslice-icon.png">
  {# This is where insert_str will end up #}{% media_container prelude %}
  {% insert_str prelude "js/manifold.js" %}
  {% insert_str prelude "css/manifold.css" %}
  {% insert_str prelude "css/plugin.css" %}
+ {% insert_str prelude "js/bootstrap.js" %}
+ {% insert_str prelude "css/bootstrap.css" %}
+ {% insert_str prelude "css/topmenu.css" %}
+ {% insert_str prelude "js/logout.js" %}
  <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/{{ theme }}.css">
  </head>
  <body>
@@@ -1,4 -1,4 +1,4 @@@
 -<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
 +<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
  <!-- <script type="text/javascript">{{ STATIC_URL }}js/ui.widget.js</script> -->
  <script src="{{ STATIC_URL }}js/jquery.notify.js" type="text/javascript"></script>
  <link rel='stylesheet' href='{{ STATIC_URL }}css/ui.notify.css' type='text/css' />
@@@ -23,10 -23,10 +23,10 @@@ $(function()
        $(document).ready(function(){
                {% for message in messages %}
              $("#notifications").notify("create", {
-               title: 'Test Notification',
+               title: 'Notification',
                text: '{{ message }}'
              },{
-               expires: false,
+               expires: true,
                speed: 1000
              });
                {% endfor %}