mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 11:20:39 -03:30
Adding organization reference to the custom inventory script
This commit is contained in:
parent
9a90277e5e
commit
19c0d04885
@ -977,7 +977,7 @@ class CustomInventoryScriptSerializer(BaseSerializer):
|
||||
|
||||
class Meta:
|
||||
model = CustomInventoryScript
|
||||
fields = ('*', "script")
|
||||
fields = ('*', "script", "organization")
|
||||
|
||||
class InventorySourceOptionsSerializer(BaseSerializer):
|
||||
|
||||
|
||||
@ -1464,10 +1464,14 @@ class CustomInventoryScriptAccess(BaseAccess):
|
||||
|
||||
def get_queryset(self):
|
||||
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
|
||||
|
||||
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):
|
||||
if self.user.is_superuser:
|
||||
|
||||
@ -19,6 +19,7 @@ class Migration(SchemaMigration):
|
||||
('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
|
||||
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=512)),
|
||||
('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'])
|
||||
|
||||
|
||||
@ -1235,6 +1235,7 @@ class CustomInventoryScript(CommonModel):
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
unique_together = [('name', 'organization')]
|
||||
ordering = ('name',)
|
||||
|
||||
script = models.TextField(
|
||||
@ -1242,6 +1243,12 @@ class CustomInventoryScript(CommonModel):
|
||||
default='',
|
||||
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):
|
||||
return reverse('api:inventory_script_detail', args=(self.pk,))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user