class Migration(migrations.Migration):

    dependencies = [
        ('main', '0075_v360_remove_old_instance_group_relations'),
    ]

    operations = [
        migrations.AddField(
            model_name='inventory',
            name='instance_groups',
            field=OrderedManyToManyField(
                blank=True,
                through='main.InventoryInstanceGroupMembership',
                to='main.InstanceGroup'),
        ),
        migrations.AddField(
            model_name='organization',
            name='instance_groups',
            field=OrderedManyToManyField(
                blank=True,
                through='main.OrganizationInstanceGroupMembership',
                to='main.InstanceGroup'),
        ),
        migrations.AddField(
            model_name='unifiedjobtemplate',
            name='instance_groups',
            field=OrderedManyToManyField(
                blank=True,
                through='main.UnifiedJobTemplateInstanceGroupMembership',
                to='main.InstanceGroup'),
        ),
    ]
Ejemplo n.º 2
0
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin,
                   CustomVirtualEnvMixin, RelatedJobsMixin):
    '''
    An organization is the basic unit of multi-tenancy divisions
    '''
    class Meta:
        app_label = 'main'
        ordering = ('name', )

    instance_groups = OrderedManyToManyField(
        'InstanceGroup',
        blank=True,
        through='OrganizationInstanceGroupMembership')
    max_hosts = models.PositiveIntegerField(
        blank=True,
        default=0,
        help_text=
        _('Maximum number of hosts allowed to be managed by this organization.'
          ),
    )
    notification_templates_approvals = models.ManyToManyField(
        "NotificationTemplate",
        blank=True,
        related_name='%(class)s_notification_templates_for_approvals')

    admin_role = ImplicitRoleField(parent_role='singleton:' +
                                   ROLE_SINGLETON_SYSTEM_ADMINISTRATOR, )
    execute_role = ImplicitRoleField(parent_role='admin_role', )
    project_admin_role = ImplicitRoleField(parent_role='admin_role', )
    inventory_admin_role = ImplicitRoleField(parent_role='admin_role', )
    credential_admin_role = ImplicitRoleField(parent_role='admin_role', )
    workflow_admin_role = ImplicitRoleField(parent_role='admin_role', )
    notification_admin_role = ImplicitRoleField(parent_role='admin_role', )
    job_template_admin_role = ImplicitRoleField(parent_role='admin_role', )
    auditor_role = ImplicitRoleField(parent_role='singleton:' +
                                     ROLE_SINGLETON_SYSTEM_AUDITOR, )
    member_role = ImplicitRoleField(parent_role=['admin_role'])
    read_role = ImplicitRoleField(parent_role=[
        'member_role',
        'auditor_role',
        'execute_role',
        'project_admin_role',
        'inventory_admin_role',
        'workflow_admin_role',
        'notification_admin_role',
        'credential_admin_role',
        'job_template_admin_role',
        'approval_role',
    ], )
    approval_role = ImplicitRoleField(parent_role='admin_role', )

    def get_absolute_url(self, request=None):
        return reverse('api:organization_detail',
                       kwargs={'pk': self.pk},
                       request=request)

    '''
    RelatedJobsMixin
    '''

    def _get_related_jobs(self):
        project_ids = self.projects.all().values_list('id')
        return UnifiedJob.objects.non_polymorphic().filter(
            Q(Job___project__in=project_ids)
            | Q(ProjectUpdate___project__in=project_ids) |
            Q(InventoryUpdate___inventory_source__inventory__organization=self)
        )
Ejemplo n.º 3
0
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin,
                   CustomVirtualEnvMixin, RelatedJobsMixin):
    """
    An organization is the basic unit of multi-tenancy divisions
    """
    class Meta:
        app_label = 'main'
        ordering = ('name', )

    instance_groups = OrderedManyToManyField(
        'InstanceGroup',
        blank=True,
        through='OrganizationInstanceGroupMembership')
    galaxy_credentials = OrderedManyToManyField(
        'Credential',
        blank=True,
        through='OrganizationGalaxyCredentialMembership',
        related_name='%(class)s_galaxy_credentials')
    max_hosts = models.PositiveIntegerField(
        blank=True,
        default=0,
        help_text=
        _('Maximum number of hosts allowed to be managed by this organization.'
          ),
    )
    notification_templates_approvals = models.ManyToManyField(
        "NotificationTemplate",
        blank=True,
        related_name='%(class)s_notification_templates_for_approvals')
    default_environment = models.ForeignKey(
        'ExecutionEnvironment',
        null=True,
        blank=True,
        default=None,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text=
        _('The default execution environment for jobs run by this organization.'
          ),
    )

    admin_role = ImplicitRoleField(parent_role='singleton:' +
                                   ROLE_SINGLETON_SYSTEM_ADMINISTRATOR, )
    execute_role = ImplicitRoleField(parent_role='admin_role', )
    project_admin_role = ImplicitRoleField(parent_role='admin_role', )
    inventory_admin_role = ImplicitRoleField(parent_role='admin_role', )
    credential_admin_role = ImplicitRoleField(parent_role='admin_role', )
    workflow_admin_role = ImplicitRoleField(parent_role='admin_role', )
    notification_admin_role = ImplicitRoleField(parent_role='admin_role', )
    job_template_admin_role = ImplicitRoleField(parent_role='admin_role', )
    execution_environment_admin_role = ImplicitRoleField(
        parent_role='admin_role', )
    auditor_role = ImplicitRoleField(parent_role='singleton:' +
                                     ROLE_SINGLETON_SYSTEM_AUDITOR, )
    member_role = ImplicitRoleField(parent_role=['admin_role'])
    read_role = ImplicitRoleField(parent_role=[
        'member_role',
        'auditor_role',
        'execute_role',
        'project_admin_role',
        'inventory_admin_role',
        'workflow_admin_role',
        'notification_admin_role',
        'credential_admin_role',
        'job_template_admin_role',
        'approval_role',
        'execution_environment_admin_role',
    ], )
    approval_role = ImplicitRoleField(parent_role='admin_role', )

    def get_absolute_url(self, request=None):
        return reverse('api:organization_detail',
                       kwargs={'pk': self.pk},
                       request=request)

    '''
    RelatedJobsMixin
    '''

    def _get_related_jobs(self):
        return UnifiedJob.objects.non_polymorphic().filter(organization=self)

    def create_default_galaxy_credential(self):
        from awx.main.models import Credential

        public_galaxy_credential = Credential.objects.filter(
            managed=True, name='Ansible Galaxy').first()
        if public_galaxy_credential is not None and public_galaxy_credential not in self.galaxy_credentials.all(
        ):
            self.galaxy_credentials.add(public_galaxy_credential)