mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Make it obvious which board members are backed by a real account and which are not, both on card avatars and in the right sidebar member list. - userAvatar (js/jade/css): the avatar gets an 'imported-member' class (dashed grey ring + amber '?' corner badge) for un-reconciled board-import placeholders (authenticationMethod:'imported'), and an 'inactive-member' class (greyscale + dim + grey badge) for members deactivated on the board (e.g. a person not in LDAP after reconciliation). A placeholder is usually both; a real active account gets neither. The tooltip explains the state. - boards.js membersForSidebar(): active members first (as before) then the inactive / imported ones appended, and sidebar.jade uses it, so the member list shows EVERYONE and which are active vs not instead of hiding inactive members. - i18n: imported-member-no-account, inactive-member. Thanks to xet7.
498 lines
16 KiB
JavaScript
498 lines
16 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { avatarUpdateCounter } from '/client/components/users/avatarUpdateCounter';
|
|
import Avatars from '/models/avatars';
|
|
import Presences from '/models/presences';
|
|
import { Utils } from '/client/lib/utils';
|
|
|
|
Template.userAvatar.helpers({
|
|
userData() {
|
|
const user = ReactiveCache.getUser(this.userId, {
|
|
fields: {
|
|
profile: 1,
|
|
username: 1,
|
|
authenticationMethod: 1,
|
|
isActive: 1,
|
|
},
|
|
});
|
|
return user;
|
|
},
|
|
|
|
// Distinguish, on the avatar itself, whether a real account backs this member:
|
|
// - imported-member: an inert placeholder created by a board import that has not been
|
|
// reconciled/mapped to a real account yet (dashed ring + "?" badge).
|
|
// - inactive-member: deactivated on this board (e.g. a person not in LDAP after
|
|
// reconciliation) (greyscale + dim).
|
|
// A placeholder is typically both. A real, active account gets neither.
|
|
memberAccountClass() {
|
|
const user = ReactiveCache.getUser(this.userId, {
|
|
fields: { authenticationMethod: 1, isActive: 1 },
|
|
});
|
|
if (!user) return '';
|
|
const classes = [];
|
|
if (user.authenticationMethod === 'imported') classes.push('imported-member');
|
|
let inactive = user.isActive === false;
|
|
if (!inactive) {
|
|
const board = Utils.getCurrentBoard && Utils.getCurrentBoard();
|
|
const m = board && Array.isArray(board.members)
|
|
? board.members.find(x => x.userId === this.userId)
|
|
: null;
|
|
if (m && m.isActive === false) inactive = true;
|
|
}
|
|
if (inactive) classes.push('inactive-member');
|
|
return classes.join(' ');
|
|
},
|
|
|
|
isImportedMember() {
|
|
const user = ReactiveCache.getUser(this.userId, { fields: { authenticationMethod: 1 } });
|
|
return !!(user && user.authenticationMethod === 'imported');
|
|
},
|
|
|
|
isInactiveMember() {
|
|
const user = ReactiveCache.getUser(this.userId, { fields: { authenticationMethod: 1, isActive: 1 } });
|
|
if (!user) return false;
|
|
if (user.authenticationMethod === 'imported') return false; // shown via the imported badge
|
|
if (user.isActive === false) return true;
|
|
const board = Utils.getCurrentBoard && Utils.getCurrentBoard();
|
|
const m = board && Array.isArray(board.members)
|
|
? board.members.find(x => x.userId === this.userId)
|
|
: null;
|
|
return !!(m && m.isActive === false);
|
|
},
|
|
|
|
avatarUrl() {
|
|
const user = ReactiveCache.getUser(this.userId, { fields: { profile: 1 } });
|
|
const base = (user && user.profile && user.profile.avatarUrl) || '';
|
|
if (!base) return '';
|
|
// Append current boardId when available so public viewers can access avatars on public boards
|
|
try {
|
|
const boardId = Utils.getCurrentBoardId && Utils.getCurrentBoardId();
|
|
if (boardId) {
|
|
const sep = base.includes('?') ? '&' : '?';
|
|
return `${base}${sep}boardId=${encodeURIComponent(boardId)}`;
|
|
}
|
|
} catch (_) {}
|
|
return base;
|
|
},
|
|
|
|
memberType() {
|
|
const user = ReactiveCache.getUser(this.userId);
|
|
if (!user) return '';
|
|
|
|
const board = Utils.getCurrentBoard();
|
|
if (!board) return '';
|
|
|
|
// Return role in priority order: Admin, Normal, NormalAssignedOnly, NoComments, CommentOnly, CommentAssignedOnly, Worker, ReadOnly, ReadAssignedOnly
|
|
if (user.isBoardAdmin()) return 'admin';
|
|
if (board.hasReadAssignedOnly(user._id)) return 'read-assigned-only';
|
|
if (board.hasReadOnly(user._id)) return 'read-only';
|
|
if (board.hasWorker(user._id)) return 'worker';
|
|
if (board.hasCommentAssignedOnly(user._id)) return 'comment-assigned-only';
|
|
if (board.hasCommentOnly(user._id)) return 'comment-only';
|
|
if (board.hasNoComments(user._id)) return 'no-comments';
|
|
if (board.hasNormalAssignedOnly(user._id)) return 'normal-assigned-only';
|
|
return 'normal';
|
|
},
|
|
|
|
/*
|
|
presenceStatusClassName() {
|
|
const user = ReactiveCache.getUser(this.userId);
|
|
const userPresence = Presences.findOne({ userId: this.userId });
|
|
if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
|
|
else if (!userPresence) return 'disconnected';
|
|
else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
|
|
return 'active';
|
|
else return 'idle';
|
|
},
|
|
*/
|
|
|
|
});
|
|
|
|
Template.userAvatarInitials.helpers({
|
|
initials() {
|
|
const user = ReactiveCache.getUser(this.userId);
|
|
return user && user.getInitials();
|
|
},
|
|
|
|
viewPortWidth() {
|
|
const user = ReactiveCache.getUser(this.userId);
|
|
return ((user && user.getInitials().length) || 1) * 12;
|
|
},
|
|
});
|
|
|
|
Template.boardOrgRow.onCreated(function () {
|
|
this.error = new ReactiveVar('');
|
|
this.loading = new ReactiveVar(false);
|
|
this.findOrgsOptions = new ReactiveVar({});
|
|
|
|
this.page = new ReactiveVar(1);
|
|
this.autorun(() => {
|
|
const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
|
|
this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
|
|
});
|
|
});
|
|
|
|
Template.boardOrgRow.onRendered(function () {
|
|
this.loading.set(false);
|
|
});
|
|
|
|
Template.boardOrgRow.helpers({
|
|
isLoading() {
|
|
return Template.instance().loading.get();
|
|
},
|
|
orgData() {
|
|
return ReactiveCache.getOrg(this.orgId);
|
|
},
|
|
});
|
|
|
|
Template.boardOrgRow.events({
|
|
'keyup input'(event, tpl) {
|
|
tpl.error.set('');
|
|
},
|
|
'click .js-manage-board-removeOrg': Popup.open('removeBoardOrg'),
|
|
});
|
|
|
|
Template.boardOrgName.helpers({
|
|
orgName() {
|
|
const org = ReactiveCache.getOrg(this.orgId);
|
|
return org && org.orgDisplayName;
|
|
},
|
|
|
|
orgViewPortWidth() {
|
|
const org = ReactiveCache.getOrg(this.orgId);
|
|
return ((org && org.orgDisplayName.length) || 1) * 12;
|
|
},
|
|
});
|
|
|
|
Template.boardTeamRow.onCreated(function () {
|
|
this.error = new ReactiveVar('');
|
|
this.loading = new ReactiveVar(false);
|
|
this.findOrgsOptions = new ReactiveVar({});
|
|
|
|
this.page = new ReactiveVar(1);
|
|
this.autorun(() => {
|
|
const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
|
|
this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
|
|
});
|
|
});
|
|
|
|
Template.boardTeamRow.onRendered(function () {
|
|
this.loading.set(false);
|
|
});
|
|
|
|
Template.boardTeamRow.helpers({
|
|
isLoading() {
|
|
return Template.instance().loading.get();
|
|
},
|
|
teamData() {
|
|
return ReactiveCache.getTeam(this.teamId);
|
|
},
|
|
});
|
|
|
|
Template.boardTeamRow.events({
|
|
'keyup input'(event, tpl) {
|
|
tpl.error.set('');
|
|
},
|
|
'click .js-manage-board-removeTeam': Popup.open('removeBoardTeam'),
|
|
});
|
|
|
|
Template.boardTeamName.helpers({
|
|
teamName() {
|
|
const team = ReactiveCache.getTeam(this.teamId);
|
|
return team && team.teamDisplayName;
|
|
},
|
|
|
|
teamViewPortWidth() {
|
|
const team = ReactiveCache.getTeam(this.teamId);
|
|
return ((team && team.teamDisplayName.length) || 1) * 12;
|
|
},
|
|
});
|
|
|
|
// #5850: row showing a single board email-domain share, with a remove affordance.
|
|
Template.boardDomainRow.helpers({
|
|
domainViewPortWidth() {
|
|
return ((this.domain && this.domain.length) || 1) * 12;
|
|
},
|
|
});
|
|
|
|
Template.boardDomainRow.events({
|
|
// The row's data context is `{ domain }`, which becomes removeBoardDomainPopup's
|
|
// data context, so the popup can read `this.domain` directly.
|
|
'click .js-manage-board-removeDomain': Popup.open('removeBoardDomain'),
|
|
});
|
|
|
|
Template.changeAvatarPopup.onCreated(function () {
|
|
this.error = new ReactiveVar('');
|
|
this.avatarUpdateCounter = new ReactiveVar(0); // Trigger to force helper re-evaluation
|
|
// Whether an admin has blocked avatar uploads (Admin Panel > Attachments >
|
|
// Transfer limits). Default false (avatars enabled); when true the upload
|
|
// option is hidden and the upload is also rejected server-side.
|
|
this.avatarUploadBlocked = new ReactiveVar(false);
|
|
Meteor.call('isAvatarUploadBlocked', (err, blocked) => {
|
|
if (!err) this.avatarUploadBlocked.set(blocked === true);
|
|
});
|
|
Meteor.subscribe('my-avatars');
|
|
});
|
|
|
|
Template.changeAvatarPopup.helpers({
|
|
error() {
|
|
return Template.instance().error;
|
|
},
|
|
avatarUploadBlocked() {
|
|
return Template.instance().avatarUploadBlocked.get();
|
|
},
|
|
uploadedAvatars() {
|
|
Template.instance().avatarUpdateCounter.get(); // Create dependency on update counter
|
|
const ret = ReactiveCache.getAvatars({ userId: Meteor.userId() }, {}, true);
|
|
return ret;
|
|
},
|
|
avatarLink() {
|
|
if (this && typeof this.link === 'function') {
|
|
return this.link();
|
|
}
|
|
return '';
|
|
},
|
|
isSelected() {
|
|
Template.instance().avatarUpdateCounter.get(); // Create dependency on update counter
|
|
const userProfile = ReactiveCache.getCurrentUser().profile;
|
|
const avatarUrl = userProfile && userProfile.avatarUrl;
|
|
const currentAvatarUrl = this.link && typeof this.link === 'function' ? this.link() : '';
|
|
// Normalize URLs by removing query parameters for comparison
|
|
// (they may be added for boardId but shouldn't affect selection comparison)
|
|
const normalizeUrl = (url) => url ? url.split('?')[0] : '';
|
|
return normalizeUrl(avatarUrl) === normalizeUrl(currentAvatarUrl);
|
|
},
|
|
noAvatarUrl() {
|
|
Template.instance().avatarUpdateCounter.get(); // Create dependency on update counter
|
|
const userProfile = ReactiveCache.getCurrentUser().profile;
|
|
const avatarUrl = userProfile && userProfile.avatarUrl;
|
|
return !avatarUrl;
|
|
},
|
|
});
|
|
|
|
function changeAvatarSetAvatar(tpl, avatarUrl) {
|
|
Meteor.call('setAvatarUrl', avatarUrl, (err) => {
|
|
if (err) {
|
|
tpl.error.set(err.reason || 'Error setting avatar');
|
|
} else {
|
|
// Trigger a re-evaluation of helpers to show updated avatar selection
|
|
const counter = tpl.avatarUpdateCounter.get();
|
|
tpl.avatarUpdateCounter.set(counter + 1);
|
|
// Also increment global counter for admin people list updates
|
|
avatarUpdateCounter.set(avatarUpdateCounter.get() + 1);
|
|
// Clear input for next upload
|
|
tpl.$('.js-upload-avatar-input').val('');
|
|
}
|
|
});
|
|
}
|
|
|
|
Template.changeAvatarPopup.events({
|
|
'click .js-upload-avatar'(event, tpl) {
|
|
tpl.$('.js-upload-avatar-input').click();
|
|
},
|
|
async 'change .js-upload-avatar-input'(event, tpl) {
|
|
if (event.currentTarget.files && event.currentTarget.files[0]) {
|
|
const uploader = await Avatars.insertAsync(
|
|
{
|
|
file: event.currentTarget.files[0],
|
|
chunkSize: 'dynamic',
|
|
},
|
|
false,
|
|
);
|
|
uploader.on('error', (error, fileData) => {
|
|
tpl.error.set(error.reason);
|
|
});
|
|
uploader.on('uploaded', (error, fileRef) => {
|
|
if (!error) {
|
|
// Trigger a re-evaluation of helpers to show new uploaded avatar
|
|
const counter = tpl.avatarUpdateCounter.get();
|
|
tpl.avatarUpdateCounter.set(counter + 1);
|
|
// Also increment global counter for admin people list updates
|
|
avatarUpdateCounter.set(avatarUpdateCounter.get() + 1);
|
|
} else {
|
|
tpl.error.set(error.reason);
|
|
}
|
|
});
|
|
uploader.start();
|
|
}
|
|
},
|
|
'click .js-select-avatar'(event, tpl) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
if (this && typeof this.link === 'function') {
|
|
const avatarUrl = this.link();
|
|
changeAvatarSetAvatar(tpl, avatarUrl);
|
|
}
|
|
},
|
|
'click .js-select-initials'(event, tpl) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
changeAvatarSetAvatar(tpl, '');
|
|
},
|
|
'click .js-delete-avatar': Popup.afterConfirm('deleteAvatar', async function() {
|
|
// Inside the each loop, 'this' is the avatar object
|
|
const avatarId = this._id;
|
|
if (avatarId) {
|
|
await Avatars.removeAsync(avatarId);
|
|
}
|
|
Popup.back();
|
|
}),
|
|
});
|
|
|
|
Template.cardMemberPopup.helpers({
|
|
user() {
|
|
return ReactiveCache.getUser(this.userId);
|
|
},
|
|
});
|
|
|
|
Template.cardMemberPopup.events({
|
|
'click .js-remove-member'() {
|
|
ReactiveCache.getCard(this.cardId).unassignMember(this.userId);
|
|
Popup.back();
|
|
},
|
|
'click .js-edit-profile': Popup.open('editProfile'),
|
|
});
|
|
|
|
Template.adminChangeAvatarPopup.onCreated(function () {
|
|
this.error = new ReactiveVar('');
|
|
this.avatarUpdateCounter = new ReactiveVar(0);
|
|
const userId = this.data._id || (this.data.user && this.data.user._id);
|
|
this.targetUserId = userId;
|
|
if (userId) {
|
|
Meteor.subscribe('avatars-for-user', userId);
|
|
}
|
|
});
|
|
|
|
Template.adminChangeAvatarPopup.helpers({
|
|
error() {
|
|
return Template.instance().error;
|
|
},
|
|
userId() {
|
|
const instance = Template.instance();
|
|
return instance.targetUserId || (this._id || (this.user && this.user._id));
|
|
},
|
|
userData() {
|
|
return this.user || this;
|
|
},
|
|
uploadedAvatars() {
|
|
Template.instance().avatarUpdateCounter.get();
|
|
const instance = Template.instance();
|
|
const userId = instance.targetUserId || (this._id || (this.user && this.user._id));
|
|
if (!userId) return [];
|
|
const ret = ReactiveCache.getAvatars({ userId: userId }, {}, true);
|
|
return ret;
|
|
},
|
|
avatarLink() {
|
|
if (this && typeof this.link === 'function') {
|
|
return this.link();
|
|
}
|
|
return '';
|
|
},
|
|
currentEditingUser() {
|
|
Template.instance().avatarUpdateCounter.get();
|
|
const instance = Template.instance();
|
|
const userId = instance.targetUserId;
|
|
if (!userId) return null;
|
|
return ReactiveCache.getUser(userId);
|
|
},
|
|
isSelected() {
|
|
Template.instance().avatarUpdateCounter.get();
|
|
const instance = Template.instance();
|
|
const userId = instance.targetUserId;
|
|
if (!userId) return false;
|
|
const user = ReactiveCache.getUser(userId);
|
|
if (!user) return false;
|
|
const userProfile = user.profile;
|
|
const avatarUrl = userProfile && userProfile.avatarUrl;
|
|
const currentAvatarUrl = this.link && typeof this.link === 'function' ? this.link() : '';
|
|
const normalizeUrl = (url) => url ? url.split('?')[0] : '';
|
|
return normalizeUrl(avatarUrl) === normalizeUrl(currentAvatarUrl);
|
|
},
|
|
noAvatarUrl() {
|
|
Template.instance().avatarUpdateCounter.get();
|
|
const instance = Template.instance();
|
|
const userId = instance.targetUserId;
|
|
if (!userId) return true;
|
|
const user = ReactiveCache.getUser(userId);
|
|
if (!user) return true;
|
|
const userProfile = user.profile;
|
|
const avatarUrl = userProfile && userProfile.avatarUrl;
|
|
return !avatarUrl;
|
|
},
|
|
});
|
|
|
|
function adminChangeAvatarSetAvatar(tpl, avatarUrl) {
|
|
const userId = tpl.targetUserId || (Template.currentData()._id || (Template.currentData().user && Template.currentData().user._id));
|
|
if (!userId) {
|
|
console.error('Cannot set avatar: no userId found');
|
|
return;
|
|
}
|
|
Meteor.call('adminSetAvatarUrl', userId, avatarUrl, (err) => {
|
|
if (err) {
|
|
tpl.error.set(err.reason || 'Error setting avatar');
|
|
} else {
|
|
const counter = tpl.avatarUpdateCounter.get();
|
|
tpl.avatarUpdateCounter.set(counter + 1);
|
|
// Also increment global counter to update admin people list
|
|
avatarUpdateCounter.set(avatarUpdateCounter.get() + 1);
|
|
tpl.$('.js-upload-avatar-input').val('');
|
|
}
|
|
});
|
|
}
|
|
|
|
Template.adminChangeAvatarPopup.events({
|
|
'click .js-upload-avatar'(event, tpl) {
|
|
tpl.$('.js-upload-avatar-input').click();
|
|
},
|
|
async 'change .js-upload-avatar-input'(event, tpl) {
|
|
if (event.currentTarget.files && event.currentTarget.files[0]) {
|
|
const userId = tpl.targetUserId || (this._id || (this.user && this.user._id));
|
|
const uploader = await Avatars.insertAsync(
|
|
{
|
|
file: event.currentTarget.files[0],
|
|
chunkSize: 'dynamic',
|
|
meta: {
|
|
adminUploadForUserId: userId,
|
|
},
|
|
},
|
|
false,
|
|
);
|
|
uploader.on('error', (error, fileData) => {
|
|
tpl.error.set(error.reason);
|
|
});
|
|
uploader.on('uploaded', (error, fileRef) => {
|
|
if (!error) {
|
|
const counter = tpl.avatarUpdateCounter.get();
|
|
tpl.avatarUpdateCounter.set(counter + 1);
|
|
// Also increment global counter to update admin people list
|
|
avatarUpdateCounter.set(avatarUpdateCounter.get() + 1);
|
|
} else {
|
|
tpl.error.set(error.reason);
|
|
}
|
|
});
|
|
uploader.start();
|
|
}
|
|
},
|
|
'click .js-select-avatar'(event, tpl) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
if (this && typeof this.link === 'function') {
|
|
const avatarUrl = this.link();
|
|
adminChangeAvatarSetAvatar(tpl, avatarUrl);
|
|
}
|
|
},
|
|
'click .js-select-initials'(event, tpl) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
adminChangeAvatarSetAvatar(tpl, '');
|
|
},
|
|
'click .js-delete-avatar': Popup.afterConfirm('deleteAvatar', async function() {
|
|
// Inside the each loop, 'this' is the avatar object
|
|
const avatarId = this._id;
|
|
if (avatarId) {
|
|
await Avatars.removeAsync(avatarId);
|
|
}
|
|
Popup.back();
|
|
}),
|
|
});
|