Vulcan/packages/telescope-search/lib/search.js
Charlie DeTar ed09d0ea7c Fully abstract isAdmin
We're using a fork with a different definition of "isAdmin" (using
``meteor-roles`` rather than the boolean user.isAdmin).  ``lib/user.js``
provides abstracted methods for reading admin state, which makes it very
easy to change our definition -- except that the abstractions weren't
used universally.

This commit finishes the job of using the abstractions, and adds a few
new parts to also allow abstracting setting and updating admin-ness:

 - setAdmin: sets admin status directly on a user object.
 - updateAdmin: executes a mongo update to set admin status.
 - adminMongoQuery: the query parameter for admin-ness, for composing
   user queries with other fields.
 - notAdminMongoQuery: the query parameter for not-admin-ness.
2014-10-03 16:21:06 -06:00

46 lines
1 KiB
JavaScript

// push "search" template to primaryNav
primaryNav.push('search');
Searches = new Meteor.Collection("searches", {
schema: new SimpleSchema({
_id: {
type: String,
optional: true
},
timestamp: {
type: Date
},
keyword: {
type: String
}
})
});
Meteor.startup(function() {
Searches.allow({
update: isAdminById
, remove: isAdminById
});
});
// search post list parameters
viewParameters.search = function (terms, baseParameters) {
// if query is empty, just return parameters that will result in an empty collection
if(typeof terms.query == 'undefined' || !terms.query)
return {find:{_id: 0}}
// log current search in the db
if(Meteor.isServer)
logSearch(terms.query);
var parameters = deepExtend(true, baseParameters, {
find: {
$or: [
{title: {$regex: terms.query, $options: 'i'}},
{url: {$regex: terms.query, $options: 'i'}},
{body: {$regex: terms.query, $options: 'i'}}
]
}
});
return parameters;
}