core: home_domain: only show joined

This commit is contained in:
undefined committed 2025-03-20 17:55:10 +00:00
1 parent 24f61b8b27
commit 2a04921de2
3 files changed
+20 -23

No files matched your search

+18 -21
View File
@@ -468,36 +468,33 @@ class UserChangemailWithCodeHandler extends Handler {
class HomeDomainHandler extends Handler {
@query('all', Types.Boolean)
async get(domainId: string, all: boolean) {
let res: DomainDoc[] = [];
let dudict: Record<string, any> = {};
async get({ }, all: boolean) {
let ddocs: DomainDoc[] = [];
const role: Record<string, string> = {};
if (!all) {
dudict = await domain.getDictUserByDomainId(this.user._id);
const dudict = await domain.getDictUserByDomainId(this.user._id);
const dids = Object.keys(dudict);
res = await domain.getMulti({ _id: { $in: dids } }).toArray();
ddocs = await domain.getMulti({ _id: { $in: dids } }).toArray();
} else {
this.checkPriv(PRIV.PRIV_VIEW_ALL_DOMAIN);
res = await domain.getMulti().toArray();
await Promise.all(res.map(async (ddoc) => {
dudict[ddoc._id] = await user.getById(domainId, this.user._id);
}));
ddocs = await domain.getMulti().toArray();
}
const canManage = {};
const ddocs = [];
for (const ddoc of res) {
// eslint-disable-next-line no-await-in-loop
const udoc = (await user.getById(ddoc._id, this.user._id))!;
const dudoc = dudict[ddoc._id];
if (['default', 'guest'].includes(dudoc.role) && this.domain._id !== ddoc._id) {
delete dudict[ddoc._id];
continue;
if (this.user.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN)) {
for (const ddoc of ddocs) {
canManage[ddoc._id] = true;
role[ddoc._id] = 'root';
}
} else {
for (const ddoc of ddocs) {
// eslint-disable-next-line no-await-in-loop
const udoc = (await user.getById(ddoc._id, this.user._id))!;
canManage[ddoc._id] = udoc.hasPerm(PERM.PERM_EDIT_DOMAIN);
role[ddoc._id] = udoc.role;
}
ddocs.push(ddoc);
canManage[ddoc._id] = udoc.hasPerm(PERM.PERM_EDIT_DOMAIN)
|| udoc.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN);
}
this.response.template = 'home_domain.html';
this.response.body = { ddocs, dudict, canManage };
this.response.body = { ddocs, canManage, role };
}
@param('id', Types.String)
+1 -1
View File
@@ -251,7 +251,7 @@ class DomainModel {
@ArgMethod
static async getDictUserByDomainId(uid: number) {
const dudocs = await collUser.find({ uid }).toArray();
const dudocs = await collUser.find({ uid, join: true }).toArray();
const dudict: Record<string, any> = {};
for (const dudoc of dudocs) dudict[dudoc.domainId] = dudoc;
return dudict;