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 { class HomeDomainHandler extends Handler {
@query('all', Types.Boolean) @query('all', Types.Boolean)
async get(domainId: string, all: boolean) { async get({ }, all: boolean) {
let res: DomainDoc[] = []; let ddocs: DomainDoc[] = [];
let dudict: Record<string, any> = {}; const role: Record<string, string> = {};
if (!all) { if (!all) {
dudict = await domain.getDictUserByDomainId(this.user._id); const dudict = await domain.getDictUserByDomainId(this.user._id);
const dids = Object.keys(dudict); const dids = Object.keys(dudict);
res = await domain.getMulti({ _id: { $in: dids } }).toArray(); ddocs = await domain.getMulti({ _id: { $in: dids } }).toArray();
} else { } else {
this.checkPriv(PRIV.PRIV_VIEW_ALL_DOMAIN); this.checkPriv(PRIV.PRIV_VIEW_ALL_DOMAIN);
res = await domain.getMulti().toArray(); ddocs = await domain.getMulti().toArray();
await Promise.all(res.map(async (ddoc) => {
dudict[ddoc._id] = await user.getById(domainId, this.user._id);
}));
} }
const canManage = {}; const canManage = {};
const ddocs = []; if (this.user.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN)) {
for (const ddoc of res) { for (const ddoc of ddocs) {
// eslint-disable-next-line no-await-in-loop canManage[ddoc._id] = true;
const udoc = (await user.getById(ddoc._id, this.user._id))!; role[ddoc._id] = 'root';
const dudoc = dudict[ddoc._id]; }
if (['default', 'guest'].includes(dudoc.role) && this.domain._id !== ddoc._id) { } else {
delete dudict[ddoc._id]; for (const ddoc of ddocs) {
continue; // 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.template = 'home_domain.html';
this.response.body = { ddocs, dudict, canManage }; this.response.body = { ddocs, canManage, role };
} }
@param('id', Types.String) @param('id', Types.String)
+1 -1
View File
@@ -251,7 +251,7 @@ class DomainModel {
@ArgMethod @ArgMethod
static async getDictUserByDomainId(uid: number) { 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> = {}; const dudict: Record<string, any> = {};
for (const dudoc of dudocs) dudict[dudoc.domainId] = dudoc; for (const dudoc of dudocs) dudict[dudoc.domainId] = dudoc;
return dudict; return dudict;
@@ -37,7 +37,7 @@
{{ ddoc['name'] }} ({{ ddoc['_id'] }}) {{ ddoc['name'] }} ({{ ddoc['_id'] }})
</td> </td>
<td class="col--role"> <td class="col--role">
{{ dudict[ddoc._id].role|default('default') }} {{ role[ddoc._id]|default('default') }}
</td> </td>
<td class="col--action"> <td class="col--action">
<a class="typo-a" href="{{ url('homepage', domainId=ddoc['_id']) }}">{{ _('Visit') }}</a> <a class="typo-a" href="{{ url('homepage', domainId=ddoc['_id']) }}">{{ _('Visit') }}</a>