tableVisibilityModeSettings.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. TableVisibilityModeSettings = new Mongo.Collection('tableVisibilityModeSettings');
  2. TableVisibilityModeSettings.attachSchema(
  3. new SimpleSchema({
  4. _id: {
  5. type: String,
  6. },
  7. booleanValue: {
  8. type: Boolean,
  9. optional: true,
  10. },
  11. sort: {
  12. type: Number,
  13. decimal: true,
  14. },
  15. createdAt: {
  16. type: Date,
  17. optional: true,
  18. // eslint-disable-next-line consistent-return
  19. autoValue() {
  20. if (this.isInsert) {
  21. return new Date();
  22. } else if (this.isUpsert) {
  23. return { $setOnInsert: new Date() };
  24. } else {
  25. this.unset();
  26. }
  27. },
  28. },
  29. modifiedAt: {
  30. type: Date,
  31. denyUpdate: false,
  32. // eslint-disable-next-line consistent-return
  33. autoValue() {
  34. if (this.isInsert || this.isUpsert || this.isUpdate) {
  35. return new Date();
  36. } else {
  37. this.unset();
  38. }
  39. },
  40. },
  41. }),
  42. );
  43. TableVisibilityModeSettings.allow({
  44. update(userId) {
  45. const user = Users.findOne(userId);
  46. return user && user.isAdmin;
  47. },
  48. });
  49. if (Meteor.isServer) {
  50. Meteor.startup(() => {
  51. TableVisibilityModeSettings._collection._ensureIndex({ modifiedAt: -1 });
  52. TableVisibilityModeSettings.upsert(
  53. { _id: 'tableVisibilityMode-allowPrivateOnly' },
  54. {
  55. $setOnInsert: {
  56. booleanValue: false,
  57. sort: 0,
  58. },
  59. },
  60. );
  61. });
  62. }
  63. TableVisibilityModeSettings.helpers({
  64. allowPrivateOnly() {
  65. return TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  66. },
  67. });
  68. export default TableVisibilityModeSettings;