Merge pull request #2654 from wwitzel3/issue-2485

reduce activity stream noise
This commit is contained in:
Wayne Witzel III 2016-06-27 15:47:59 -04:00 committed by GitHub
commit 5456b209ac
2 changed files with 21 additions and 1 deletions

View File

@ -63,11 +63,14 @@ def register_access(model_class, access_class):
@property
def user_admin_role(self):
return Role.objects.get(
role = Role.objects.get(
content_type=ContentType.objects.get_for_model(User),
object_id=self.id,
role_field='admin_role'
)
# Trick the user.admin_role so that the signal filtering for RBAC activity stream works as intended.
role.parents = [org.admin_role.pk for org in self.organizations]
return role
def user_accessible_objects(user, role_name):
return ResourceMixin._accessible_objects(User, user, role_name)

View File

@ -166,11 +166,28 @@ def rbac_activity_stream(instance, sender, **kwargs):
return
elif sender.__name__ == 'Role_parents':
role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first()
# don't record implicit creation / parents
if role is not None and role.content_type is not None:
parent = role.content_type.name + "." + role.role_field
# Get the list of implicit parents that were defined at the class level.
# We have to take this list from the class property to avoid including parents
# that may have been added since the creation of the ImplicitRoleField
implicit_parents = getattr(instance.content_object.__class__, instance.role_field).field.parent_role
if type(implicit_parents) != list:
implicit_parents = [implicit_parents]
# Ignore any singleton parents we find. If the parent for the role
# matches any of the implicit parents we find, skip recording the activity stream.
for ip in implicit_parents:
if '.' not in ip and 'singleton:' not in ip:
ip = instance.content_type.name + "." + ip
if parent == ip:
return
else:
role = instance
instance = instance.content_object
else:
role = kwargs['model'].objects.filter(pk__in=kwargs['pk_set']).first()
activity_stream_associate(sender, instance, role=role, **kwargs)
def cleanup_detached_labels_on_deleted_parent(sender, instance, **kwargs):