mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: handle 2FA permission check
This commit is contained in:
1 parent
f68b8d54cf
commit
502ced8f27
4 files changed
+6
-1
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.2.1",
|
"version": "4.2.2",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ export function rebuild() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ApiHandler extends Handler {
|
class ApiHandler extends Handler {
|
||||||
|
noCheckPermView = true;
|
||||||
|
|
||||||
query(q: string, variables: any) {
|
query(q: string, variables: any) {
|
||||||
return graphql({
|
return graphql({
|
||||||
schema,
|
schema,
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ registerValue('Contest', [
|
|||||||
registerResolver(
|
registerResolver(
|
||||||
'Query', 'contest(id: ObjectID!)', 'Contest',
|
'Query', 'contest(id: ObjectID!)', 'Contest',
|
||||||
async (arg, ctx) => {
|
async (arg, ctx) => {
|
||||||
|
ctx.checkPerm(PERM.PERM_VIEW);
|
||||||
arg.id = new ObjectID(arg.id);
|
arg.id = new ObjectID(arg.id);
|
||||||
ctx.tdoc = await contest.get(ctx.args.domainId, new ObjectID(arg.id));
|
ctx.tdoc = await contest.get(ctx.args.domainId, new ObjectID(arg.id));
|
||||||
if (!ctx.tdoc) throw new ContestNotFoundError(ctx.args.domainId, arg.id);
|
if (!ctx.tdoc) throw new ContestNotFoundError(ctx.args.domainId, arg.id);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ registerValue('Problem', [
|
|||||||
registerResolver(
|
registerResolver(
|
||||||
'Query', 'problem(id: Int, pid: String)', 'Problem',
|
'Query', 'problem(id: Int, pid: String)', 'Problem',
|
||||||
async (arg, ctx) => {
|
async (arg, ctx) => {
|
||||||
|
ctx.checkPerm(PERM.PERM_VIEW);
|
||||||
const pdoc = await problem.get(ctx.args.domainId, arg.pid || arg.id);
|
const pdoc = await problem.get(ctx.args.domainId, arg.pid || arg.id);
|
||||||
if (!pdoc) return null;
|
if (!pdoc) return null;
|
||||||
if (pdoc.hidden) ctx.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
if (pdoc.hidden) ctx.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
@@ -83,6 +84,7 @@ registerResolver(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
registerResolver('Query', 'problems(ids: [Int])', '[Problem]', async (arg, ctx) => {
|
registerResolver('Query', 'problems(ids: [Int])', '[Problem]', async (arg, ctx) => {
|
||||||
|
ctx.checkPerm(PERM.PERM_VIEW);
|
||||||
const res = await problem.getList(ctx.args.domainId, arg.ids, ctx.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || ctx.user._id,
|
const res = await problem.getList(ctx.args.domainId, arg.ids, ctx.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || ctx.user._id,
|
||||||
ctx.user.group, undefined, undefined, true);
|
ctx.user.group, undefined, undefined, true);
|
||||||
return Object.keys(res).map((id) => res[+id]);
|
return Object.keys(res).map((id) => res[+id]);
|
||||||
|
|||||||
Reference in new issue
Block a user