mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
fix PRIV_VIEW_ALL_DOMAIN
This commit is contained in:
1 parent
7fd01715bc
commit
24f61b8b27
2 files changed
+10
-9
No files matched your search
@@ -282,13 +282,16 @@ class DomainJoinHandler extends Handler {
|
|||||||
async prepare({ domainId }, target: string = domainId) {
|
async prepare({ domainId }, target: string = domainId) {
|
||||||
const [ddoc, dudoc] = await Promise.all([
|
const [ddoc, dudoc] = await Promise.all([
|
||||||
domain.get(target),
|
domain.get(target),
|
||||||
domain.getDomainUser(target, this.user),
|
domain.collUser.findOne({ domainId, uid: this.user._id }),
|
||||||
]);
|
]);
|
||||||
if (dudoc.join) throw new DomainJoinAlreadyMemberError(target, this.user._id);
|
const assignedRole = this.user.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN)
|
||||||
|
? 'root'
|
||||||
|
: dudoc?.role;
|
||||||
|
if (dudoc?.join) throw new DomainJoinAlreadyMemberError(target, this.user._id);
|
||||||
const r = await domain.getRoles(ddoc);
|
const r = await domain.getRoles(ddoc);
|
||||||
const roles = r.map((role) => role._id);
|
const roles = r.map((role) => role._id);
|
||||||
this.joinSettings = domain.getJoinSettings(ddoc, roles);
|
this.joinSettings = domain.getJoinSettings(ddoc, roles);
|
||||||
if (dudoc.role !== 'default') delete this.joinSettings;
|
if (assignedRole !== 'default') delete this.joinSettings;
|
||||||
else if (!this.joinSettings) throw new DomainJoinForbiddenError(target);
|
else if (!this.joinSettings) throw new DomainJoinForbiddenError(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,8 +128,8 @@ class DomainModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async countUser(domainId: string, role?: string) {
|
static async countUser(domainId: string, role?: string) {
|
||||||
if (role) return await collUser.countDocuments({ domainId, role });
|
if (role) return await collUser.countDocuments({ domainId, role, join: true });
|
||||||
return await collUser.countDocuments({ domainId });
|
return await collUser.countDocuments({ domainId, join: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
@@ -166,10 +166,8 @@ class DomainModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count) {
|
if (count) {
|
||||||
await Promise.all(roles.map(async (role) => {
|
await Promise.all(roles.filter((i) => i._id !== 'guest').map(async (role) => {
|
||||||
if (['default', 'guest'].includes(role._id)) return role;
|
|
||||||
role.count = await DomainModel.countUser(ddoc._id, role._id);
|
role.count = await DomainModel.countUser(ddoc._id, role._id);
|
||||||
return role;
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return roles;
|
return roles;
|
||||||
@@ -207,7 +205,7 @@ class DomainModel {
|
|||||||
let dudoc = await collUser.findOne({ domainId, uid: udoc._id });
|
let dudoc = await collUser.findOne({ domainId, uid: udoc._id });
|
||||||
dudoc ||= { domainId, uid: udoc._id };
|
dudoc ||= { domainId, uid: udoc._id };
|
||||||
if (!(udoc.priv & PRIV.PRIV_USER_PROFILE)) dudoc.role = 'guest';
|
if (!(udoc.priv & PRIV.PRIV_USER_PROFILE)) dudoc.role = 'guest';
|
||||||
if (!dudoc.join) dudoc.role = 'guest';
|
if (!dudoc.join && !(udoc.priv & PRIV.PRIV_VIEW_ALL_DOMAIN)) dudoc.role = 'guest';
|
||||||
if (udoc.priv & PRIV.PRIV_MANAGE_ALL_DOMAIN) dudoc.role = 'root';
|
if (udoc.priv & PRIV.PRIV_MANAGE_ALL_DOMAIN) dudoc.role = 'root';
|
||||||
dudoc.role ||= 'default';
|
dudoc.role ||= 'default';
|
||||||
const ddoc = await DomainModel.get(domainId);
|
const ddoc = await DomainModel.get(domainId);
|
||||||
|
|||||||
Reference in new issue
Block a user