announcements.js 647 B

123456789101112131415161718192021222324252627282930313233343536
  1. Announcements = new Mongo.Collection('announcements');
  2. Announcements.attachSchema(new SimpleSchema({
  3. enabled: {
  4. type: Boolean,
  5. defaultValue: false,
  6. },
  7. title: {
  8. type: String,
  9. optional: true,
  10. },
  11. body: {
  12. type: String,
  13. optional: true,
  14. },
  15. sort: {
  16. type: Number,
  17. decimal: true,
  18. },
  19. }));
  20. Announcements.allow({
  21. update(userId) {
  22. const user = Users.findOne(userId);
  23. return user && user.isAdmin;
  24. },
  25. });
  26. if (Meteor.isServer) {
  27. Meteor.startup(() => {
  28. const announcements = Announcements.findOne({});
  29. if(!announcements){
  30. Announcements.insert({enabled: false, sort: 0});
  31. }
  32. });
  33. }