|
@@ -7,6 +7,7 @@ from rapid import filters
|
|
|
|
|
|
import itertools
|
|
import itertools
|
|
from django.db import models
|
|
from django.db import models
|
|
|
|
+from rapid import permissions
|
|
|
|
|
|
|
|
|
|
class InstanceData:
|
|
class InstanceData:
|
|
@@ -56,18 +57,10 @@ class InstanceData:
|
|
return self.model.is_controlled()
|
|
return self.model.is_controlled()
|
|
|
|
|
|
def can_read(self):
|
|
def can_read(self):
|
|
- if self.can_write():
|
|
|
|
- return True
|
|
|
|
- vw = registry.model_entry(self.model.model).permission_set(self.request)
|
|
|
|
- if vw:
|
|
|
|
- return vw.filter(pk=self.instance.pk).exists()
|
|
|
|
- return False
|
|
|
|
|
|
+ return self.has_permission(self.request, 'view')
|
|
|
|
|
|
def can_write(self):
|
|
def can_write(self):
|
|
- ed = registry.model_entry(self.model.model)['edit'].permission_set(self.request)
|
|
|
|
- if ed:
|
|
|
|
- return ed.filter(pk=self.instance.pk).exists()
|
|
|
|
- return False
|
|
|
|
|
|
+ return self.has_permission(self.request, 'edit')
|
|
|
|
|
|
def view_url(self):
|
|
def view_url(self):
|
|
return registry.get_url_of_action(self.model.model, "view", pk=self.instance.pk)
|
|
return registry.get_url_of_action(self.model.model, "view", pk=self.instance.pk)
|
|
@@ -101,8 +94,7 @@ class InstanceData:
|
|
acts = registry.model_entry(self.model.model)
|
|
acts = registry.model_entry(self.model.model)
|
|
if self.request:
|
|
if self.request:
|
|
for a in acts.values():
|
|
for a in acts.values():
|
|
- if a.permission_set(self.request) and\
|
|
|
|
- a.permission_set(self.request).filter(pk=self.instance.pk).exists() and\
|
|
|
|
|
|
+ if self.has_permission(self.request, a.action.name) and\
|
|
a.action.visibility > Action.Visibility.hidden:
|
|
a.action.visibility > Action.Visibility.hidden:
|
|
yield (a, a.get_url(self.instance))
|
|
yield (a, a.get_url(self.instance))
|
|
|
|
|
|
@@ -124,8 +116,8 @@ class InstanceData:
|
|
def has_permission(self, request, action_name):
|
|
def has_permission(self, request, action_name):
|
|
m = registry.model_entry(self.model.model).get(action_name)
|
|
m = registry.model_entry(self.model.model).get(action_name)
|
|
if m:
|
|
if m:
|
|
- return m.permission_set(request) and\
|
|
|
|
- m.permission_set(request).filter(pk=self.instance.pk).exists()
|
|
|
|
|
|
+ perm = m.permission_set.instances
|
|
|
|
+ return permissions.has_instance(self.model, perm(request), self.instance)
|
|
return False
|
|
return False
|
|
|
|
|
|
def __unicode__(self):
|
|
def __unicode__(self):
|
|
@@ -211,8 +203,7 @@ class ModelData:
|
|
acts = registry.model_entry(self.model)
|
|
acts = registry.model_entry(self.model)
|
|
if self.request:
|
|
if self.request:
|
|
for a in acts.values():
|
|
for a in acts.values():
|
|
- if a.permission_set(self.request) and\
|
|
|
|
- a.permission_set(self.request).exists() and\
|
|
|
|
|
|
+ if self.has_permission(self.request, a.action.name) and\
|
|
not a.action.query_parameters and\
|
|
not a.action.query_parameters and\
|
|
a.action.visibility > Action.Visibility.hidden:
|
|
a.action.visibility > Action.Visibility.hidden:
|
|
yield (a, a.get_url())
|
|
yield (a, a.get_url())
|
|
@@ -220,8 +211,7 @@ class ModelData:
|
|
def has_permission(self, request, action_name):
|
|
def has_permission(self, request, action_name):
|
|
m = registry.model_entry(self.model).get(action_name)
|
|
m = registry.model_entry(self.model).get(action_name)
|
|
if m:
|
|
if m:
|
|
- return m.permission_set(request) and\
|
|
|
|
- m.permission_set(request).exists()
|
|
|
|
|
|
+ return bool(m.permission_set.model(request))
|
|
return False
|
|
return False
|
|
|
|
|
|
def field_by_name(self, field_name):
|
|
def field_by_name(self, field_name):
|