mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 10:27:34 -02:30
Adding organization reference to the custom inventory script
This commit is contained in:
@@ -977,7 +977,7 @@ class CustomInventoryScriptSerializer(BaseSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CustomInventoryScript
|
model = CustomInventoryScript
|
||||||
fields = ('*', "script")
|
fields = ('*', "script", "organization")
|
||||||
|
|
||||||
class InventorySourceOptionsSerializer(BaseSerializer):
|
class InventorySourceOptionsSerializer(BaseSerializer):
|
||||||
|
|
||||||
|
|||||||
@@ -1464,10 +1464,14 @@ class CustomInventoryScriptAccess(BaseAccess):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
qs = self.model.objects.filter(active=True).distinct()
|
qs = self.model.objects.filter(active=True).distinct()
|
||||||
|
if not self.user.is_superuser:
|
||||||
|
qs = qs.filter(Q(organization__admins__in=[self.user]) | Q(organization__users__in=[self.user]))
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def can_read(self, obj):
|
def can_read(self, obj):
|
||||||
return True
|
if self.user.is_superuser:
|
||||||
|
return True
|
||||||
|
return bool(obj.organization in self.user.organizations.all() or obj.organization in self.user.admin_of_organizations.all())
|
||||||
|
|
||||||
def can_add(self, data):
|
def can_add(self, data):
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Migration(SchemaMigration):
|
|||||||
('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
|
('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
|
||||||
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=512)),
|
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=512)),
|
||||||
('script', self.gf('django.db.models.fields.TextField')(default='', blank=True)),
|
('script', self.gf('django.db.models.fields.TextField')(default='', blank=True)),
|
||||||
|
('organization', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['main.Organization'])),
|
||||||
))
|
))
|
||||||
db.send_create_signal('main', ['CustomInventoryScript'])
|
db.send_create_signal('main', ['CustomInventoryScript'])
|
||||||
|
|
||||||
|
|||||||
@@ -1235,6 +1235,7 @@ class CustomInventoryScript(CommonModel):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
unique_together = [('name', 'organization')]
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|
||||||
script = models.TextField(
|
script = models.TextField(
|
||||||
@@ -1242,6 +1243,12 @@ class CustomInventoryScript(CommonModel):
|
|||||||
default='',
|
default='',
|
||||||
help_text=_('Inventory script contents'),
|
help_text=_('Inventory script contents'),
|
||||||
)
|
)
|
||||||
|
organization = models.ForeignKey(
|
||||||
|
'Organization',
|
||||||
|
related_name='custom_inventory_scripts',
|
||||||
|
help_text=_('Organization owning this inventory script'),
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:inventory_script_detail', args=(self.pk,))
|
return reverse('api:inventory_script_detail', args=(self.pk,))
|
||||||
|
|||||||
Reference in New Issue
Block a user