org.js 3.2 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. 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. createdAt: {
  39. /**
  40. * creation date of the organization
  41. */
  42. type: Date,
  43. // eslint-disable-next-line consistent-return
  44. autoValue() {
  45. if (this.isInsert) {
  46. return new Date();
  47. } else if (this.isUpsert) {
  48. return { $setOnInsert: new Date() };
  49. } else {
  50. this.unset();
  51. }
  52. },
  53. },
  54. modifiedAt: {
  55. type: Date,
  56. denyUpdate: false,
  57. // eslint-disable-next-line consistent-return
  58. autoValue() {
  59. if (this.isInsert || this.isUpsert || this.isUpdate) {
  60. return new Date();
  61. } else {
  62. this.unset();
  63. }
  64. },
  65. },
  66. }),
  67. );
  68. if (Meteor.isServer) {
  69. Meteor.methods({
  70. setCreateOrg(
  71. orgDisplayName,
  72. orgDesc,
  73. orgShortName,
  74. orgWebsite,
  75. orgIsActive,
  76. ) {
  77. if (Meteor.user() && Meteor.user().isAdmin) {
  78. check(orgDisplayName, String);
  79. check(orgDesc, String);
  80. check(orgShortName, String);
  81. check(orgWebsite, String);
  82. check(orgIsActive, String);
  83. const nOrgNames = Org.find({ orgShortName }).count();
  84. if (nOrgNames > 0) {
  85. throw new Meteor.Error('orgname-already-taken');
  86. } else {
  87. Org.insert({
  88. orgDisplayName,
  89. orgDesc,
  90. orgShortName,
  91. orgWebsite,
  92. orgIsActive,
  93. });
  94. }
  95. }
  96. },
  97. setOrgDisplayName(org, orgDisplayName) {
  98. if (Meteor.user() && Meteor.user().isAdmin) {
  99. check(org, String);
  100. check(orgDisplayName, String);
  101. Org.update(org, {
  102. $set: { orgDisplayName: orgDisplayName },
  103. });
  104. }
  105. },
  106. setOrgDesc(org, orgDesc) {
  107. if (Meteor.user() && Meteor.user().isAdmin) {
  108. check(org, String);
  109. check(orgDesc, String);
  110. Org.update(org, {
  111. $set: { orgDesc: orgDesc },
  112. });
  113. }
  114. },
  115. setOrgShortName(org, orgShortName) {
  116. if (Meteor.user() && Meteor.user().isAdmin) {
  117. check(org, String);
  118. check(orgShortName, String);
  119. Org.update(org, {
  120. $set: { orgShortName: orgShortName },
  121. });
  122. }
  123. },
  124. setOrgIsActive(org, orgIsActive) {
  125. if (Meteor.user() && Meteor.user().isAdmin) {
  126. check(org, String);
  127. check(orgIsActive, String);
  128. Org.update(org, {
  129. $set: { orgIsActive: orgIsActive },
  130. });
  131. }
  132. },
  133. });
  134. }
  135. if (Meteor.isServer) {
  136. // Index for Organization name.
  137. Meteor.startup(() => {
  138. Org._collection._ensureIndex({ name: -1 });
  139. });
  140. }
  141. export default Org;