|
|
@@ -17,6 +17,11 @@
|
|
|
|
|
|
from crequest.middleware import CrequestMiddleware
|
|
|
|
|
|
+from django.db import connection, models, transaction
|
|
|
+
|
|
|
+from desktop.conf import ENABLE_ORGANIZATIONS
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def default_organization():
|
|
|
from useradmin.models import Organization
|
|
|
@@ -42,3 +47,27 @@ def _fitered_queryset(queryset, by_owner=False):
|
|
|
queryset = queryset.filter(**filters)
|
|
|
|
|
|
return queryset
|
|
|
+
|
|
|
+
|
|
|
+if ENABLE_ORGANIZATIONS.get():
|
|
|
+ class OrganizationConnectorPermissionManager(models.Manager):
|
|
|
+
|
|
|
+ def get_queryset(self):
|
|
|
+ """Restrict to only organization"""
|
|
|
+ queryset = super(OrganizationConnectorPermissionManager, self).get_queryset()
|
|
|
+ return _fitered_queryset(queryset)
|
|
|
+
|
|
|
+ class OrganizationConnectorPermission(ConnectorPermission):
|
|
|
+ organization = models.ForeignKey(Organization)
|
|
|
+
|
|
|
+ objects = OrganizationConnectorPermissionManager()
|
|
|
+
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ if not kwargs.get('organization'):
|
|
|
+ kwargs['organization'] = get_user_request_organization()
|
|
|
+
|
|
|
+ super(OrganizationConnectorPermission, self).__init__(*args, **kwargs)
|
|
|
+
|
|
|
+ class Meta(ConnectorPermission.Meta):
|
|
|
+ abstract = True
|
|
|
+ unique_together = ('connector', 'action', 'organization',)
|