mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: auto-join system domain
This commit is contained in:
1 parent
e15a310351
commit
b9dbdc39ca
3 files changed
+20
-2
No files matched your search
@@ -276,6 +276,7 @@ DomainUserSetting(
|
|||||||
Setting('setting_storage', 'rpdelta', 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'rpdelta', 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
Setting('setting_storage', 'rank', 0, 'number', 'Rank', null, FLAG_DISABLED | FLAG_HIDDEN),
|
Setting('setting_storage', 'rank', 0, 'number', 'Rank', null, FLAG_DISABLED | FLAG_HIDDEN),
|
||||||
Setting('setting_storage', 'level', 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'level', 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
|
Setting('setting_storage', 'join', 0, 'number', 'join', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
);
|
);
|
||||||
|
|
||||||
const ignoreUA = [
|
const ignoreUA = [
|
||||||
|
|||||||
@@ -336,6 +336,12 @@ class UserModel {
|
|||||||
priv,
|
priv,
|
||||||
avatar: `gravatar:${mail}`,
|
avatar: `gravatar:${mail}`,
|
||||||
});
|
});
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await domain.collUser.updateOne(
|
||||||
|
{ uid, domainId: 'system' },
|
||||||
|
{ $set: { join: true } },
|
||||||
|
{ upsert: true },
|
||||||
|
);
|
||||||
return uid;
|
return uid;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e?.code === 11000) {
|
if (e?.code === 11000) {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ const unsupportedUpgrade = async function _26_27() {
|
|||||||
Please use hydrooj@3 to perform these upgrades before upgrading to v4');
|
Please use hydrooj@3 to perform these upgrades before upgrading to v4');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onPrimary = { readPreference: 'primary' } as const;
|
||||||
|
|
||||||
export const coreScripts: MigrationScript[] = [
|
export const coreScripts: MigrationScript[] = [
|
||||||
// Mark as used
|
// Mark as used
|
||||||
async function init() {
|
async function init() {
|
||||||
@@ -703,11 +705,20 @@ export const coreScripts: MigrationScript[] = [
|
|||||||
},
|
},
|
||||||
// Start Hydro v5
|
// Start Hydro v5
|
||||||
async function _91_92() {
|
async function _91_92() {
|
||||||
await db.collection('domain.user').updateMany({}, { $set: { join: true } });
|
await domain.collUser.updateMany({}, { $set: { join: true } });
|
||||||
const ddocs = await domain.coll.updateMany(
|
await domain.coll.updateMany(
|
||||||
{ _join: { $or: [{ $exists: false }, { $eq: null }] } },
|
{ _join: { $or: [{ $exists: false }, { $eq: null }] } },
|
||||||
{ $set: { _join: { method: domain.JOIN_METHOD_ALL, role: 'default', expire: null }, _migratedJoin: true } },
|
{ $set: { _join: { method: domain.JOIN_METHOD_ALL, role: 'default', expire: null }, _migratedJoin: true } },
|
||||||
);
|
);
|
||||||
|
const domainUser = await domain.coll.find({ domainId: 'system', join: true }, onPrimary)
|
||||||
|
.project({ uid: 1 }).toArray();
|
||||||
|
const otherUsers = await user.coll.find({ _id: { $gt: 1, $nin: domainUser.map((u) => u.uid) } }, onPrimary)
|
||||||
|
.project({ _id: 1 }).toArray();
|
||||||
|
await domain.collUser.updateMany(
|
||||||
|
{ uid: { $in: otherUsers.map((u) => u._id) }, domainId: 'system' },
|
||||||
|
{ $set: { join: true } },
|
||||||
|
{ upsert: true },
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Reference in new issue
Block a user