fix: add check if the users need to be imported (#716)

This commit is contained in:
pablohashescobar 2023-04-06 13:58:56 +05:30 committed by GitHub
parent f2144c3e89
commit 105428894f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,54 +38,55 @@ def service_importer(service, importer_id):
users = importer.data.get("users", []) users = importer.data.get("users", [])
# For all invited users create the uers # Check if we need to import users as well
new_users = User.objects.bulk_create( if len(users):
[ # For all invited users create the uers
User( new_users = User.objects.bulk_create(
email=user.get("email").strip().lower(), [
username=uuid.uuid4().hex, User(
password=make_password(uuid.uuid4().hex), email=user.get("email").strip().lower(),
is_password_autoset=True, username=uuid.uuid4().hex,
) password=make_password(uuid.uuid4().hex),
for user in users is_password_autoset=True,
if user.get("import", False) == "invite" )
], for user in users
batch_size=10, if user.get("import", False) == "invite"
ignore_conflicts=True, ],
) batch_size=10,
ignore_conflicts=True,
)
workspace_users = User.objects.filter( workspace_users = User.objects.filter(
email__in=[ email__in=[
user.get("email").strip().lower() user.get("email").strip().lower()
for user in users for user in users
if user.get("import", False) == "invite" if user.get("import", False) == "invite"
or user.get("import", False) == "map" or user.get("import", False) == "map"
] ]
) )
# Add new users to Workspace and project automatically
WorkspaceMember.objects.bulk_create(
[
WorkspaceMember(member=user, workspace_id=importer.workspace_id)
for user in workspace_users
],
batch_size=100,
ignore_conflicts=True,
)
# Add new users to Workspace and project automatically ProjectMember.objects.bulk_create(
WorkspaceMember.objects.bulk_create( [
[ ProjectMember(
WorkspaceMember(member=user, workspace_id=importer.workspace_id) project_id=importer.project_id,
for user in workspace_users workspace_id=importer.workspace_id,
], member=user,
batch_size=100, )
ignore_conflicts=True, for user in workspace_users
) ],
batch_size=100,
ProjectMember.objects.bulk_create( ignore_conflicts=True,
[ )
ProjectMember(
project_id=importer.project_id,
workspace_id=importer.workspace_id,
member=user,
)
for user in workspace_users
],
batch_size=100,
ignore_conflicts=True,
)
# Check if sync config is on for github importers # Check if sync config is on for github importers
if service == "github" and importer.config.get("sync", False): if service == "github" and importer.config.get("sync", False):