mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 00:37:37 -02:30
add basic Organization migration
This commit is contained in:
committed by
Akita Noek
parent
c6b2e509fd
commit
932b6a4c82
@@ -76,6 +76,16 @@ class Organization(CommonModel, ResourceMixin):
|
||||
script.save()
|
||||
super(Organization, self).mark_inactive(save=save)
|
||||
|
||||
def migrate_to_rbac(self):
|
||||
migrated_users = []
|
||||
for admin in self.admins.all():
|
||||
self.admin_role.members.add(admin)
|
||||
migrated_users.append(admin)
|
||||
for user in self.users.all():
|
||||
self.auditor_role.members.add(user)
|
||||
migrated_user.append(user)
|
||||
return migrated_users
|
||||
|
||||
|
||||
class Team(CommonModelNameNotUnique, ResourceMixin):
|
||||
'''
|
||||
|
||||
29
awx/main/tests/functional/test_rbac_migrations.py
Normal file
29
awx/main/tests/functional/test_rbac_migrations.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import pytest
|
||||
|
||||
from awx.main.models.organization import Organization
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
def make_user(name, admin=False):
|
||||
email = '%s@example.org' % name
|
||||
if admin == True:
|
||||
return User.objects.create_superuser(name, email, name)
|
||||
else:
|
||||
return User.objects.create_user(name, email, name)
|
||||
|
||||
@pytest.fixture
|
||||
def organization():
|
||||
return Organization.objects.create(name="test-org", description="test-org-desc")
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("username,admin", [
|
||||
("admin", True),
|
||||
("user", False),
|
||||
])
|
||||
def test_organization_migration(organization, username, admin):
|
||||
user = make_user(username, admin)
|
||||
organization.admins.add(user)
|
||||
|
||||
migrated_users = organization.migrate_to_rbac()
|
||||
assert len(migrated_users) == 1
|
||||
assert migrated_users[0] == user
|
||||
|
||||
Reference in New Issue
Block a user