MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / postCopy

Method postCopy

packages/hydrooj/src/handler/problem.ts:202–234  ·  view source on GitHub ↗
(domainId: string, pids: number[], target: string, hidden?: boolean, redirect = false)

Source from the content-addressed store, hash-verified

200 @param('hidden', Types.Boolean)
201 @param('redirect', Types.Boolean)
202 async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean, redirect = false) {
203 let t = `,${this.domain.share || ''},`;
204 if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(this.domain._id, target);
205 const ddoc = await domain.get(target);
206 if (!ddoc) throw new NotFoundError(target);
207 const dudoc = await user.getById(target, this.user._id);
208 if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
209 if (!pids.length) throw new ValidationError('pids');
210 // Check if user can access all those problems
211 const pdict = await problem.getList(
212 domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id,
213 true, ['domainId', 'docId', 'reference'], true,
214 );
215 const ids = [];
216 for (const pid of pids) {
217 let pdoc = pdict[pid];
218 if (pdoc.reference) {
219 // eslint-disable-next-line no-await-in-loop
220 const [sourcePdoc, sourceDdoc] = await Promise.all([
221 problem.get(pdoc.reference.domainId, pdoc.reference.pid),
222 domain.get(pdoc.reference.domainId),
223 ]);
224 if (!sourcePdoc) throw new ProblemNotFoundError(pdoc.reference.domainId, pdoc.reference.pid);
225 else pdoc = sourcePdoc;
226 t = `,${sourceDdoc.share || ''},`;
227 if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(sourceDdoc._id, target);
228 }
229 // eslint-disable-next-line no-await-in-loop
230 ids.push(await problem.copy(pdoc.domainId, pdoc.docId, target, undefined, hidden));
231 }
232 if (redirect) this.response.redirect = this.url('problem_detail', { domainId: target, pid: ids[0] });
233 else this.response.body = ids;
234 }
235
236 @param('pids', Types.NumericArray)
237 async postDelete(domainId: string, pids: number[]) {

Callers

nothing calls this directly

Calls 8

getByIdMethod · 0.80
hasPermMethod · 0.80
urlMethod · 0.80
getMethod · 0.45
getListMethod · 0.45
allMethod · 0.45
pushMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected