def role_for(user, instance): """ Looks up the instance's user/group and compares against the user and the user's list of all groups. Then determines if the user is the owner, group or world of this instance. """ return _figure_role( (instance.user_id, instance.group_id), user.id, user.all_group_ids )
def instance_permissions(user, instance=None): """ How should this user see this instance? Figure's out the user's status compared to the instance, then figures owner/group/world for the user, then fires off a new copy of that permissions dictionary for that role. If instance is missing, we're talking about this site's group and user as figured in the settings. """ if not instance: top_group = user.status_over(SITE_GROUP) user_role = _figure_role((SITE_OWNER.pk, SITE_GROUP.name), user.pk, user.all_group_ids) else: top_group = user.status_over(instance.group) user_role = role_for(user, instance) return narrow_config(top_group.name)[user_role]