def sync_ldap_users_groups(request):
 if (not request.user.is_superuser):
  request.audit = {'operation': 'SYNC_LDAP_USERS_GROUPS', 'operationText': _get_failed_operation_text(request.user.username, 'SYNC_LDAP_USERS_GROUPS'), 'allowed': False}
  raise PopupException(_('You must be a superuser to sync the LDAP users/groups.'), error_code=401)
 if (request.method == 'POST'):
  form = SyncLdapUsersGroupsForm(request.POST)
  if form.is_valid():
   is_ensuring_home_directory = form.cleaned_data['ensure_home_directory']
   server = form.cleaned_data.get('server')
   connection = ldap_access.get_connection_from_server(server)
   failed_ldap_users = []
   sync_ldap_users_and_groups(connection, is_ensuring_home_directory, request.fs, failed_users=failed_ldap_users)
   request.audit = {'operation': 'SYNC_LDAP_USERS_GROUPS', 'operationText': 'Successfully synced LDAP users/groups'}
   if failed_ldap_users:
    unique_users = set(failed_ldap_users)
    request.warn((_('Failed to import following users: %s') % ', '.join(unique_users)))
   return redirect(reverse(list_users))
 else:
  form = SyncLdapUsersGroupsForm()
 return render('sync_ldap_users_groups.mako', request, dict(path=request.path, form=form))

def sync_ldap_users_groups ( request ) : if ( not request . user . is_superuser ) : request . audit = { 'operation' : 'SYNC_LDAP_USERS_GROUPS' , 'operationText' : _get_failed_operation_text ( request . user . username , 'SYNC_LDAP_USERS_GROUPS' ) , 'allowed' : False } raise PopupException ( _ ( 'You must be a superuser to sync the LDAP users/groups.' ) , error_code = 401 ) if ( request . method == 'POST' ) : form = SyncLdapUsersGroupsForm ( request . POST ) if form . is_valid ( ) : is_ensuring_home_directory = form . cleaned_data [ 'ensure_home_directory' ] server = form . cleaned_data . get ( 'server' ) connection = ldap_access . get_connection_from_server ( server ) failed_ldap_users = [ ] sync_ldap_users_and_groups ( connection , is_ensuring_home_directory , request . fs , failed_users = failed_ldap_users ) request . audit = { 'operation' : 'SYNC_LDAP_USERS_GROUPS' , 'operationText' : 'Successfully synced LDAP users/groups' } if failed_ldap_users : unique_users = set ( failed_ldap_users ) request . warn ( ( _ ( 'Failed to import following users: %s' ) % ', ' . join ( unique_users ) ) ) return redirect ( reverse ( list_users ) ) else : form = SyncLdapUsersGroupsForm ( ) return render ( 'sync_ldap_users_groups.mako' , request , dict ( path = request . path , form = form ) )
handler for syncing the hue database with ldap users and groups .