utils.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. allowIsBoardAdmin = function(userId, board) {
  2. return board && board.hasAdmin(userId);
  3. };
  4. allowIsBoardMember = function(userId, board) {
  5. return board && board.hasMember(userId);
  6. };
  7. allowIsAnyBoardMember = function(userId, boards) {
  8. return _.some(boards, board => {
  9. return board && board.hasMember(userId);
  10. });
  11. };
  12. allowIsBoardMemberCommentOnly = function(userId, board) {
  13. return board && board.hasMember(userId) && !board.hasCommentOnly(userId);
  14. };
  15. allowIsBoardMemberNoComments = function(userId, board) {
  16. return board && board.hasMember(userId) && !board.hasNoComments(userId);
  17. };
  18. allowIsBoardMemberByCard = function(userId, card) {
  19. const board = card.board();
  20. return board && board.hasMember(userId);
  21. };
  22. // Policy: can a user update a board's 'sort' field?
  23. // Requirements:
  24. // - user must be authenticated
  25. // - update must include 'sort' field
  26. // - user must be a member of the board
  27. canUpdateBoardSort = function(userId, board, fieldNames) {
  28. return !!userId && _.contains(fieldNames || [], 'sort') && allowIsBoardMember(userId, board);
  29. };