Merge branch 'master' into search-debug

This commit is contained in:
John Supplee 2021-12-21 02:42:54 +02:00
commit 6ef612d04e
11 changed files with 323 additions and 124 deletions

View file

@ -1,5 +1,5 @@
template(name="adminReports") template(name="adminReports")
.setting-content .setting-content.admin-reports-content
unless currentUser.isAdmin unless currentUser.isAdmin
| {{_ 'error-notAuthorized'}} | {{_ 'error-notAuthorized'}}
else else
@ -26,6 +26,16 @@ template(name="adminReports")
i.fa.fa-magic i.fa.fa-magic
| {{_ 'rulesReportTitle'}} | {{_ 'rulesReportTitle'}}
li
a.js-report-boards(data-id="report-boards")
i.fa.fa-magic
| {{_ 'boardsReportTitle'}}
li
a.js-report-cards(data-id="report-cards")
i.fa.fa-magic
| {{_ 'cardsReportTitle'}}
.main-body .main-body
if loading.get if loading.get
+spinner +spinner
@ -37,6 +47,10 @@ template(name="adminReports")
+orphanedFilesReport +orphanedFilesReport
else if showRulesReport.get else if showRulesReport.get
+rulesReport +rulesReport
else if showBoardsReport.get
+boardsReport
else if showCardsReport.get
+cardsReport
template(name="brokenCardsReport") template(name="brokenCardsReport")
@ -57,7 +71,7 @@ template(name="rulesReport")
th actionType th actionType
th activityType th activityType
each rule in rows each rule in results
tr tr
td {{ rule.title }} td {{ rule.title }}
td {{ rule.boardTitle }} td {{ rule.boardTitle }}
@ -78,7 +92,7 @@ template(name="filesReport")
th MD5 Sum th MD5 Sum
th ID th ID
each att in attachmentFiles each att in results
tr tr
td {{ att.filename }} td {{ att.filename }}
td.right {{fileSize att.length }} td.right {{fileSize att.length }}
@ -100,7 +114,7 @@ template(name="orphanedFilesReport")
th MD5 Sum th MD5 Sum
th ID th ID
each att in attachmentFiles each att in results
tr tr
td {{ att.filename }} td {{ att.filename }}
td.right {{fileSize att.length }} td.right {{fileSize att.length }}
@ -109,3 +123,50 @@ template(name="orphanedFilesReport")
td {{ att._id.toHexString }} td {{ att._id.toHexString }}
else else
div {{_ 'no-results' }} div {{_ 'no-results' }}
template(name="cardsReport")
h1 {{_ 'cardsReportTitle'}}
if resultsCount
table.table
tr
th Card Title
th Board
th Swimlane
th List
th Members
th Assignees
each card in results
tr
td {{abbreviate card.title }}
td {{abbreviate card.board.title }}
td {{abbreviate card.swimlane.title }}
td {{abbreviate card.list.title }}
td {{userNames card.members }}
td {{userNames card.assignees }}
else
div {{_ 'no-results' }}
template(name="boardsReport")
h1 {{_ 'boardsReportTitle'}}
if resultsCount
table.table
tr
th Title
th Id
th Permission
th Archived?
th Members
th Organizations
th Teams
each board in results
tr
td {{abbreviate board.title }}
td {{abbreviate board._id }}
td {{ board.permission }}
td
= yesOrNo(board.archived)
td {{userNames board.members }}
else
div {{_ 'no-results' }}

View file

@ -1,6 +1,8 @@
import { AttachmentStorage } from '/models/attachments'; import { AttachmentStorage } from '/models/attachments';
import { CardSearchPagedComponent } from '/client/lib/cardSearch'; import { CardSearchPagedComponent } from '/client/lib/cardSearch';
import SessionData from '/models/usersessiondata'; import SessionData from '/models/usersessiondata';
import { QueryParams } from '/config/query-classes';
import { OPERATOR_LIMIT } from '/config/search-const';
BlazeComponent.extendComponent({ BlazeComponent.extendComponent({
subscription: null, subscription: null,
@ -8,10 +10,14 @@ BlazeComponent.extendComponent({
showBrokenCardsReport: new ReactiveVar(false), showBrokenCardsReport: new ReactiveVar(false),
showOrphanedFilesReport: new ReactiveVar(false), showOrphanedFilesReport: new ReactiveVar(false),
showRulesReport: new ReactiveVar(false), showRulesReport: new ReactiveVar(false),
showCardsReport: new ReactiveVar(false),
showBoardsReport: new ReactiveVar(false),
sessionId: null,
onCreated() { onCreated() {
this.error = new ReactiveVar(''); this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false); this.loading = new ReactiveVar(false);
this.sessionId = SessionData.getSessionId();
}, },
events() { events() {
@ -21,6 +27,8 @@ BlazeComponent.extendComponent({
'click a.js-report-files': this.switchMenu, 'click a.js-report-files': this.switchMenu,
'click a.js-report-orphaned-files': this.switchMenu, 'click a.js-report-orphaned-files': this.switchMenu,
'click a.js-report-rules': this.switchMenu, 'click a.js-report-rules': this.switchMenu,
'click a.js-report-cards': this.switchMenu,
'click a.js-report-boards': this.switchMenu,
}, },
]; ];
}, },
@ -32,6 +40,9 @@ BlazeComponent.extendComponent({
this.showFilesReport.set(false); this.showFilesReport.set(false);
this.showBrokenCardsReport.set(false); this.showBrokenCardsReport.set(false);
this.showOrphanedFilesReport.set(false); this.showOrphanedFilesReport.set(false);
this.showRulesReport.set(false)
this.showBoardsReport.set(false);
this.showCardsReport.set(false);
if (this.subscription) { if (this.subscription) {
this.subscription.stop(); this.subscription.stop();
} }
@ -64,68 +75,79 @@ BlazeComponent.extendComponent({
this.showRulesReport.set(true); this.showRulesReport.set(true);
this.loading.set(false); this.loading.set(false);
}); });
} else if ('report-boards' === targetID) {
this.subscription = Meteor.subscribe('boardsReport', () => {
this.showBoardsReport.set(true);
this.loading.set(false);
});
} else if ('report-cards' === targetID) {
const qp = new QueryParams();
qp.addPredicate(OPERATOR_LIMIT, 300);
this.subscription = Meteor.subscribe(
'globalSearch',
this.sessionId,
qp.getParams(),
qp.text,
() => {
this.showCardsReport.set(true);
this.loading.set(false);
},
);
} }
} }
}, },
}).register('adminReports'); }).register('adminReports');
Template.filesReport.helpers({ class AdminReport extends BlazeComponent {
attachmentFiles() { collection;
results() {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('attachments:', AttachmentStorage.find()); // console.log('attachments:', AttachmentStorage.find());
// console.log('attachments.count:', AttachmentStorage.find().count()); // console.log('attachments.count:', AttachmentStorage.find().count());
return AttachmentStorage.find(); return this.collection.find();
}, }
rulesReport() { yesOrNo(value) {
const rules = []; if (value) {
return TAPi18n.__('yes');
Rules.find().forEach(rule => { } else {
rules.push({ return TAPi18n.__('no');
_id: rule._id, }
title: rule.title, }
boardId: rule.boardId,
boardTitle: rule.board().title,
action: rule.action().fetch(),
trigger: rule.trigger().fetch(),
});
});
return rules;
},
resultsCount() { resultsCount() {
return AttachmentStorage.find().count(); return this.collection.find().count();
}, }
fileSize(size) { fileSize(size) {
return Math.round(size / 1024); return Math.round(size / 1024);
}, }
usageCount(key) { usageCount(key) {
return Attachments.find({ 'copies.attachments.key': key }).count(); return Attachments.find({ 'copies.attachments.key': key }).count();
}, }
});
Template.orphanedFilesReport.helpers({ abbreviate(text) {
attachmentFiles() { if (text.length > 30) {
// eslint-disable-next-line no-console return `${text.substr(0, 29)}...`;
// console.log('attachments:', AttachmentStorage.find()); }
// console.log('attachments.count:', AttachmentStorage.find().count()); return text;
return AttachmentStorage.find(); }
}, }
resultsCount() { (class extends AdminReport {
return AttachmentStorage.find().count(); collection = AttachmentStorage;
}, }.register('filesReport'));
fileSize(size) { (class extends AdminReport {
return Math.round(size / 1024); collection = AttachmentStorage;
}, }.register('orphanedFilesReport'));
});
Template.rulesReport.helpers({ (class extends AdminReport {
rows() { collection = Rules;
results() {
const rules = []; const rules = [];
Rules.find().forEach(rule => { Rules.find().forEach(rule => {
@ -139,14 +161,43 @@ Template.rulesReport.helpers({
}); });
}); });
// eslint-disable-next-line no-console
console.log('rows:', rules); console.log('rows:', rules);
return rules; return rules;
}, }
}.register('rulesReport'));
resultsCount() { (class extends AdminReport {
return Rules.find().count(); collection = Boards;
},
}); userNames(members) {
let text = '';
members.forEach(member => {
const user = Users.findOne(member.userId);
text += text ? ', ' : '';
if (user) {
text += user.username;
} else {
text += member.userId
}
});
return text;
}
}.register('boardsReport'));
(class extends AdminReport {
collection = Cards;
userNames(userIds) {
let text = '';
userIds.forEach(userId => {
const user = Users.findOne(userId);
text += text ? ', ' : '';
text += user.username;
});
return text;
}
}.register('cardsReport'));
class BrokenCardsComponent extends CardSearchPagedComponent { class BrokenCardsComponent extends CardSearchPagedComponent {
onCreated() { onCreated() {

View file

@ -0,0 +1,3 @@
.admin-reports-content
height: auto !important

View file

@ -49,6 +49,14 @@ export const TYPE_LINKED_BOARD = 'cardType-linkedBoard';
export const TYPE_LINKED_CARD = 'cardType-linkedCard'; export const TYPE_LINKED_CARD = 'cardType-linkedCard';
export const TYPE_TEMPLATE_BOARD = 'template-board'; export const TYPE_TEMPLATE_BOARD = 'template-board';
export const TYPE_TEMPLATE_CONTAINER = 'template-container'; export const TYPE_TEMPLATE_CONTAINER = 'template-container';
export const TYPE_TEMPLATE_CARD = 'template-card';
export const TYPE_TEMPLATE_LIST = 'template-list';
export const CARD_TYPES = [
TYPE_CARD,
TYPE_LINKED_CARD,
TYPE_LINKED_BOARD,
TYPE_TEMPLATE_CARD
];
export const ALLOWED_WAIT_SPINNERS = [ export const ALLOWED_WAIT_SPINNERS = [
'Bounce', 'Bounce',
'Cube', 'Cube',

View file

@ -1065,6 +1065,8 @@
"orphanedFilesReportTitle": "Orphaned Files Report", "orphanedFilesReportTitle": "Orphaned Files Report",
"reports": "Reports", "reports": "Reports",
"rulesReportTitle": "Rules Report", "rulesReportTitle": "Rules Report",
"boardsReportTitle": "Boards Report",
"cardsReportTitle": "Cards Report",
"copy-swimlane": "Copy Swimlane", "copy-swimlane": "Copy Swimlane",
"copySwimlanePopup-title": "Copy Swimlane", "copySwimlanePopup-title": "Copy Swimlane",
"display-card-creator": "Display Card Creator", "display-card-creator": "Display Card Creator",

View file

@ -5,6 +5,7 @@ import {
TYPE_TEMPLATE_BOARD, TYPE_TEMPLATE_BOARD,
TYPE_TEMPLATE_CONTAINER, TYPE_TEMPLATE_CONTAINER,
} from '/config/const'; } from '/config/const';
import Users from "./users";
const escapeForRegex = require('escape-string-regexp'); const escapeForRegex = require('escape-string-regexp');
Boards = new Mongo.Collection('boards'); Boards = new Mongo.Collection('boards');
@ -1479,7 +1480,17 @@ Boards.userSearch = (
return Boards.find(selector, projection); return Boards.find(selector, projection);
}; };
Boards.userBoards = (userId, archived = false, selector = {}) => { Boards.userBoards = (
userId,
archived = false,
selector = {},
projection = {},
) => {
const user = Users.findOne(userId);
if (!user) {
return [];
}
if (typeof archived === 'boolean') { if (typeof archived === 'boolean') {
selector.archived = archived; selector.archived = archived;
} }
@ -1487,15 +1498,20 @@ Boards.userBoards = (userId, archived = false, selector = {}) => {
selector.type = 'board'; selector.type = 'board';
} }
selector.$or = [{ permission: 'public' }]; selector.$or = [
if (userId) { { permission: 'public' },
selector.$or.push({ members: { $elemMatch: { userId, isActive: true } } }); { members: { $elemMatch: { userId, isActive: true } } },
} { 'orgs.orgId': { $in: user.orgIds() } },
return Boards.find(selector); { 'teams.teamId': { $in : user.teamIds() } },
];
return Boards.find(selector, projection);
}; };
Boards.userBoardIds = (userId, archived = false, selector = {}) => { Boards.userBoardIds = (userId, archived = false, selector = {}) => {
return Boards.userBoards(userId, archived, selector).map(board => { return Boards.userBoards(userId, archived, selector, {
fields: { _id: 1 },
}).map(board => {
return board._id; return board._id;
}); });
}; };

View file

@ -519,6 +519,18 @@ Users.helpers({
} }
return ''; return '';
}, },
teamIds() {
if (this.teams) {
return this.teams.map(team => { return team.teamId });
}
return [];
},
orgIds() {
if (this.orgs) {
return this.orgs.map(org => { return org.orgId });
}
return [];
},
orgsUserBelongs() { orgsUserBelongs() {
if (this.orgs) { if (this.orgs) {
return this.orgs.map(function(org){return org.orgDisplayName}).sort().join(','); return this.orgs.map(function(org){return org.orgDisplayName}).sort().join(',');
@ -544,32 +556,16 @@ Users.helpers({
return ''; return '';
}, },
boards() { boards() {
return Boards.find( return Boards.userBoards(this._id, null, {}, { sort: { sort: 1 } })
{
'members.userId': this._id,
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
);
}, },
starredBoards() { starredBoards() {
const { starredBoards = [] } = this.profile || {}; const { starredBoards = [] } = this.profile || {};
return Boards.find( return Boards.userBoards(
{ this._id,
archived: false, false,
_id: { { _id: { $in: starredBoards } },
$in: starredBoards, { sort: { sort: 1 } }
},
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
); );
}, },
@ -580,18 +576,11 @@ Users.helpers({
invitedBoards() { invitedBoards() {
const { invitedBoards = [] } = this.profile || {}; const { invitedBoards = [] } = this.profile || {};
return Boards.find( return Boards.userBoards(
{ this._id,
archived: false, false,
_id: { { _id: { $in: invitedBoards } },
$in: invitedBoards, { sort: { sort: 1 } }
},
},
{
sort: {
sort: 1 /* boards default sorting */,
},
},
); );
}, },

View file

@ -6,11 +6,11 @@ cd ~/repos/wekan/.build
zip -r wekan-$1.zip bundle zip -r wekan-$1.zip bundle
{ {
scp ~/repos/wekan/releases/maintainer-make-bundle-a.sh a:/home/wekan/repos/maintainer-make-bundle.sh scp ~/repos/wekan/releases/maintainer-make-bundle-a.sh a:/home/wekan/maintainer-make-bundle.sh
scp ~/repos/wekan/releases/maintainer-make-bundle-s.sh s:/home/linux1/maintainer-make-bundle.sh scp ~/repos/wekan/releases/maintainer-make-bundle-s.sh s:/home/linux1/maintainer-make-bundle.sh
scp ~/repos/wekan/releases/maintainer-make-bundle-o.sh o:/home/ubuntu/maintainer-make-bundle.sh scp ~/repos/wekan/releases/maintainer-make-bundle-o.sh o:/home/ubuntu/maintainer-make-bundle.sh
scp wekan-$1.zip x2:/var/snap/wekan/common/releases.wekan.team/ scp wekan-$1.zip x2:/var/snap/wekan/common/releases.wekan.team/
scp wekan-$1.zip a:/home/wekan/repos/ scp wekan-$1.zip a:/home/wekan/
scp wekan-$1.zip s:/home/linux1/ scp wekan-$1.zip s:/home/linux1/
scp wekan-$1.zip o:/home/ubuntu/ scp wekan-$1.zip o:/home/ubuntu/
} | parallel -k } | parallel -k

View file

@ -11,7 +11,7 @@ if [ $# -ne 1 ]
fi fi
# 2) Download release from arm64 build server # 2) Download release from arm64 build server
scp a:/home/wekan/repos/wekan-$1-arm64.zip . scp a:/home/wekan/wekan-$1-arm64.zip .
# 3) Upload arm64 release to download server # 3) Upload arm64 release to download server
scp wekan-$1-arm64.zip x2:/var/snap/wekan/common/releases.wekan.team/raspi3/ scp wekan-$1-arm64.zip x2:/var/snap/wekan/common/releases.wekan.team/raspi3/

View file

@ -2,40 +2,47 @@
// non-archived boards: // non-archived boards:
// 1. that the user is a member of // 1. that the user is a member of
// 2. the user has starred // 2. the user has starred
import Users from "../../models/users";
import Org from "../../models/org";
import Team from "../../models/team";
Meteor.publish('boards', function() { Meteor.publish('boards', function() {
const userId = this.userId; const userId = this.userId;
// Ensure that the user is connected. If it is not, we need to return an empty // Ensure that the user is connected. If it is not, we need to return an empty
// array to tell the client to remove the previously published docs. // array to tell the client to remove the previously published docs.
if (!Match.test(userId, String) || !userId) return []; if (!Match.test(userId, String) || !userId) {
return [];
}
// Defensive programming to verify that starredBoards has the expected // Defensive programming to verify that starredBoards has the expected
// format -- since the field is in the `profile` a user can modify it. // format -- since the field is in the `profile` a user can modify it.
const { starredBoards = [] } = (Users.findOne(userId) || {}).profile || {}; // const { starredBoards = [] } = (Users.findOne(userId) || {}).profile || {};
check(starredBoards, [String]); // check(starredBoards, [String]);
let currUser = Users.findOne(userId); // let currUser = Users.findOne(userId);
let orgIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : ''; // let orgIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
let teamIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : ''; // let teamIdsUserBelongs = currUser!== 'undefined' && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : '';
let orgsIds = []; // let orgsIds = [];
let teamsIds = []; // let teamsIds = [];
if(orgIdsUserBelongs && orgIdsUserBelongs != ''){ // if(orgIdsUserBelongs && orgIdsUserBelongs != ''){
orgsIds = orgIdsUserBelongs.split(','); // orgsIds = orgIdsUserBelongs.split(',');
} // }
if(teamIdsUserBelongs && teamIdsUserBelongs != ''){ // if(teamIdsUserBelongs && teamIdsUserBelongs != ''){
teamsIds = teamIdsUserBelongs.split(','); // teamsIds = teamIdsUserBelongs.split(',');
} // }
return Boards.find( return Boards.find(
{ {
archived: false, archived: false,
$or: [ _id: { $in: Boards.userBoardIds(userId, false) },
{ // $or: [
// _id: { $in: starredBoards }, // Commented out, to get a list of all public boards // {
permission: 'public', // // _id: { $in: starredBoards }, // Commented out, to get a list of all public boards
}, // permission: 'public',
{ members: { $elemMatch: { userId, isActive: true } } }, // },
{'orgs.orgId': {$in : orgsIds}}, // { members: { $elemMatch: { userId, isActive: true } } },
{'teams.teamId': {$in : teamsIds}}, // {'orgs.orgId': {$in : orgsIds}},
], // {'teams.teamId': {$in : teamsIds}},
// ],
}, },
{ {
fields: { fields: {
@ -58,19 +65,79 @@ Meteor.publish('boards', function() {
); );
}); });
Meteor.publish('boardsReport', function() {
const userId = this.userId;
// Ensure that the user is connected. If it is not, we need to return an empty
// array to tell the client to remove the previously published docs.
if (!Match.test(userId, String) || !userId) return [];
const boards = Boards.find(
{
_id: { $in: Boards.userBoardIds(userId, null) },
},
{
fields: {
_id: 1,
boardId: 1,
archived: 1,
slug: 1,
title: 1,
description: 1,
color: 1,
members: 1,
orgs: 1,
teams: 1,
permission: 1,
type: 1,
sort: 1,
},
sort: { sort: 1 /* boards default sorting */ },
},
);
const userIds = [];
const orgIds = [];
const teamIds = [];
boards.forEach(board => {
if (board.members) {
board.members.forEach(member => {
userIds.push(member.userId);
});
}
if (board.orgs) {
board.orgs.forEach(org => {
orgIds.push(org.orgId);
});
}
if (board.teams) {
board.teams.forEach(team => {
teamIds.push(team.teamId);
});
}
})
return [
boards,
Users.find({ _id: { $in: userIds } }, { fields: Users.safeFields }),
Team.find({ _id: { $in: teamIds } }),
Org.find({ _id: { $in: orgIds } }),
]
});
Meteor.publish('archivedBoards', function() { Meteor.publish('archivedBoards', function() {
const userId = this.userId; const userId = this.userId;
if (!Match.test(userId, String)) return []; if (!Match.test(userId, String)) return [];
return Boards.find( return Boards.find(
{ {
archived: true, _id: { $in: Boards.userBoardIds(userId, true)},
members: { // archived: true,
$elemMatch: { // members: {
userId, // $elemMatch: {
isAdmin: true, // userId,
}, // isAdmin: true,
}, // },
// },
}, },
{ {
fields: { fields: {

View file

@ -48,6 +48,7 @@ import {
PREDICATE_SYSTEM, PREDICATE_SYSTEM,
} from '/config/search-const'; } from '/config/search-const';
import { QueryErrors, QueryParams, Query } from '/config/query-classes'; import { QueryErrors, QueryParams, Query } from '/config/query-classes';
import { CARD_TYPES } from '../../config/const';
const escapeForRegex = require('escape-string-regexp'); const escapeForRegex = require('escape-string-regexp');
@ -587,6 +588,7 @@ Meteor.publish('brokenCards', function(sessionId) {
{ boardId: { $in: [null, ''] } }, { boardId: { $in: [null, ''] } },
{ swimlaneId: { $in: [null, ''] } }, { swimlaneId: { $in: [null, ''] } },
{ listId: { $in: [null, ''] } }, { listId: { $in: [null, ''] } },
{ type: { $nin: CARD_TYPES } },
]; ];
// console.log('brokenCards selector:', query.selector); // console.log('brokenCards selector:', query.selector);