From 0d58d5c6b51e766ea4ec31642914ea3c4511846e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 13 Jan 2022 08:36:40 +0900 Subject: [PATCH] Move create member command --- backend/roles/management/__init__.py | 0 backend/roles/management/commands/__init__.py | 0 .../management/commands/create_member.py} | 14 ++++++++------ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 backend/roles/management/__init__.py create mode 100644 backend/roles/management/commands/__init__.py rename backend/{api/management/commands/create_role_mapping.py => roles/management/commands/create_member.py} (72%) diff --git a/backend/roles/management/__init__.py b/backend/roles/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/roles/management/commands/__init__.py b/backend/roles/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/api/management/commands/create_role_mapping.py b/backend/roles/management/commands/create_member.py similarity index 72% rename from backend/api/management/commands/create_role_mapping.py rename to backend/roles/management/commands/create_member.py index 9ebdfcf7..d520d4c9 100644 --- a/backend/api/management/commands/create_role_mapping.py +++ b/backend/roles/management/commands/create_member.py @@ -1,10 +1,12 @@ from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User -from api.models import Project, Role, RoleMapping, User +from api.models import Project +from ...models import Member, Role class Command(BaseCommand): - help = 'Non-interactively create a rolemapping' + help = 'Non-interactively create a member' @classmethod def add_arguments(self, parser): @@ -21,15 +23,15 @@ class Command(BaseCommand): projectname = options.get('projectname') if not rolename or not username or not projectname: - raise CommandError('--rolename --projectname --username are required for the rolemapping') + raise CommandError('--rolename --projectname --username are required for the member') if rolename and projectname and username: try: role = Role.objects.get(name=rolename) user = User.objects.get(username=username) project = Project.objects.get(name=projectname) - rolemapping = RoleMapping.objects.create(role_id=role.id, user_id=user.id, project_id=project.id) + member = Member.objects.create(role_id=role.id, user_id=user.id, project_id=project.id) except Exception as ex: - self.stderr.write(self.style.ERROR('Error occurred while creating rolemapping "%s"' % ex)) + self.stderr.write(self.style.ERROR('Error occurred while creating member "%s"' % ex)) else: - self.stdout.write(self.style.SUCCESS('Rolemapping created successfully "%s"' % rolemapping.id)) + self.stdout.write(self.style.SUCCESS('Member created successfully "%s"' % member.id))