org.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. Org = new Mongo.Collection('org');
  2. /**
  3. * A Organization in Wekan. A Enterprise in Trello.
  4. */
  5. Org.attachSchema(
  6. new SimpleSchema({
  7. _id: {
  8. /**
  9. * the organization id
  10. */
  11. type: Number,
  12. optional: true,
  13. // eslint-disable-next-line consistent-return
  14. autoValue() {
  15. if (this.isInsert && !this.isSet) {
  16. return incrementCounter('counters', 'orgId', 1);
  17. }
  18. },
  19. },
  20. displayName: {
  21. /**
  22. * the name to display for the organization
  23. */
  24. type: String,
  25. optional: true,
  26. },
  27. desc: {
  28. /**
  29. * the description the organization
  30. */
  31. type: String,
  32. optional: true,
  33. max: 190,
  34. },
  35. name: {
  36. /**
  37. * short name of the organization
  38. */
  39. type: String,
  40. optional: true,
  41. max: 255,
  42. },
  43. website: {
  44. /**
  45. * website of the organization
  46. */
  47. type: String,
  48. optional: true,
  49. max: 255,
  50. },
  51. teams: {
  52. /**
  53. * List of teams of a organization
  54. */
  55. type: [Object],
  56. // eslint-disable-next-line consistent-return
  57. autoValue() {
  58. if (this.isInsert && !this.isSet) {
  59. return [
  60. {
  61. teamId: this.teamId,
  62. isAdmin: true,
  63. isActive: true,
  64. isNoComments: false,
  65. isCommentOnly: false,
  66. isWorker: false,
  67. },
  68. ];
  69. }
  70. },
  71. },
  72. 'teams.$.teamId': {
  73. /**
  74. * The uniq ID of the team
  75. */
  76. type: String,
  77. },
  78. 'teams.$.isAdmin': {
  79. /**
  80. * Is the team an admin of the board?
  81. */
  82. type: Boolean,
  83. },
  84. 'teams.$.isActive': {
  85. /**
  86. * Is the team active?
  87. */
  88. type: Boolean,
  89. },
  90. 'teams.$.isNoComments': {
  91. /**
  92. * Is the team not allowed to make comments
  93. */
  94. type: Boolean,
  95. optional: true,
  96. },
  97. 'teams.$.isCommentOnly': {
  98. /**
  99. * Is the team only allowed to comment on the board
  100. */
  101. type: Boolean,
  102. optional: true,
  103. },
  104. 'teams.$.isWorker': {
  105. /**
  106. * Is the team only allowed to move card, assign himself to card and comment
  107. */
  108. type: Boolean,
  109. optional: true,
  110. },
  111. createdAt: {
  112. /**
  113. * creation date of the organization
  114. */
  115. type: Date,
  116. // eslint-disable-next-line consistent-return
  117. autoValue() {
  118. if (this.isInsert) {
  119. return new Date();
  120. } else if (this.isUpsert) {
  121. return { $setOnInsert: new Date() };
  122. } else {
  123. this.unset();
  124. }
  125. },
  126. },
  127. modifiedAt: {
  128. type: Date,
  129. denyUpdate: false,
  130. // eslint-disable-next-line consistent-return
  131. autoValue() {
  132. if (this.isInsert || this.isUpsert || this.isUpdate) {
  133. return new Date();
  134. } else {
  135. this.unset();
  136. }
  137. },
  138. },
  139. }),
  140. );
  141. if (Meteor.isServer) {
  142. // Index for Organization name.
  143. Meteor.startup(() => {
  144. Org._collection._ensureIndex({ name: -1 });
  145. });
  146. }
  147. export default Org;