def json_users(request, exclude=None): query = request.GET.get("q", None) json = { 'identifier': 'id', 'label': 'name', 'items': [], } if exclude: exclude = exclude.split(',') else: exclude = [] idx = 1 for user in FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER | FLAGS_CACHE_WRITE_USER): if idx > 50: break if (query == None or user.pw_name.startswith(query)) and \ user.pw_name not in exclude: json['items'].append({ 'id': user.pw_name, 'name': user.pw_name, 'label': user.pw_name, }) idx += 1 return HttpResponse(simplejson.dumps(json, indent=3))
def _reroll(self): from freenasUI.account.forms import FilteredSelectJSON users = FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER | FLAGS_CACHE_WRITE_USER) if len(users) > 500: if self.initial: self.choices = ((self.initial, self.initial), ) kwargs = {} if len(self._exclude) > 0: kwargs['exclude'] = ','.join(self._exclude) self.widget = FilteredSelectJSON(url=("account_bsduser_json", None, (), kwargs)) else: ulist = [] if not self.required: ulist.append(('-----', 'N/A')) ulist.extend( map( lambda x: ( x.pw_name, x.pw_name, ), filter( lambda y: y is not None and y.pw_name not in self. _exclude, users))) self.widget = widgets.FilteringSelect() self.choices = ulist
def cache_fill(**kwargs): uargs = {'flags': FLAGS_DBINIT | FLAGS_CACHE_WRITE_USER} gargs = {'flags': FLAGS_DBINIT | FLAGS_CACHE_WRITE_GROUP} for u in FreeNAS_Users(**uargs): pass for g in FreeNAS_Groups(**gargs): pass
def cache_dump(**kwargs): print("FreeNAS_Users:") for u in FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER): print(" ", u) print("\n\n") print("FreeNAS_Groups:") for g in FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP): print(" ", g)
def _reroll(self): from freenasUI.account.forms import FilteredSelectJSON try: users = FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER) except: users = [] if len(users) > 500: if self.initial: self.choices = ((self.initial, self.initial),) kwargs = {} if len(self._exclude) > 0: kwargs['exclude'] = ','.join(self._exclude) self.widget = FilteredSelectJSON( attrs=self.widget.attrs, url=("account_bsduser_json", None, (), kwargs) ) else: ulist = [] if not self.required: ulist.append(('-----', 'N/A')) notbuiltin = [ o[0] for o in bsdUsers.objects.filter( bsdusr_builtin=False ).values_list('bsdusr_uid') ] ulist.extend( map( lambda x: (x.pw_name, x.pw_name, ), sorted(filter( lambda y: ( y is not None and y.pw_name not in self._exclude ), users ), key=lambda y: (y.pw_uid not in notbuiltin, y.pw_name)) ) ) self.widget = FilteredSelectJSON( attrs=self.widget.attrs, url=("account_bsduser_json",), choices=ulist )
def _reroll(self): from freenasUI.account.forms import FilteredSelectJSON try: users = FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER) except: users = [] kwargs = { 'api_name': 'v1.0', 'resource_name': 'account/all_users' } if len(users) > 500: if self.initial: self.choices = ((self.initial, self.initial),) if len(self._exclude) > 0: kwargs['exclude'] = ','.join(self._exclude) self.widget = FilteredSelectJSON( attrs=self.widget.attrs, url=reverse('api_dispatch_list', kwargs=kwargs) ) else: ulist = [] if not self.required: ulist.append(('-----', 'N/A')) notbuiltin = [ o[0] for o in bsdUsers.objects.filter( bsdusr_builtin=False ).values_list('bsdusr_uid') ] ulist.extend( [(x.pw_name, x.pw_name, ) for x in sorted([y for y in users if ( y is not None and y.pw_name not in self._exclude )], key=lambda y: (y.pw_uid not in notbuiltin, y.pw_name))] ) self.widget = FilteredSelectJSON( attrs=self.widget.attrs, url=reverse('api_dispatch_list', kwargs=kwargs), choices=ulist )
def json_users(request, exclude=None): query = request.GET.get("q", None) json_user = { 'identifier': 'id', 'label': 'name', 'items': [], } if exclude: exclude = exclude.split(',') else: exclude = [] idx = 1 for user in FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER | FLAGS_CACHE_WRITE_USER): if idx > 50: break if ((query is None or user.pw_name.startswith(query)) and user.pw_name not in exclude): json_user['items'].append({ 'id': user.pw_name, 'name': user.pw_name, 'label': user.pw_name, }) idx += 1 # Show users for the directory service provided in the wizard wizard_ds = request.session.get('wizard_ds') if request.GET.get('wizard') == '1' and wizard_ds: if wizard_ds.get('ds_type') == 'ad': users = FreeNAS_ActiveDirectory_Users( domainname=wizard_ds.get('ds_ad_domainname'), bindname=wizard_ds.get('ds_ad_bindname'), bindpw=wizard_ds.get('ds_ad_bindpw'), flags=FLAGS_DBINIT, ) elif wizard_ds.get('ds_type') == 'ldap': users = FreeNAS_LDAP_Users( host=wizard_ds.get('ds_ldap_hostname'), basedn=wizard_ds.get('ds_ldap_basedn'), binddn=wizard_ds.get('ds_ldap_binddn'), bindpw=wizard_ds.get('ds_ldap_bindpw'), flags=FLAGS_DBINIT, ) elif wizard_ds.get('ds_type') == 'nis': users = FreeNAS_NIS_Users( domain=wizard_ds.get('ds_nis_domain'), servers=wizard_ds.get('ds_nis_servers'), secure_mode=wizard_ds.get('ds_nis_secure_mode'), manycast=wizard_ds.get('ds_nis_manycast'), flags=FLAGS_DBINIT, ) else: users = None if users is not None: idx = 1 # FIXME: code duplication withe the block above for user in users._get_uncached_usernames(): if idx > 50: break if ((query is None or user.startswith(query)) and user not in exclude): json_user['items'].append({ 'id': '%s_%s' % ( wizard_ds.get('ds_type'), user, ), 'name': user, 'label': user, }) idx += 1 del users return HttpResponse( json.dumps(json_user, indent=3), content_type='application/json', )