Add Worker role.

This was originally added at Wekan v3.58,
reverted at Wekan v3.60 because of bugs,
and now after fixes added back.

Thanks to xet7 !

Closes #2788
This commit is contained in:
Lauri Ojansivu 2020-01-05 21:28:14 +02:00
parent 6209b792aa
commit f6f7705f23
19 changed files with 346 additions and 205 deletions

View file

@ -38,6 +38,7 @@ template(name="attachmentsGalery")
| {{_ 'download'}}
if currentUser.isBoardMember
unless currentUser.isCommentOnly
unless currentUser.isWorker
if isImage
a(class="{{#if $eq ../coverId _id}}js-remove-cover{{else}}js-add-cover{{/if}}")
i.fa.fa-thumb-tack
@ -51,5 +52,6 @@ template(name="attachmentsGalery")
if currentUser.isBoardMember
unless currentUser.isCommentOnly
unless currentUser.isWorker
li.attachment-item.add-attachment
a.js-add-attachment {{_ 'add-attachment' }}

View file

@ -97,7 +97,8 @@ Template.dateBadge.helpers({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
});

View file

@ -44,6 +44,7 @@ template(name="cardDetails")
+cardReceivedDate
else
if canModifyCard
unless currentUser.isWorker
a.js-received-date {{_ 'add'}}
.card-details-item.card-details-item-start
@ -54,6 +55,7 @@ template(name="cardDetails")
+cardStartDate
else
if canModifyCard
unless currentUser.isWorker
a.js-start-date {{_ 'add'}}
.card-details-item.card-details-item-due
@ -64,6 +66,7 @@ template(name="cardDetails")
+cardDueDate
else
if canModifyCard
unless currentUser.isWorker
a.js-due-date {{_ 'add'}}
.card-details-item.card-details-item-end
@ -74,6 +77,7 @@ template(name="cardDetails")
+cardEndDate
else
if canModifyCard
unless currentUser.isWorker
a.js-end-date {{_ 'add'}}
.card-details-items
@ -85,6 +89,7 @@ template(name="cardDetails")
+userAvatar(userId=this cardId=../_id)
| {{! XXX Hack to hide syntaxic coloration /// }}
if canModifyCard
unless currentUser.isWorker
a.member.add-member.card-details-item-add-button.js-add-members(title="{{_ 'card-members-title'}}")
i.fa.fa-plus
@ -96,10 +101,14 @@ template(name="cardDetails")
+userAvatarAssignee(userId=this cardId=../_id)
| {{! XXX Hack to hide syntaxic coloration /// }}
if canModifyCard
a.assignee.add-assignee.card-details-item-add-button.js-add-assignees(title="{{_ 'assignee'}}")
i.fa.fa-plus
if currentUser.isWorker
unless assigneeSelected
a.assignee.add-assignee.card-details-item-add-button.js-add-assignees(title="{{_ 'assignee'}}")
i.fa.fa-plus
.card-details-item.card-details-item-labels
h3
i.fa.fa-tags
@ -110,6 +119,7 @@ template(name="cardDetails")
+viewer
= name
if canModifyCard
unless currentUser.isWorker
a.card-label.add-label.js-add-labels(title="{{_ 'card-labels-title'}}")
i.fa.fa-plus
@ -132,6 +142,7 @@ template(name="cardDetails")
//- XXX We should use "editable" to avoid repetiting ourselves
if canModifyCard
unless currentUser.isWorker
h3
i.fa.fa-align-left
card-details-item-title {{_ 'description'}}
@ -165,6 +176,7 @@ template(name="cardDetails")
i.fa.fa-shopping-cart
card-details-item-title {{_ 'requested-by'}}
if canModifyCard
unless currentUser.isWorker
+inlinedForm(classNames="js-card-details-requester")
+editCardRequesterForm
else
@ -183,6 +195,7 @@ template(name="cardDetails")
i.fa.fa-user-plus
card-details-item-title {{_ 'assigned-by'}}
if canModifyCard
unless currentUser.isWorker
+inlinedForm(classNames="js-card-details-assigner")
+editCardAssignerForm
else
@ -266,6 +279,7 @@ template(name="cardDetailsActionsPopup")
i.fa.fa-eye-slash
| {{_ 'watch'}}
if canModifyCard
unless currentUser.isWorker
hr
ul.pop-over-list
//li: a.js-members {{_ 'card-edit-members'}}
@ -297,6 +311,7 @@ template(name="cardDetailsActionsPopup")
a.js-move-card-to-bottom
i.fa.fa-arrow-down
| {{_ 'moveCardToBottom-title'}}
unless currentUser.isWorker
hr
ul.pop-over-list
li
@ -379,6 +394,7 @@ template(name="cardMembersPopup")
i.fa.fa-check
template(name="cardAssigneesPopup")
unless currentUser.isWorker
ul.pop-over-list.js-card-assignee-list
each board.activeMembers
li.item(class="{{#if isCardAssignee}}active{{/if}}")
@ -389,6 +405,16 @@ template(name="cardAssigneesPopup")
| (<span class="username">{{ user.username }}</span>)
if isCardAssignee
i.fa.fa-check
if currentUser.isWorker
ul.pop-over-list.js-card-assignee-list
li.item(class="{{#if currentUser.isCardAssignee}}active{{/if}}")
a.name.js-select-assignee(href="#")
+userAvatar(userId=currentUser._id)
span.full-name
= currentUser.profile.fullname
| (<span class="username">{{ currentUser.username }}</span>)
if currentUser.isCardAssignee
i.fa.fa-check
template(name="userAvatarAssignee")
a.assignee.js-assignee(title="{{userData.profile.fullname}} ({{userData.username}})")
@ -416,8 +442,10 @@ template(name="cardAssigneePopup")
p.quiet @{{ user.username }}
ul.pop-over-list
if currentUser.isNotCommentOnly
unless currentUser.isWorker
li: a.js-remove-assignee {{_ 'remove-member-from-card'}}
unless currentUser.isWorker
if $eq currentUser._id user._id
with currentUser
li: a.js-edit-profile {{_ 'edit-profile'}}

View file

@ -51,7 +51,8 @@ BlazeComponent.extendComponent({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},

View file

@ -67,7 +67,8 @@ BlazeComponent.extendComponent({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
}).register('checklistDetail');
@ -120,7 +121,8 @@ BlazeComponent.extendComponent({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
@ -228,7 +230,8 @@ Template.checklistItemDetail.helpers({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
});

View file

@ -3,7 +3,8 @@ BlazeComponent.extendComponent({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
}).register('subtaskDetail');
@ -55,7 +56,8 @@ BlazeComponent.extendComponent({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
@ -154,7 +156,8 @@ Template.subtaskItemDetail.helpers({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
});

View file

@ -189,7 +189,8 @@ BlazeComponent.extendComponent({
!this.reachedWipLimit() &&
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},

View file

@ -10,7 +10,7 @@ template(name="listHeader")
a.list-header-left-icon.fa.fa-angle-left.js-unselect-list
h2.list-header-name(
title="{{ moment modifiedAt 'LLL' }}"
class="{{#if currentUser.isBoardMember}}{{#unless currentUser.isCommentOnly}}js-open-inlined-form is-editable{{/unless}}{{/if}}")
class="{{#if currentUser.isBoardMember}}{{#unless currentUser.isCommentOnly}}{{#unless currentUser.isWorker}}js-open-inlined-form is-editable{{/unless}}{{/unless}}{{/if}}")
+viewer
= title
if wipLimit.enabled
@ -65,6 +65,7 @@ template(name="listActionPopup")
i.fa.fa-eye-slash
| {{_ 'watch'}}
unless currentUser.isCommentOnly
unless currentUser.isWorker
ul.pop-over-list
li
a.js-set-color-list
@ -82,6 +83,7 @@ template(name="listActionPopup")
a.js-set-wip-limit
i.fa.fa-ban
| {{#if isWipLimitEnabled }}{{_ 'edit-wip-limit'}}{{else}}{{_ 'setWipLimitPopup-title'}}{{/if}}
unless currentUser.isWorker
hr
ul.pop-over-list
li
@ -114,6 +116,7 @@ template(name="listMorePopup")
input.inline-input(type="text" readonly value="{{ rootUrl }}")
| {{_ 'added'}}
span.date(title=list.createdAt) {{ moment createdAt 'LLL' }}
unless currentUser.isWorker
a.js-delete {{_ 'delete'}}
template(name="listDeletePopup")

View file

@ -9,9 +9,10 @@ BlazeComponent.extendComponent({
canSeeAddCard() {
const list = Template.currentData();
return (
!list.getWipLimit('enabled') ||
(!list.getWipLimit('enabled') ||
list.getWipLimit('soft') ||
!this.reachedWipLimit()
!this.reachedWipLimit()) &&
!Meteor.user().isWorker()
);
},

View file

@ -40,6 +40,7 @@ template(name="membersWidget")
i.fa.fa-users
| {{_ 'members'}}
unless currentUser.isCommentOnly
unless currentUser.isWorker
a.board-header-btn.js-open-board-menu(title="{{_ 'boardMenuPopup-title'}}").right
i.board-header-btn-icon.fa.fa-cog
@ -164,6 +165,7 @@ template(name="outgoingWebhooksPopup")
template(name="boardMenuPopup")
ul.pop-over-list
if isNotWorker
li: a.js-custom-fields {{_ 'custom-fields'}}
li
a.js-open-archives
@ -246,7 +248,7 @@ template(name="labelsWidget")
.board-widget-content
each currentBoard.labels
a.card-label(class="card-label-{{color}}"
class="{{#if currentUser.isNotCommentOnly}}js-label{{/if}}")
class="{{#if currentUser.isNotCommentOnly}}{{#if currentUser.isNotWorker}}js-label{{/if}}{{/if}}")
span.card-label-name
+viewer
= name
@ -275,6 +277,7 @@ template(name="memberPopup")
a.js-change-role
| {{_ 'change-permissions'}}
span.quiet (#{memberType})
unless currentUser.isWorker
li
if $eq currentUser._id userId
a.js-leave-member {{_ 'leave-board'}}
@ -343,6 +346,12 @@ template(name="changePermissionsPopup")
if isCommentOnly
i.fa.fa-check
span.sub-name {{_ 'comment-only-desc'}}
li
a(class="{{#if isLastAdmin}}disabled{{else}}js-set-worker{{/if}}")
| {{_ 'worker'}}
if isWorker
i.fa.fa-check
span.sub-name {{_ 'worker-desc'}}
if isLastAdmin
hr
p.quiet.bottom {{_ 'last-admin-desc'}}

View file

@ -161,10 +161,13 @@ Template.memberPopup.helpers({
const currentBoard = Boards.findOne(Session.get('currentBoard'));
const commentOnly = currentBoard.hasCommentOnly(this.userId);
const noComments = currentBoard.hasNoComments(this.userId);
const worker = currentBoard.hasWorker(this.userId);
if (commentOnly) {
return TAPi18n.__('comment-only').toLowerCase();
} else if (noComments) {
return TAPi18n.__('no-comments').toLowerCase();
} else if (worker) {
return TAPi18n.__('worker').toLowerCase();
} else {
return TAPi18n.__(type).toLowerCase();
}
@ -267,6 +270,14 @@ Template.membersWidget.helpers({
const user = Meteor.user();
return user && user.isInvitedTo(Session.get('currentBoard'));
},
isWorker() {
const user = Meteor.user();
if (user) {
return Meteor.call(Boards.hasWorker(user.memberId));
} else {
return false;
}
},
});
Template.membersWidget.events({
@ -644,7 +655,7 @@ BlazeComponent.extendComponent({
}).register('addMemberPopup');
Template.changePermissionsPopup.events({
'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only'(
'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
event,
) {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
@ -654,11 +665,13 @@ Template.changePermissionsPopup.events({
'js-set-comment-only',
);
const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
const isWorker = $(event.currentTarget).hasClass('js-set-worker');
currentBoard.setMemberPermission(
memberId,
isAdmin,
isNoComments,
isCommentOnly,
isWorker,
);
Popup.back(1);
},
@ -675,7 +688,8 @@ Template.changePermissionsPopup.helpers({
return (
!currentBoard.hasAdmin(this.userId) &&
!currentBoard.hasNoComments(this.userId) &&
!currentBoard.hasCommentOnly(this.userId)
!currentBoard.hasCommentOnly(this.userId) &&
!currentBoard.hasWorker(this.userId)
);
},
@ -695,6 +709,13 @@ Template.changePermissionsPopup.helpers({
);
},
isWorker() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return (
!currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
);
},
isLastAdmin() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return (

View file

@ -2,6 +2,7 @@ template(name="archivesSidebar")
if isArchiveReady.get
+basicTabs(tabs=tabs)
+tabContent(slug="cards")
unless isWorker
p.quiet
a.js-restore-all-cards {{_ 'restore-all'}}
| -
@ -10,6 +11,7 @@ template(name="archivesSidebar")
.minicard-wrapper.js-minicard
+minicard(this)
if currentUser.isBoardMember
unless isWorker
p.quiet
a.js-restore-card {{_ 'restore'}}
| -
@ -20,6 +22,7 @@ template(name="archivesSidebar")
p.no-items-message {{_ 'no-archived-cards'}}
+tabContent(slug="lists")
unless isWorker
p.quiet
a.js-restore-all-lists {{_ 'restore-all'}}
| -
@ -29,6 +32,7 @@ template(name="archivesSidebar")
li.archived-lists-item
= title
if currentUser.isBoardMember
unless isWorker
p.quiet
a.js-restore-list {{_ 'restore'}}
| -
@ -37,6 +41,7 @@ template(name="archivesSidebar")
li.no-items-message {{_ 'no-archived-lists'}}
+tabContent(slug="swimlanes")
unless isWorker
p.quiet
a.js-restore-all-swimlanes {{_ 'restore-all'}}
| -
@ -46,6 +51,7 @@ template(name="archivesSidebar")
li.archived-lists-item
= title
if currentUser.isBoardMember
unless isWorker
p.quiet
a.js-restore-swimlane {{_ 'restore'}}
| -

View file

@ -139,3 +139,12 @@ BlazeComponent.extendComponent({
];
},
}).register('archivesSidebar');
Template.archivesSidebar.helpers({
isWorker() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return (
!currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
);
},
});

View file

@ -43,6 +43,7 @@ template(name="listsGroup")
+addListForm
template(name="addListForm")
unless currentUser.isWorker
.list.list-composer.js-list-composer(class="{{#if isMiniScreen}}mini-list{{/if}}")
.list-header-add
+inlinedForm(autoclose=false)

View file

@ -94,7 +94,8 @@ function initSortable(boardComponent, $listsDom) {
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
}
@ -131,6 +132,15 @@ function initSortable(boardComponent, $listsDom) {
// MultiSelection.isActive() || !userIsMember(),
);
}
$listsDom.sortable(
'option',
'disabled',
// Disable drag-dropping when user is not member
Meteor.user().isWorker(),
// Not disable drag-dropping while in multi-selection mode
// MultiSelection.isActive() || !userIsMember(),
);
});
}
@ -282,7 +292,8 @@ Template.swimlane.helpers({
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
!Meteor.user().isCommentOnly() &&
!Meteor.user().isWorker()
);
},
});

View file

@ -73,6 +73,7 @@ template(name="cardMemberPopup")
p.quiet @{{ user.username }}
ul.pop-over-list
if currentUser.isNotCommentOnly
if currentUser.isNotWorker
li: a.js-remove-member {{_ 'remove-member-from-card'}}
if $eq currentUser._id user._id

View file

@ -39,6 +39,7 @@ template(name="memberMenuPopup")
a.js-go-setting(href="{{pathFor 'setting'}}")
i.fa.fa-lock
| {{_ 'admin-panel'}}
unless currentUser.isWorker
hr
ul.pop-over-list
li
@ -109,6 +110,7 @@ template(name="changeSettingsPopup")
| {{_ 'show-desktop-drag-handles'}}
if showDesktopDragHandles
i.fa.fa-check
unless currentUser.isWorker
li
label.bold
i.fa.fa-sort-numeric-asc
@ -117,5 +119,6 @@ template(name="changeSettingsPopup")
input.js-apply-show-cards-at.left(type="submit" value="{{_ 'apply'}}")
template(name="userDeletePopup")
unless currentUser.isWorker
p {{_ 'delete-user-confirm-popup'}}
button.js-confirm.negate.full(type="submit") {{_ 'delete'}}

View file

@ -185,6 +185,7 @@ Boards.attachSchema(
isActive: true,
isNoComments: false,
isCommentOnly: false,
isWorker: false,
},
];
}
@ -222,6 +223,13 @@ Boards.attachSchema(
type: Boolean,
optional: true,
},
'members.$.isWorker': {
/**
* Is the member only allowed to move card, assign himself to card and comment
*/
type: Boolean,
optional: true,
},
permission: {
/**
* visibility of the board
@ -538,6 +546,7 @@ Boards.helpers({
isActive: true,
isAdmin: false,
isNoComments: true,
isWorker: false,
});
},
@ -547,6 +556,17 @@ Boards.helpers({
isActive: true,
isAdmin: false,
isCommentOnly: true,
isWorker: false,
});
},
hasWorker(memberId) {
return !!_.findWhere(this.members, {
userId: memberId,
isActive: true,
isAdmin: false,
isCommentOnly: false,
isWorker: true,
});
},
@ -849,6 +869,7 @@ Boards.mutations({
isActive: true,
isNoComments: false,
isCommentOnly: false,
isWorker: false,
},
},
};
@ -881,6 +902,7 @@ Boards.mutations({
isAdmin,
isNoComments,
isCommentOnly,
isWorker,
currentUserId = Meteor.userId(),
) {
const memberIndex = this.memberIndex(memberId);
@ -894,6 +916,7 @@ Boards.mutations({
[`members.${memberIndex}.isAdmin`]: isAdmin,
[`members.${memberIndex}.isNoComments`]: isNoComments,
[`members.${memberIndex}.isCommentOnly`]: isCommentOnly,
[`members.${memberIndex}.isWorker`]: isWorker,
},
};
},
@ -1281,6 +1304,7 @@ if (Meteor.isServer) {
* @param {boolean} [isActive] is the board active (default true)
* @param {boolean} [isNoComments] disable comments (default false)
* @param {boolean} [isCommentOnly] only enable comments (default false)
* @param {boolean} [isWorker] only move cards, assign himself to card and comment (default false)
* @param {string} [permission] "private" board <== Set to "public" if you
* want public Wekan board
* @param {string} [color] the color of the board
@ -1300,6 +1324,7 @@ if (Meteor.isServer) {
isActive: req.body.isActive || true,
isNoComments: req.body.isNoComments || false,
isCommentOnly: req.body.isCommentOnly || false,
isWorker: req.body.isWorker || false,
},
],
permission: req.body.permission || 'private',
@ -1403,6 +1428,7 @@ if (Meteor.isServer) {
* @param {boolean} isAdmin admin capability
* @param {boolean} isNoComments NoComments capability
* @param {boolean} isCommentOnly CommentsOnly capability
* @param {boolean} isWorker Worker capability
*/
JsonRoutes.add('POST', '/api/boards/:boardId/members/:memberId', function(
req,
@ -1411,7 +1437,7 @@ if (Meteor.isServer) {
try {
const boardId = req.params.boardId;
const memberId = req.params.memberId;
const { isAdmin, isNoComments, isCommentOnly } = req.body;
const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body;
Authentication.checkBoardAccess(req.userId, boardId);
const board = Boards.findOne({ _id: boardId });
function isTrue(data) {
@ -1426,6 +1452,7 @@ if (Meteor.isServer) {
isTrue(isAdmin),
isTrue(isNoComments),
isTrue(isCommentOnly),
isTrue(isWorker),
req.userId,
);

View file

@ -352,6 +352,16 @@ if (Meteor.isClient) {
return board && board.hasCommentOnly(this._id);
},
isNotWorker() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasMember(this._id) && !board.hasWorker(this._id);
},
isWorker() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasWorker(this._id);
},
isBoardAdmin() {
const board = Boards.findOne(Session.get('currentBoard'));
return board && board.hasAdmin(this._id);