team.js 3.9 KB

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