team.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. createdAt: {
  39. /**
  40. * creation date of the team
  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. setCreateTeam(
  71. teamDisplayName,
  72. teamDesc,
  73. teamShortName,
  74. teamWebsite,
  75. teamIsActive,
  76. ) {
  77. if (Meteor.user() && Meteor.user().isAdmin) {
  78. check(teamDisplayName, String);
  79. check(teamDesc, String);
  80. check(teamShortName, String);
  81. check(teamWebsite, String);
  82. check(teamIsActive, String);
  83. const nTeamNames = Team.find({ teamShortName }).count();
  84. if (nTeamNames > 0) {
  85. throw new Meteor.Error('teamname-already-taken');
  86. } else {
  87. Team.insert({
  88. teamDisplayName,
  89. teamDesc,
  90. teamShortName,
  91. teamWebsite,
  92. teamIsActive,
  93. });
  94. }
  95. }
  96. },
  97. setTeamDisplayName(team, teamDisplayName) {
  98. if (Meteor.user() && Meteor.user().isAdmin) {
  99. check(team, String);
  100. check(teamDisplayName, String);
  101. Team.update(team, {
  102. $set: { teamDisplayName: teamDisplayName },
  103. });
  104. }
  105. },
  106. setTeamDesc(team, teamDesc) {
  107. if (Meteor.user() && Meteor.user().isAdmin) {
  108. check(team, String);
  109. check(teamDesc, String);
  110. Team.update(team, {
  111. $set: { teamDesc: teamDesc },
  112. });
  113. }
  114. },
  115. setTeamShortName(team, teamShortName) {
  116. if (Meteor.user() && Meteor.user().isAdmin) {
  117. check(team, String);
  118. check(teamShortName, String);
  119. Team.update(team, {
  120. $set: { teamShortName: teamShortName },
  121. });
  122. }
  123. },
  124. setTeamIsActive(team, teamIsActive) {
  125. if (Meteor.user() && Meteor.user().isAdmin) {
  126. check(team, String);
  127. check(teamIsActive, String);
  128. Team.update(team, {
  129. $set: { teamIsActive: teamIsActive },
  130. });
  131. }
  132. },
  133. });
  134. }
  135. if (Meteor.isServer) {
  136. // Index for Team name.
  137. Meteor.startup(() => {
  138. Team._collection._ensureIndex({ name: -1 });
  139. });
  140. }
  141. export default Team;