# Path: shared_schema_tenants_custom_data/models.py
# class TenantSpecificTable(SingleTenantModelMixin):
#     name = models.CharField(max_length=255)
# 
#     class Meta:
#         unique_together = [('tenant', 'name')]
# 
#     def __str__(self):
#         return '%s/%s' % (self.tenant.slug, self.name)
# 
#     @property
#     def fields_definitions(self):
#         return TenantSpecificFieldDefinition.objects.filter(
#             table_content_type=ContentType.objects.get_for_model(TenantSpecificTable),
#             table_id=self.id)
# 
#     def save(self, *args, **kwargs):
#         super(TenantSpecificTable, self).save(*args, **kwargs)
#         tstgroup = TenantSpecificTablesGroup.objects.get(group__name='tenant_owner')
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="add", table=self, codename="add_" + self.name))
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="change", table=self, codename="change_" + self.name))
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="delete", table=self, codename="delete_" + self.name))


from rest_framework.permissions import DjangoModelPermissions
from rest_framework import exceptions
from shared_schema_tenants_custom_data.models import TenantSpecificTable


class DjangoTenantSpecificTablePermissions(DjangoModelPermissions):
    tenant_specific_tables_perms_map = {
        'GET': [],
        'OPTIONS': [],
        'HEAD': [],
        'POST': ['add_%(model_name)s'],
        'PUT': ['change_%(model_name)s'],
        'PATCH': ['change_%(model_name)s'],
        'DELETE': ['delete_%(model_name)s'],
    }

    authenticated_users_only = True

    def get_required_permissions(self, method, table_id):
        """
        Given a model and an HTTP method, return the list of permission
        codes that the user is required to have.
        """

# Path: shared_schema_tenants_custom_data/models.py
# class TenantSpecificTable(SingleTenantModelMixin):
#     name = models.CharField(max_length=255)
# 
#     class Meta:
#         unique_together = [('tenant', 'name')]
# 
#     def __str__(self):
#         return '%s/%s' % (self.tenant.slug, self.name)
# 
#     @property
#     def fields_definitions(self):
#         return TenantSpecificFieldDefinition.objects.filter(
#             table_content_type=ContentType.objects.get_for_model(TenantSpecificTable),
#             table_id=self.id)
# 
#     def save(self, *args, **kwargs):
#         super(TenantSpecificTable, self).save(*args, **kwargs)
#         tstgroup = TenantSpecificTablesGroup.objects.get(group__name='tenant_owner')
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="add", table=self, codename="add_" + self.name))
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="change", table=self, codename="change_" + self.name))
#         tstgroup.permissions.add(TenantSpecificTablesPermission.objects.create(
#             name="delete", table=self, codename="delete_" + self.name))


# Path: shared_schema_tenants_custom_data/permissions.py
from rest_framework.permissions import DjangoModelPermissions
from rest_framework import exceptions
from shared_schema_tenants_custom_data.models import TenantSpecificTable



class DjangoTenantSpecificTablePermissions(DjangoModelPermissions):
    tenant_specific_tables_perms_map = {
        'GET': [],
        'OPTIONS': [],
        'HEAD': [],
        'POST': ['add_%(model_name)s'],
        'PUT': ['change_%(model_name)s'],
        'PATCH': ['change_%(model_name)s'],
        'DELETE': ['delete_%(model_name)s'],
    }

    authenticated_users_only = True

    def get_required_permissions(self, method, table_id):
        """
        Given a model and an HTTP method, return the list of permission
        codes that the user is required to have.
        """

        table = TenantSpecificTable.objects.get(id=table_id)