X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=blobdiff_plain;f=portal%2Faccountview.py;h=f366555d829b446a1ddb9ba0bfd211b5282b51b5;hp=2fc5e823e5d499a1f31ff13ae6ed430cb9d54e52;hb=bbc146e5dcbd1a5285b7465cd3e7f2c23a6dc9c8;hpb=b81c98064566ba64e0e70600ce6f3aeecd0abb22 diff --git a/portal/accountview.py b/portal/accountview.py index 2fc5e823..f366555d 100644 --- a/portal/accountview.py +++ b/portal/accountview.py @@ -29,12 +29,21 @@ class AccountView(LoginRequiredAutoLogoutView): page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] ) - user_query = Query().get('local:user').select('config','email') + user_query = Query().get('local:user').select('config','email','status') user_details = execute_query(self.request, user_query) # not always found in user_details... config={} for user_detail in user_details: + # different significations of user_status + if user_detail['status'] == 0: + user_status = 'Disabled' + elif user_detail['status'] == 1: + user_status = 'Validation Pending' + elif user_detail['status'] == 2: + user_status = 'Enabled' + else: + user_status = 'N/A' #email = user_detail['email'] if user_detail['config']: config = json.loads(user_detail['config']) @@ -56,6 +65,7 @@ class AccountView(LoginRequiredAutoLogoutView): my_auths = '' ref_acc_list = '' principal_acc_list = '' + user_status_list = [] platform_name_list = [] platform_name_secondary_list = [] platform_access_list = [] @@ -85,44 +95,45 @@ class AccountView(LoginRequiredAutoLogoutView): account_usr_hrn = account_config.get('user_hrn','N/A') account_pub_key = account_config.get('user_public_key','N/A') account_reference = account_config.get ('reference_platform','N/A') - # credentials - acc_user_cred = account_config.get('delegated_user_credential','N/A') - acc_slice_cred = account_config.get('delegated_slice_credentials','N/A') - acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') + # credentials of myslice platform + if 'myslice' in platform_detail['platform']: + acc_user_cred = account_config.get('delegated_user_credential','N/A') + acc_slice_cred = account_config.get('delegated_slice_credentials','N/A') + acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') - if 'N/A' not in acc_user_cred: - exp_date = re.search('(.*)', acc_user_cred) - if exp_date: - user_exp_date = exp_date.group(1) - user_cred_exp_list.append(user_exp_date) + if 'N/A' not in acc_user_cred: + exp_date = re.search('(.*)', acc_user_cred) + if exp_date: + user_exp_date = exp_date.group(1) + user_cred_exp_list.append(user_exp_date) - my_users = [{'cred_exp': t[0]} - for t in zip(user_cred_exp_list)] + my_users = [{'cred_exp': t[0]} + for t in zip(user_cred_exp_list)] - if 'N/A' not in acc_slice_cred: - for key, value in acc_slice_cred.iteritems(): - slice_list.append(key) - # get cred_exp date - exp_date = re.search('(.*)', value) - if exp_date: - exp_date = exp_date.group(1) - slice_cred_exp_list.append(exp_date) + if 'N/A' not in acc_slice_cred: + for key, value in acc_slice_cred.iteritems(): + slice_list.append(key) + # get cred_exp date + exp_date = re.search('(.*)', value) + if exp_date: + exp_date = exp_date.group(1) + slice_cred_exp_list.append(exp_date) - my_slices = [{'slice_name': t[0], 'cred_exp': t[1]} - for t in zip(slice_list, slice_cred_exp_list)] + my_slices = [{'slice_name': t[0], 'cred_exp': t[1]} + for t in zip(slice_list, slice_cred_exp_list)] - if 'N/A' not in acc_auth_cred: - for key, value in acc_auth_cred.iteritems(): - auth_list.append(key) - #get cred_exp date - exp_date = re.search('(.*)', value) - if exp_date: - exp_date = exp_date.group(1) - auth_cred_exp_list.append(exp_date) + if 'N/A' not in acc_auth_cred: + for key, value in acc_auth_cred.iteritems(): + auth_list.append(key) + #get cred_exp date + exp_date = re.search('(.*)', value) + if exp_date: + exp_date = exp_date.group(1) + auth_cred_exp_list.append(exp_date) - my_auths = [{'auth_name': t[0], 'cred_exp': t[1]} - for t in zip(auth_list, auth_cred_exp_list)] + my_auths = [{'auth_name': t[0], 'cred_exp': t[1]} + for t in zip(auth_list, auth_cred_exp_list)] # for reference accounts @@ -148,9 +159,10 @@ class AccountView(LoginRequiredAutoLogoutView): delegation_type_list.append(delegation) usr_hrn_list.append(account_usr_hrn) pub_key_list.append(account_pub_key) + user_status_list.append(user_status) # combining 5 lists into 1 [to render in the template] - principal_acc_list = [{'platform_name': t[0], 'account_type': t[1], 'delegation_type': t[2], 'usr_hrn':t[3], 'usr_pubkey':t[4]} - for t in zip(platform_name_list, account_type_list, delegation_type_list, usr_hrn_list, pub_key_list)] + principal_acc_list = [{'platform_name': t[0], 'account_type': t[1], 'delegation_type': t[2], 'usr_hrn':t[3], 'usr_pubkey':t[4], 'user_status':t[5],} + for t in zip(platform_name_list, account_type_list, delegation_type_list, usr_hrn_list, pub_key_list, user_status_list)] # to hide private key row if it doesn't exist if 'myslice' in platform_detail['platform']: account_config = json.loads(account_detail['config']) @@ -173,6 +185,7 @@ class AccountView(LoginRequiredAutoLogoutView): context['my_users'] = my_users context['my_slices'] = my_slices context['my_auths'] = my_auths + context['user_status'] = user_status context['person'] = self.request.user context['firstname'] = config.get('firstname',"?") context['lastname'] = config.get('lastname',"?") @@ -325,9 +338,9 @@ def account_process(request): user_params = { 'config': keypair, 'auth_type':'managed'} manifold_update_account(request,user_params) # updating sfa - public_key = public_key.replace('"', ''); - user_pub_key = {'keys': public_key} - sfa_update_user(request, user_hrn, user_pub_key) + #public_key = public_key.replace('"', ''); + #user_pub_key = {'keys': public_key} + #sfa_update_user(request, user_hrn, user_pub_key) messages.success(request, 'Sucess: New Keypair Generated! Delegation of your credentials will be automatic.') return HttpResponseRedirect("/portal/account/") else: @@ -433,10 +446,9 @@ def account_process(request): user_cred = account_config.get('delegated_user_credential','N/A') if 'N/A' not in user_cred: user_hrn = account_config.get('user_hrn','N/A') - user_pub_key = account_config.get('user_public_key','N/A') - user_priv_key = account_config.get('user_private_key','N/A') - updated_config = '{"user_public_key":"'+ user_pub_key + '", "user_private_key":"'+ user_priv_key + '", "user_hrn":"'+ user_hrn + '"}' - #updated_config = ''.join(updated_config.split()) + user_pub_key = json.dumps(account_config.get('user_public_key','N/A')) + user_priv_key = json.dumps(account_config.get('user_private_key','N/A')) + updated_config = '{"user_public_key":'+ user_pub_key + ', "user_private_key":'+ user_priv_key + ', "user_hrn":"'+ user_hrn + '"}' user_params = { 'config': updated_config} manifold_update_account(request,user_params) messages.success(request, 'All Credentials cleared')