def initDataset(self): context = self.context principal = context.__parent__.principal self.dataset = getUtility(ICatalog).searchResults( sort_on='modified', sort_order='reverse', noPublishing = True, noSecurityChecks=True, draftStatus = {'any_of': ('submitted',)}, draftPublishable = {'any_of': listAllowedRoles(principal, context)})
def __call__(self, context): if not IDraftContent.providedBy(context): return Vocabulary(()) ct = IContentType(context) types = [] for tp in ct.destination: types.append(tp.name) kwargs = {} if types: kwargs['type'] = {'any_of': types} request = getRequest() catalog = getUtility(ICatalog) perms = {} permissions = [] for id in listAllowedRoles(request.principal, context): perms[ct.submit] = 1 perms[ct.publish] = 1 permissions.append((ct.submit, id)) permissions.append((ct.publish, id)) results = catalog.searchResults( draftSubmitTo={'any_of': permissions}, **kwargs) if not results: return Vocabulary(()) perms = perms.keys() ids = getUtility(IIntIds) contents = [] for content in results: allow = False for perm in perms: if checkPermission(perm, content): allow = True break if allow: contents.append( (getPath(content), IItem(content).title, ids.getId(content), content)) contents.sort() terms = [] for path, title, id, content in contents: term = SimpleTerm( id, str(id), getMultiAdapter((content, request), IBreadcrumb)) term.content = content terms.append(term) return Vocabulary(terms)
def getDraftNotification(context): request = getRequest() if request is not None: principal = request.principal results = getUtility(ICatalog).searchResults( noPublishing=True, noSecurityChecks=True, draftPublishTo={"any_of": listAllowedRoles(principal, context)} ) if bool(results): return DraftNotification(context)
def search(self, object=None, contexts=(), sort_on='date', sort_order='reverse', noSecurityChecks=False, **kw): ids = getUtility(IIntIds) query = dict(kw) # records for object if type(object) is not type({}) and object is not None: oid = ids.queryId(removeAllProxies(object)) if oid is None: return ResultSet(IFBTree(), getUtility(IActivity)) query['object'] = {'any_of': (oid,)} # context if not contexts: contexts = (getSite(),) c = [] for context in contexts: id = ids.queryId(removeAllProxies(context)) if id is not None: c.append(id) query['contexts'] = {'any_of': c} # security if not noSecurityChecks: request = getRequest() if request is not None: users = listAllowedRoles(request.principal, getSite()) if 'zope.Anonymous' not in users: users.append('zope.Anonymous') query['allowedUsers'] = {'any_of': users} # apply searh terms results = self.apply(query) if results is None: results = IFBTree() # sort result by index if sort_on and sort_on in self: sortable = ISortable(self[sort_on], None) if sortable is not None: results = sortable.sort(results) if sort_order == 'reverse': return ReverseResultSet(results, getUtility(IActivity)) else: return ResultSet(results, getUtility(IActivity))
def search(self, content=None, contexts=(), sort_on='date', sort_order='reverse', types=(), approved=()): ids = getUtility(IIntIds) indexes = list(self.values()) query = {} # comments for content if content: query['content'] = {'any_of':(ids.getId(removeAllProxies(content)),)} # context if contexts: c = [] for context in contexts: id = ids.queryId(removeAllProxies(context)) if id is not None: c.append(id) query['contexts'] = {'any_of': c} # content type if types: query['type'] = {'any_of': types} # security users = listAllowedRoles(getRequest().principal, getSite()) if 'zope.Anonymous' not in users: users.append('zope.Anonymous') query['access'] = {'any_of': users} # comments approved if approved: query['approved'] = {'any_of': approved} # apply searh terms results = self.apply(query) if results is None: results = IFBTree() # sort result by index if sort_on and sort_on in self: sortable = ISortable(self[sort_on], None) if sortable is not None: results = sortable.sort(results) if sort_order == 'reverse': return ReverseResultSet(results, ids) else: return ResultSet(results, ids)
def isAvailable(self): principal = self.context.principal request = self.request if request is None: return False if request.principal.id != principal.id: return False catalog = queryUtility(ICatalog) if catalog is not None: results = catalog.searchResults( noPublishing = True, noSecurityChecks=True, draftStatus = {'any_of': ('submitted',)}, draftPublishable = { 'any_of': listAllowedRoles(principal, self.context)}) return bool(results) return False
def addingInfo(self): request = self.request url = self.url if IDraftContentType.providedBy(self.context): curname = self.context.__name__ else: curname = u'' ctool = getUtility(ICatalog) allowed = listAllowedRoles(self.request.principal, getSite()) result = [] for name, ptype in getUtilitiesFor(IDraftContentType): permissions = [] for id in allowed: permissions.append((ptype.publish, id)) permissions.append((ptype.submit, id)) results = ctool.searchResults( noPublishing = True, noSecurityChecks = True, draftSubmitTo={'any_of': permissions}) if not results: continue action = '%s/%s/'%(url, ptype.name) result.append( {'id': ptype.name, 'title': ptype.title, 'description': ptype.description, 'action': action, 'icon': queryMultiAdapter( (ptype.contenttype, request), name='zmi_icon'), 'selected': ptype.name == curname}) result.sort(lambda a, b: cmp(a['title'], b['title'])) return result