def get_allowed_to_view(object, default): principals = principals_allowed_by_permission(object, 'view') if not principals: # An empty value tells the catalog to match anything, whereas when # there are no principals with permission to view we want for there # to be no matches. principals = ['NO ONE no way NO HOW',] return principals
def _getInfo(profile, content, ifaces=None): ifaces = ifaces or find_events(content).supported_ctx_ifaces() context = find_supported_interface(content, ifaces) if context is None: context_name = context_url = context_creator = context_type = None else: context_name = context.title context_url = model_path(context) context_creator = context.creator context_type = get_content_type(context) tagger = find_tags(content) if tagger is not None: cloud = list(tagger.getCloud(items=(content.docid,))) tag_counts = sorted(cloud, key=lambda x: x[1], reverse=True)[:3] tags = [x[0] for x in tag_counts] else: tags = () content_type = get_content_type(content) desc = getattr(content, 'description', '') short = len(desc) > 80 and '%s...' % desc[:80] or desc if IPosts.providedBy(content): comment_count = len(content.get('comments', ())) else: comment_count = False content_creator = profile.__name__ if IComment.providedBy(content): # my content filter needs to know if a comment was made inside my post content_creator = content.__parent__.__parent__.creator if hasattr(content, 'likes'): likes = len(content.likes) else: likes = 0 return {'content_type': content_type.getTaggedValue('name'), 'userid': profile.__name__, 'context_name': context_name, 'context_url': context_url, 'context_creator': context_creator, 'context_type': context_type.getTaggedValue('name') if context_type else None, 'content_creator': content_creator, 'url': model_path(content), 'title': content.title, 'description': desc, 'short_description': short, 'allowed': principals_allowed_by_permission(content, 'view'), 'comment_count': comment_count, 'tags': tags, #XXX 'author': profile.title, 'profile_url': '/profiles/%s' % profile.__name__, 'thumbnail': '/profiles/%s/profile_thumbnail' % profile.__name__, 'timestamp': _NOW(), 'likes':likes }
def get_allowed_to_view(object, default): return principals_allowed_by_permission(object, 'view')