v0.12.53 Restricted Login type rule changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rosterchirp-backend",
|
||||
"version": "0.12.52",
|
||||
"version": "0.12.53",
|
||||
"description": "RosterChirp backend server",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -192,6 +192,18 @@ router.patch('/:id', authMiddleware, teamManagerMiddleware, async (req, res) =>
|
||||
const sgId = await getOrCreateSupportGroup(req.schema);
|
||||
if (sgId) await exec(req.schema, 'INSERT INTO group_members (group_id,user_id) VALUES ($1,$2) ON CONFLICT DO NOTHING', [sgId, id]);
|
||||
}
|
||||
// Auto-unsuspend minor in players group if both guardian and DOB are now set
|
||||
if (isMinor && guardianId && dob && target.status === 'suspended') {
|
||||
const playersRow = await queryOne(req.schema, "SELECT value FROM settings WHERE key='feature_players_group_id'");
|
||||
const playersGroupId = parseInt(playersRow?.value);
|
||||
if (playersGroupId) {
|
||||
const inPlayers = await queryOne(req.schema, 'SELECT 1 FROM user_group_members WHERE user_id=$1 AND user_group_id=$2', [id, playersGroupId]);
|
||||
if (inPlayers) {
|
||||
await exec(req.schema, "UPDATE users SET status='active',updated_at=NOW() WHERE id=$1", [id]);
|
||||
await addUserToPublicGroups(req.schema, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
const user = await queryOne(req.schema,
|
||||
'SELECT id,name,first_name,last_name,phone,is_minor,date_of_birth,guardian_user_id,guardian_approval_required,email,role,status,must_change_password,last_online,created_at FROM users WHERE id=$1',
|
||||
[id]
|
||||
@@ -713,19 +725,25 @@ router.get('/minor-players', authMiddleware, async (req, res) => {
|
||||
});
|
||||
|
||||
// Claim minor as guardian (Mixed Age — Family Manager direct link, no approval needed)
|
||||
// dateOfBirth is required to activate the minor — without it the guardian is saved but the account stays suspended.
|
||||
router.post('/me/guardian-children/:minorId', authMiddleware, async (req, res) => {
|
||||
const minorId = parseInt(req.params.minorId);
|
||||
const { dateOfBirth } = req.body;
|
||||
try {
|
||||
const minor = await queryOne(req.schema, "SELECT * FROM users WHERE id=$1 AND status!='deleted'", [minorId]);
|
||||
if (!minor) return res.status(404).json({ error: 'User not found' });
|
||||
if (!minor.is_minor) return res.status(400).json({ error: 'User is not a minor' });
|
||||
if (minor.guardian_user_id && minor.guardian_user_id !== req.user.id)
|
||||
return res.status(409).json({ error: 'This minor already has a guardian' });
|
||||
const dob = dateOfBirth || minor.date_of_birth || null;
|
||||
const isMinor = dob ? isMinorFromDOB(dob) : minor.is_minor;
|
||||
const shouldActivate = !!dob;
|
||||
const newStatus = shouldActivate ? 'active' : 'suspended';
|
||||
await exec(req.schema,
|
||||
"UPDATE users SET guardian_user_id=$1,guardian_approval_required=FALSE,status='active',updated_at=NOW() WHERE id=$2",
|
||||
[req.user.id, minorId]
|
||||
'UPDATE users SET guardian_user_id=$1,guardian_approval_required=FALSE,date_of_birth=$2,is_minor=$3,status=$4,updated_at=NOW() WHERE id=$5',
|
||||
[req.user.id, dob, isMinor, newStatus, minorId]
|
||||
);
|
||||
await addUserToPublicGroups(req.schema, minorId);
|
||||
if (shouldActivate) await addUserToPublicGroups(req.schema, minorId);
|
||||
const user = await queryOne(req.schema,
|
||||
'SELECT id,name,first_name,last_name,date_of_birth,avatar,status,guardian_user_id FROM users WHERE id=$1',
|
||||
[minorId]
|
||||
|
||||
Reference in New Issue
Block a user