Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cronus/routes/v1/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { authenticator } = require("otplib");
const { sendMail } = require("../../utils/smtpMailer");
const router = express.Router();
const auth = require("../../middleware/auth");
const { getVisibleProfileBadge } = require("../../utils/profileBadges");
const EMAIL_CODE_TTL_MS = 5 * 60 * 1000;
const EMAIL_CODE_MAX_ATTEMPTS = 5;
const BCRYPT_COST = 12;
Expand Down Expand Up @@ -907,16 +908,18 @@ router.get("/github-callback", async (req, res) => {

router.get("/user", auth, async (req, res) => {
try {
const [users] = await db.query("SELECT id, username, slug, avatar, cover, description, created_at, isVerified, telegram_id, github_id, isRole, social_links FROM users WHERE id = ?", [req.user.id]);
const [users] = await db.query("SELECT id, username, slug, avatar, cover, description, created_at, isVerified, telegram_id, github_id, isRole, active_profile_badge, social_links FROM users WHERE id = ?", [req.user.id]);

if(!users.length) {
return res.status(404).json({ message: "User not found" });
}

const userData = {
...users[0],
activeProfileBadge: await getVisibleProfileBadge(db, users[0]),
social_links: users[0].social_links ? JSON.parse(users[0].social_links) : {},
};
delete userData.active_profile_badge;

res.json({ user: userData, success: true });
} catch (error) {
Expand Down
17 changes: 10 additions & 7 deletions cronus/routes/v1/mod-jams.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ const formatJam = (jam) => {
slug: jam.owner_slug,
avatar: jam.owner_avatar,
isVerified: jam.owner_isVerified,
activeProfileBadge: jam.owner_activeProfileBadge,
} : null,
submissions_count: Number(jam.submissions_count) || 0,
votes_count: Number(jam.votes_count) || 0,
Expand All @@ -344,7 +345,7 @@ const formatJam = (jam) => {

const getJamBySlug = async (slug) => {
const [rows] = await db.query(
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified,
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified, u.active_profile_badge AS owner_activeProfileBadge,
(SELECT COUNT(*) FROM mod_jam_submissions mjs WHERE mjs.jam_id = mj.id AND mjs.status = 'submitted') AS submissions_count,
${PARTICIPANTS_COUNT_SELECT} AS participants_count,
(SELECT COALESCE(SUM(COALESCE(mjv.vote_weight, 1)), 0) FROM mod_jam_votes mjv WHERE mjv.jam_id = mj.id) AS votes_count
Expand Down Expand Up @@ -386,7 +387,7 @@ const getParticipantsCount = async (jamId) => {

const getJamJury = async (jamId) => {
const [rows] = await db.query(
`SELECT mjj.id, mjj.user_id, mjj.created_at, u.username, u.slug, u.avatar, u.isVerified
`SELECT mjj.id, mjj.user_id, mjj.created_at, u.username, u.slug, u.avatar, u.isVerified, u.active_profile_badge AS activeProfileBadge
FROM mod_jam_jury mjj
LEFT JOIN users u ON u.id = mjj.user_id
WHERE mjj.jam_id = ?
Expand All @@ -404,6 +405,7 @@ const getJamJury = async (jamId) => {
slug: row.slug,
avatar: row.avatar,
isVerified: row.isVerified,
activeProfileBadge: row.activeProfileBadge,
},
}));
};
Expand Down Expand Up @@ -473,7 +475,7 @@ const getSubmissions = async ({ jamId, userId, resultsOnly = false }) => {
p.slug AS project_slug, p.title AS project_title, p.summary AS project_summary, p.icon_url AS project_icon_url,
p.downloads AS project_downloads, p.followers AS project_followers, p.updated_at AS project_updated_at, p.tags AS project_tags,
p.color AS project_color,
u.username AS submitter_username, u.slug AS submitter_slug, u.avatar AS submitter_avatar, u.isVerified AS submitter_isVerified,
u.username AS submitter_username, u.slug AS submitter_slug, u.avatar AS submitter_avatar, u.isVerified AS submitter_isVerified, u.active_profile_badge AS submitter_activeProfileBadge,
COALESCE(SUM(COALESCE(mjv.vote_weight, 1)), 0) AS votes_count,
(SELECT user_vote.submission_id FROM mod_jam_votes user_vote WHERE user_vote.jam_id = mjs.jam_id AND user_vote.user_id = ? AND COALESCE(user_vote.nomination_id, 0) = 0 LIMIT 1) AS user_voted_submission_id
FROM mod_jam_submissions mjs
Expand Down Expand Up @@ -540,6 +542,7 @@ const getSubmissions = async ({ jamId, userId, resultsOnly = false }) => {
slug: row.submitter_slug,
avatar: row.submitter_avatar,
isVerified: row.submitter_isVerified,
activeProfileBadge: row.submitter_activeProfileBadge,
},
votes_count: Number(row.votes_count) || 0,
nomination_votes: nominationScoresBySubmissionId.get(Number(row.id)) || {},
Expand All @@ -558,7 +561,7 @@ const getUserBySlug = async (slug) => {
}

const [rows] = await db.query(
"SELECT id, username, slug, avatar, isVerified FROM users WHERE slug = ? LIMIT 1",
"SELECT id, username, slug, avatar, isVerified, active_profile_badge AS activeProfileBadge FROM users WHERE slug = ? LIMIT 1",
[normalizedSlug]
);

Expand Down Expand Up @@ -727,7 +730,7 @@ router.get("/moderation", auth, async (req, res) => {

try {
const [rows] = await db.query(
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified, u.active_profile_badge AS owner_activeProfileBadge
FROM mod_jams mj
LEFT JOIN users u ON u.id = mj.owner_user_id
WHERE mj.status = 'pending_review'
Expand All @@ -744,7 +747,7 @@ router.get("/moderation", auth, async (req, res) => {
router.get("/mine", auth, async (req, res) => {
try {
const [rows] = await db.query(
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified,
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified, u.active_profile_badge AS owner_activeProfileBadge,
(SELECT COUNT(*) FROM mod_jam_submissions mjs WHERE mjs.jam_id = mj.id AND mjs.status = 'submitted') AS submissions_count,
${PARTICIPANTS_COUNT_SELECT} AS participants_count,
(SELECT COALESCE(SUM(COALESCE(mjv.vote_weight, 1)), 0) FROM mod_jam_votes mjv WHERE mjv.jam_id = mj.id) AS votes_count
Expand Down Expand Up @@ -790,7 +793,7 @@ router.get("/", async (req, res) => {
}

const [rows] = await db.query(
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified,
`SELECT mj.*, u.username AS owner_username, u.slug AS owner_slug, u.avatar AS owner_avatar, u.isVerified AS owner_isVerified, u.active_profile_badge AS owner_activeProfileBadge,
(SELECT COUNT(*) FROM mod_jam_submissions mjs WHERE mjs.jam_id = mj.id AND mjs.status = 'submitted') AS submissions_count,
${PARTICIPANTS_COUNT_SELECT} AS participants_count,
(SELECT COALESCE(SUM(COALESCE(mjv.vote_weight, 1)), 0) FROM mod_jam_votes mjv WHERE mjv.jam_id = mj.id) AS votes_count
Expand Down
4 changes: 3 additions & 1 deletion cronus/routes/v1/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ router.get("/", auth, async (req, res) => {
u.username,
u.slug,
u.avatar,
u.isVerified
u.isVerified,
u.active_profile_badge AS activeProfileBadge
FROM notification_events ne
INNER JOIN users u ON u.id = ne.actor_user_id
WHERE ne.recipient_user_id = ?
Expand Down Expand Up @@ -237,6 +238,7 @@ router.get("/", auth, async (req, res) => {
slug: actor.slug,
avatar: actor.avatar,
isVerified: Number(actor.isVerified || 0),
activeProfileBadge: actor.activeProfileBadge,
createdAt: Number(actor.created_at),
})),
project: row.object_type === "project" ? (projectMap.get(String(row.object_id)) || null) : null,
Expand Down
10 changes: 7 additions & 3 deletions cronus/routes/v1/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const getMemberView = (row) => ({
slug: row.slug,
avatar: row.avatar,
isVerified: row.isVerified,
activeProfileBadge: row.activeProfileBadge,
role: row.role,
status: row.status,
project_permissions: parsePermissions(row.project_permissions),
Expand Down Expand Up @@ -331,7 +332,8 @@ router.get("/:slug", async (req, res) => {
u.username,
u.slug,
u.avatar,
u.isVerified
u.isVerified,
u.active_profile_badge AS activeProfileBadge
FROM organization_members om
INNER JOIN users u ON u.id = om.user_id
WHERE om.organization_id = ?
Expand Down Expand Up @@ -396,7 +398,8 @@ router.get("/:slug/settings", auth, async (req, res) => {
u.username,
u.slug,
u.avatar,
u.isVerified
u.isVerified,
u.active_profile_badge AS activeProfileBadge
FROM organization_members om
INNER JOIN users u ON u.id = om.user_id
WHERE om.organization_id = ?
Expand All @@ -407,7 +410,7 @@ router.get("/:slug/settings", auth, async (req, res) => {
const [pendingInvites] = await db.query(
`SELECT oi.id, oi.invited_user_id, oi.invited_by_user_id, oi.role,
oi.project_permissions, oi.organization_permissions, oi.created_at,
u.username, u.slug, u.avatar, u.isVerified
u.username, u.slug, u.avatar, u.isVerified, u.active_profile_badge AS activeProfileBadge
FROM organization_invitations oi
INNER JOIN users u ON u.id = oi.invited_user_id
WHERE oi.organization_id = ? AND oi.status = 'pending'
Expand Down Expand Up @@ -439,6 +442,7 @@ router.get("/:slug/settings", auth, async (req, res) => {
slug: invite.slug,
avatar: invite.avatar,
isVerified: invite.isVerified,
activeProfileBadge: invite.activeProfileBadge,
role: invite.role,
project_permissions: parsePermissions(invite.project_permissions),
organization_permissions: parsePermissions(invite.organization_permissions),
Expand Down
28 changes: 19 additions & 9 deletions cronus/routes/v1/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ router.get("/", async (req, res) => {

let query = `
SELECT p.id, p.slug, p.title, p.summary, p.icon_url, p.color, p.downloads, p.followers, p.created_at, p.updated_at, p.project_type, p.tags, p.license_id, p.license_name, p.show_players_last_14d,
ANY_VALUE(u.username) AS username, ANY_VALUE(u.slug) AS user_slug, ANY_VALUE(u.avatar) AS avatar, ANY_VALUE(u.id) AS user_id, ANY_VALUE(u.isVerified) AS isVerified,
ANY_VALUE(u.username) AS username, ANY_VALUE(u.slug) AS user_slug, ANY_VALUE(u.avatar) AS avatar, ANY_VALUE(u.id) AS user_id, ANY_VALUE(u.isVerified) AS isVerified, ANY_VALUE(u.active_profile_badge) AS activeProfileBadge,
ANY_VALUE(o.id) AS organization_id, ANY_VALUE(o.slug) AS organization_slug, ANY_VALUE(o.name) AS organization_name, ANY_VALUE(o.icon_url) AS organization_icon_url, ANY_VALUE(o.summary) AS organization_summary,
ANY_VALUE(pv.game_versions) AS game_versions, ANY_VALUE(pv.loaders) AS loaders,
(SELECT url FROM project_gallery WHERE project_id = p.id AND featured = 1 LIMIT 1) AS featured_image
Expand Down Expand Up @@ -1327,6 +1327,7 @@ router.get("/", async (req, res) => {
slug: project.user_slug,
avatar: project.avatar,
isVerified: project.isVerified,
activeProfileBadge: project.activeProfileBadge,
type: "user",
profile_url: `/user/${project.user_slug}`,
},
Expand Down Expand Up @@ -1422,6 +1423,7 @@ router.get('/user/projects', auth, async (req, res) => {
u.slug AS user_slug,
u.avatar,
u.isVerified,
u.active_profile_badge AS activeProfileBadge,
o.id AS organization_id,
o.slug AS organization_slug,
o.name AS organization_name,
Expand Down Expand Up @@ -1482,6 +1484,7 @@ router.get('/user/projects', auth, async (req, res) => {
slug: project.user_slug,
avatar: project.avatar,
isVerified: project.isVerified,
activeProfileBadge: project.activeProfileBadge,
type: "user",
profile_url: profileUrl,
},
Expand Down Expand Up @@ -2191,7 +2194,7 @@ router.get('/:slug', optionalAuth, async (req, res) => {

const [project] = await db.query(
`SELECT p.*,
u.username, u.slug AS user_slug, u.avatar, u.id AS user_id, u.isVerified AS isVerified,
u.username, u.slug AS user_slug, u.avatar, u.id AS user_id, u.isVerified AS isVerified, u.active_profile_badge AS activeProfileBadge,
(SELECT COUNT(*) FROM project_likes pl WHERE pl.project_id = p.id) AS followers_count,
(SELECT 1 FROM project_likes pl WHERE pl.project_id = p.id AND pl.user_id = ?) AS is_liked
FROM projects p
Expand Down Expand Up @@ -2220,7 +2223,7 @@ router.get('/:slug', optionalAuth, async (req, res) => {
);

const [members] = await db.query(
`SELECT pm.user_id, pm.role, pm.status, u.username, u.slug, u.avatar, u.isVerified
`SELECT pm.user_id, pm.role, pm.status, u.username, u.slug, u.avatar, u.isVerified, u.active_profile_badge AS activeProfileBadge
FROM project_members pm
LEFT JOIN users u ON pm.user_id = u.id
WHERE pm.project_id = ?`,
Expand Down Expand Up @@ -2320,6 +2323,7 @@ router.get('/:slug', optionalAuth, async (req, res) => {
slug: projectData.user_slug,
avatar: projectData.avatar,
isVerified: projectData.isVerified,
activeProfileBadge: projectData.activeProfileBadge,
type: "user",
profile_url: `/user/${projectData.user_slug}`,
},
Expand All @@ -2338,6 +2342,7 @@ router.get('/:slug', optionalAuth, async (req, res) => {
slug: member.slug,
avatar: member.avatar,
isVerified: member.isVerified,
activeProfileBadge: member.activeProfileBadge,
})),
mod_jam_participations: modJamParticipations.map((jam) => ({
...(() => {
Expand Down Expand Up @@ -3056,7 +3061,7 @@ router.get('/:slug/members', async (req, res) => {
}

const [members] = await db.query(`
SELECT pm.user_id, pm.role, pm.status, u.username, u.slug, u.avatar, u.isVerified
SELECT pm.user_id, pm.role, pm.status, u.username, u.slug, u.avatar, u.isVerified, u.active_profile_badge AS activeProfileBadge
FROM project_members pm
LEFT JOIN users u ON pm.user_id = u.id
WHERE pm.project_id = ?
Expand Down Expand Up @@ -3110,7 +3115,7 @@ router.get("/:slug/issues", optionalAuth, async (req, res) => {
const params = [project.id];
let query = `
SELECT i.id, i.title, i.status, i.created_at, i.updated_at, i.author_user_id, i.is_pinned,
u.username, u.slug, u.avatar, u.isVerified, u.isRole,
u.username, u.slug, u.avatar, u.isVerified, u.isRole, u.active_profile_badge AS activeProfileBadge,
(
SELECT COUNT(*) FROM project_issue_comments ic
WHERE ic.issue_id = i.id AND ic.status = 'visible'
Expand Down Expand Up @@ -3177,6 +3182,7 @@ router.get("/:slug/issues", optionalAuth, async (req, res) => {
avatar: issue.avatar,
isVerified: issue.isVerified,
isRole: issue.isRole,
activeProfileBadge: issue.activeProfileBadge,
} : null,
}));

Expand Down Expand Up @@ -3669,7 +3675,7 @@ router.get("/:slug/issues/:issueId", optionalAuth, async (req, res) => {

const [issues] = await db.query(
`SELECT i.id, i.title, i.body, i.status, i.created_at, i.updated_at, i.closed_at, i.closed_by, i.template_id,
i.author_user_id, u.username, u.slug, u.avatar, u.isVerified, u.isRole
i.author_user_id, u.username, u.slug, u.avatar, u.isVerified, u.isRole, u.active_profile_badge AS activeProfileBadge
FROM project_issues i
LEFT JOIN users u ON u.id = i.author_user_id
WHERE i.project_id = ? AND i.id = ? LIMIT 1`,
Expand Down Expand Up @@ -3702,7 +3708,7 @@ router.get("/:slug/issues/:issueId", optionalAuth, async (req, res) => {

const commentsQuery = `
SELECT c.id, c.parent_id, c.content, c.created_at, c.updated_at, c.status, c.user_id,
u.username, u.slug, u.avatar, u.isVerified, u.isRole
u.username, u.slug, u.avatar, u.isVerified, u.isRole, u.active_profile_badge AS activeProfileBadge
FROM project_issue_comments c
LEFT JOIN users u ON c.user_id = u.id
WHERE c.issue_id = ?
Expand All @@ -3728,13 +3734,14 @@ router.get("/:slug/issues/:issueId", optionalAuth, async (req, res) => {
avatar: comment.avatar,
isVerified: comment.isVerified,
isRole: comment.isRole,
activeProfileBadge: comment.activeProfileBadge,
},
};
});

const [eventRows] = await db.query(
`SELECT e.id, e.event_type, e.created_at, e.actor_user_id, e.meta,
u.username, u.slug, u.avatar, u.isVerified, u.isRole
u.username, u.slug, u.avatar, u.isVerified, u.isRole, u.active_profile_badge AS activeProfileBadge
FROM project_issue_events e
LEFT JOIN users u ON u.id = e.actor_user_id
WHERE e.issue_id = ?
Expand All @@ -3754,6 +3761,7 @@ router.get("/:slug/issues/:issueId", optionalAuth, async (req, res) => {
avatar: row.avatar,
isVerified: row.isVerified,
isRole: row.isRole,
activeProfileBadge: row.activeProfileBadge,
} : null,
}));

Expand Down Expand Up @@ -3787,6 +3795,7 @@ router.get("/:slug/issues/:issueId", optionalAuth, async (req, res) => {
avatar: issue.avatar,
isVerified: issue.isVerified,
isRole: issue.isRole,
activeProfileBadge: issue.activeProfileBadge,
} : null,
},
canManage: !!access.canManage,
Expand Down Expand Up @@ -4274,7 +4283,7 @@ router.post("/:slug/issues/:issueId/comments", auth, async (req, res) => {
[issueId, userId, parent_id || null, trimmed, now, now]
);

const [users] = await db.query("SELECT id, username, slug, avatar, isVerified, isRole FROM users WHERE id = ? LIMIT 1", [userId]);
const [users] = await db.query("SELECT id, username, slug, avatar, isVerified, isRole, active_profile_badge AS activeProfileBadge FROM users WHERE id = ? LIMIT 1", [userId]);
const author = users[0];

return res.status(201).json({
Expand All @@ -4291,6 +4300,7 @@ router.post("/:slug/issues/:issueId/comments", auth, async (req, res) => {
avatar: author.avatar,
isVerified: author.isVerified,
isRole: author.isRole,
activeProfileBadge: author.activeProfileBadge,
},
});
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions cronus/routes/v1/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ router.get("/", async (req, res) => {
u.username,
u.slug AS user_slug,
u.avatar AS user_avatar,
u.active_profile_badge AS activeProfileBadge,
o.slug AS organization_slug,
o.name AS organization_name,
o.icon_url AS organization_icon_url,
Expand Down Expand Up @@ -87,6 +88,7 @@ router.get("/", async (req, res) => {
username: project.username,
slug: project.user_slug,
avatar: project.user_avatar || "https://media.modifold.com/static/no-project-icon.svg",
activeProfileBadge: project.activeProfileBadge,
profile_url: `/user/${project.user_slug}`,
},
})),
Expand Down
Loading
Loading