def run(self, _input): u = create_user(insert_if_db_user_exists=True, **self.options) if u.password: log.info("Created new database user %r with password=%r" % (u.username, u.password)) else: log.info("Created User object for database user %r" % (u.username)) return u
def import_users(self): for u in self._get_dicts("users.jsonl"): # get or create user try: user = User.objects.get(email=u['email']) except User.DoesNotExist: user = create_user(u['username'], u['first_name'], u['last_name'], u['email']) user.password = u['password'] user.save() yield u['email'], user.id self.check_coders()
def create_test_user(**kargs): """Create a user to be used in unit testing""" from amcat.models.user import User, create_user if 'username' not in kargs: kargs['username'] = "******" % User.objects.count() if 'email' not in kargs: kargs['email'] = "*****@*****.**" % User.objects.count() if 'first_name' not in kargs: kargs['first_name'] = kargs['username'] if 'last_name' not in kargs: kargs['last_name'] = kargs['username'] if 'password' not in kargs: kargs['password'] = '******' return create_user(**kargs)
def create_users(self): """ For every role-object with projectlevel == False, create a user with that name and assign it to this object. I.e.: self.(super)admin --> user with (super)admin rights self.read_write --> user with read/write role """ try: nl = Language.objects.get(label='NL') except Language.DoesNotExist: nl = Language(label='NL') nl.save() try: af = Affiliation.objects.get(name='VU') except Affiliation.DoesNotExist: af = Affiliation(name='VU') af.save() users = [ r.label for r in authorisation.Role.objects.filter(projectlevel=False) ] init_users = bool(User.objects.all()) for label, user in [(u, u.replace('/', '_')) for u in users]: u = User.objects.get(username=user) if init_users else None if u is None: u = create_user( user, "Test", user, "{}@test.com".format(user), af, nl, authorisation.Role.objects.get(label=label, projectlevel=False)) setattr(self, user, u) adminaff = Affiliation(name="admin") adminaff.save() self.superadmin.affiliation = adminaff self.superadmin.is_superuser = True self.admin.affiliation = adminaff self.superadmin.save() self.admin.save()
def create_test_user(**kargs): """Create a user to be used in unit testing""" from amcat.models.user import Affiliation, User, create_user if 'affiliation' not in kargs: kargs['affiliation'] = Affiliation.objects.create() if 'username' not in kargs: kargs['username'] = "******" % User.objects.count() if 'email' not in kargs: kargs['email'] = "*****@*****.**" % User.objects.count() if 'first_name' not in kargs: kargs['first_name'] = kargs['username'] if 'last_name' not in kargs: kargs['last_name'] = kargs['username'] if 'language' not in kargs: kargs['language'] = get_test_language() if 'role' not in kargs: kargs['role'] = get_test_role() #if "id" not in kargs: kargs["id"] = _get_next_id() return create_user(**kargs)
def create_test_user(**kargs): """Create a user to be used in unit testing""" from amcat.models.user import Affiliation, User, create_user if 'affiliation' not in kargs: kargs['affiliation'] = Affiliation.objects.create() if 'username' not in kargs: kargs['username'] = "******" % User.objects.count() if 'email' not in kargs: kargs['email'] = "*****@*****.**" % User.objects.count() if 'first_name' not in kargs: kargs['first_name'] = kargs['username'] if 'last_name' not in kargs: kargs['last_name'] = kargs['username'] if 'language' not in kargs: kargs['language'] = get_test_language() if 'role' not in kargs: kargs['role'] = get_test_role() if 'password' not in kargs: kargs['password'] = '******' #if "id" not in kargs: kargs["id"] = _get_next_id() return create_user(**kargs)
def create_users(self): """ For every role-object with projectlevel == False, create a user with that name and assign it to this object. I.e.: self.(super)admin --> user with (super)admin rights self.read_write --> user with read/write role """ try: nl = Language.objects.get(label='NL') except Language.DoesNotExist: nl = Language(label='NL'); nl.save() try: af = Affiliation.objects.get(name='VU') except Affiliation.DoesNotExist: af = Affiliation(name='VU'); af.save() users = [r.label for r in authorisation.Role.objects.filter(projectlevel=False)] init_users = bool(User.objects.all()) for label, user in [(u, u.replace('/', '_')) for u in users]: u = User.objects.get(username=user) if init_users else None if u is None: u = create_user(user, "Test", user, "{}@test.com".format(user), af, nl, authorisation.Role.objects.get(label=label, projectlevel=False) ) setattr(self, user, u) adminaff = Affiliation(name="admin"); adminaff.save() self.superadmin.affiliation = adminaff self.superadmin.is_superuser = True self.admin.affiliation = adminaff self.superadmin.save(); self.admin.save()