2014-10-04 08:48:44 +02:00
|
|
|
docs = new Meteor.Collection 'docs'
|
|
|
|
|
2014-10-04 17:16:27 +02:00
|
|
|
validatedUser = (uid) ->
|
|
|
|
return no unless Meteor.users.findOne uid
|
|
|
|
u = Meteor.users.findOne uid
|
|
|
|
return yes for mail in u.emails when mail.verified is yes; no
|
|
|
|
|
|
|
|
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
|
|
|
|
Meteor.publish 'docs', -> docs.find {}, fields: text: 0
|
|
|
|
Meteor.publish 'user', ->
|
|
|
|
if @userId
|
2014-10-06 08:42:31 +02:00
|
|
|
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
|
2014-10-04 17:16:27 +02:00
|
|
|
else @ready()
|
2014-10-04 09:39:07 +02:00
|
|
|
|
|
|
|
docs.allow
|
2014-10-04 17:16:27 +02:00
|
|
|
insert: (uid,doc) ->
|
2014-10-06 08:42:31 +02:00
|
|
|
if doc.text and doc.title
|
|
|
|
doc.dateCreated = moment().unix()
|
|
|
|
if doc.owner and !uid then return no
|
|
|
|
if uid then doc.owner = uid
|
|
|
|
console.log 'ok'
|
|
|
|
return yes
|
|
|
|
console.log 'nope'
|
|
|
|
return no
|
|
|
|
docs.allow
|
2014-10-04 17:16:27 +02:00
|
|
|
# Owners can update and remove their documents
|
|
|
|
update: (uid,doc) -> doc.owner is uid
|
|
|
|
remove: (uid,doc) -> doc.owner is uid
|
|
|
|
fetch: ['owner'] # Only fetch the owner field from the database documents
|
|
|
|
|
|
|
|
# Save account creation date
|