org.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Org = new Mongo.Collection('org');
  2. /**
  3. * A Organization in Wekan. A Enterprise in Trello.
  4. */
  5. Org.attachSchema(
  6. new SimpleSchema({
  7. orgDisplayName: {
  8. /**
  9. * the name to display for the organization
  10. */
  11. type: String,
  12. optional: true,
  13. },
  14. orgDesc: {
  15. /**
  16. * the description the organization
  17. */
  18. type: String,
  19. optional: true,
  20. max: 190,
  21. },
  22. orgShortName: {
  23. /**
  24. * short name of the organization
  25. */
  26. type: String,
  27. optional: true,
  28. max: 255,
  29. },
  30. orgWebsite: {
  31. /**
  32. * website of the organization
  33. */
  34. type: String,
  35. optional: true,
  36. max: 255,
  37. },
  38. orgIsActive: {
  39. /**
  40. * status of the organization
  41. */
  42. type: Boolean,
  43. optional: true,
  44. },
  45. createdAt: {
  46. /**
  47. * creation date of the organization
  48. */
  49. type: Date,
  50. denyUpdate: false,
  51. // eslint-disable-next-line consistent-return
  52. autoValue() {
  53. if (this.isInsert) {
  54. return new Date();
  55. } else if (this.isUpsert) {
  56. return { $setOnInsert: new Date() };
  57. } else {
  58. this.unset();
  59. }
  60. },
  61. },
  62. modifiedAt: {
  63. type: Date,
  64. denyUpdate: false,
  65. // eslint-disable-next-line consistent-return
  66. autoValue() {
  67. if (this.isInsert || this.isUpsert || this.isUpdate) {
  68. return new Date();
  69. } else {
  70. this.unset();
  71. }
  72. },
  73. },
  74. }),
  75. );
  76. if (Meteor.isServer) {
  77. Meteor.methods({
  78. setCreateOrg(
  79. orgDisplayName,
  80. orgDesc,
  81. orgShortName,
  82. orgWebsite,
  83. orgIsActive,
  84. ) {
  85. if (Meteor.user() && Meteor.user().isAdmin) {
  86. check(orgDisplayName, String);
  87. check(orgDesc, String);
  88. check(orgShortName, String);
  89. check(orgWebsite, String);
  90. check(orgIsActive, Boolean);
  91. const nOrgNames = Org.find({ orgShortName }).count();
  92. if (nOrgNames > 0) {
  93. throw new Meteor.Error('orgname-already-taken');
  94. } else {
  95. Org.insert({
  96. orgDisplayName,
  97. orgDesc,
  98. orgShortName,
  99. orgWebsite,
  100. orgIsActive,
  101. });
  102. }
  103. }
  104. },
  105. setOrgDisplayName(org, orgDisplayName) {
  106. if (Meteor.user() && Meteor.user().isAdmin) {
  107. check(org, Object);
  108. check(orgDisplayName, String);
  109. Org.update(org, {
  110. $set: { orgDisplayName: orgDisplayNameorgShortName},
  111. });
  112. }
  113. },
  114. setOrgDesc(org, orgDesc) {
  115. if (Meteor.user() && Meteor.user().isAdmin) {
  116. check(org, Object);
  117. check(orgDesc, String);
  118. Org.update(org, {
  119. $set: { orgDesc: orgDesc },
  120. });
  121. }
  122. },
  123. setOrgShortName(org, orgShortName) {
  124. if (Meteor.user() && Meteor.user().isAdmin) {
  125. check(org, Object);
  126. check(orgShortName, String);
  127. Org.update(org, {
  128. $set: { orgShortName: orgShortName },
  129. });
  130. }
  131. },
  132. setOrgIsActive(org, orgIsActive) {
  133. if (Meteor.user() && Meteor.user().isAdmin) {
  134. check(org, Object);
  135. check(orgIsActive, Boolean);
  136. Org.update(org, {
  137. $set: { orgIsActive: orgIsActive },
  138. });
  139. }
  140. },
  141. setOrgAllFields(org, orgDisplayName, orgDesc, orgShortName, orgWebsite, orgIsActive) {
  142. if (Meteor.user() && Meteor.user().isAdmin) {
  143. check(org, Object);
  144. check(orgDisplayName, String);
  145. check(orgDesc, String);
  146. check(orgShortName, String);
  147. check(orgWebsite, String);
  148. check(orgIsActive, Boolean);
  149. Org.update(org, {
  150. $set: { orgDisplayName : orgDisplayName, orgDesc : orgDesc, orgShortName : orgShortName, orgWebsite : orgWebsite, orgIsActive: orgIsActive },
  151. });
  152. }
  153. },
  154. });
  155. }
  156. if (Meteor.isServer) {
  157. // Index for Organization name.
  158. Meteor.startup(() => {
  159. // Org._collection._ensureIndex({ name: -1 });
  160. Org._collection._ensureIndex({ orgDisplayName: -1 });
  161. });
  162. }
  163. export default Org;