diff --git a/api/doc/api_data.js b/api/doc/api_data.js index 65178695..3185b758 100644 --- a/api/doc/api_data.js +++ b/api/doc/api_data.js @@ -3011,6 +3011,27 @@ define({ "api": [ "field": ":job", "description": "
Job ID
" } + ], + "Query": [ + { + "group": "Query", + "type": "Boolean", + "optional": true, + "field": "dl", + "description": "Optional param to set content-disposition - forcing the browser to download
" + }, + { + "group": "Query", + "type": "String", + "allowedValues": [ + "\"json\"", + "\"csv\"" + ], + "optional": true, + "field": "format", + "defaultValue": "json", + "description": "" + } ] } }, @@ -4660,6 +4681,7 @@ define({ "api": [ "type": "String", "allowedValues": [ "\"close\"", + "\"fabric\"", "\"scale\"", "\"level\"", "\"collect\"", diff --git a/api/doc/api_data.json b/api/doc/api_data.json index fd06d295..cee677f5 100644 --- a/api/doc/api_data.json +++ b/api/doc/api_data.json @@ -3011,6 +3011,27 @@ "field": ":job", "description": "Job ID
" } + ], + "Query": [ + { + "group": "Query", + "type": "Boolean", + "optional": true, + "field": "dl", + "description": "Optional param to set content-disposition - forcing the browser to download
" + }, + { + "group": "Query", + "type": "String", + "allowedValues": [ + "\"json\"", + "\"csv\"" + ], + "optional": true, + "field": "format", + "defaultValue": "json", + "description": "" + } ] } }, @@ -4660,6 +4681,7 @@ "type": "String", "allowedValues": [ "\"close\"", + "\"fabric\"", "\"scale\"", "\"level\"", "\"collect\"", diff --git a/api/doc/api_project.js b/api/doc/api_project.js index ef6fd3f1..08d42346 100644 --- a/api/doc/api_project.js +++ b/api/doc/api_project.js @@ -12,7 +12,7 @@ define({ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2021-09-30T01:40:14.063Z", + "time": "2021-10-01T16:52:23.494Z", "url": "https://apidocjs.com", "version": "0.29.0" } diff --git a/api/doc/api_project.json b/api/doc/api_project.json index 177a2eb3..52af4041 100644 --- a/api/doc/api_project.json +++ b/api/doc/api_project.json @@ -12,7 +12,7 @@ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2021-09-30T01:40:14.063Z", + "time": "2021-10-01T16:52:23.494Z", "url": "https://apidocjs.com", "version": "0.29.0" } diff --git a/api/index.js b/api/index.js index b71afbb3..acd30d46 100755 --- a/api/index.js +++ b/api/index.js @@ -286,17 +286,20 @@ async function server(args, config, cb) { res: 'res.User.json' }, async (req, res) => { try { - const usr = await user.register(req.body); + if (req.body.password) { + await user.register(req.body); + } - const forgot = await user.forgot(usr.username, 'verify'); + const forgot = await user.forgot(req.body.username, 'verify'); if (args.email) await email.verify({ - username: usr.username, - email: usr.email, + username: forgot.username, + email: forgot.email, token: forgot.token }); - res.json(usr); + delete forgot.token; + res.json(forgot); } catch (err) { return Err.respond(err, res); } diff --git a/api/lib/batch.js b/api/lib/batch.js index 58804662..3f00cba9 100644 --- a/api/lib/batch.js +++ b/api/lib/batch.js @@ -138,6 +138,16 @@ async function trigger(event) { environment: [] } }; + } else if (event.type === 'fabric') { + params = { + jobDefinition: jobDefinition, + jobQueue: mega_queue, + jobName: 'OA_Fabric', + containerOverrides: { + command: ['./fabric.js'], + environment: [] + } + }; } else if (event.type === 'sources') { params = { jobDefinition: jobDefinition, diff --git a/api/lib/schedule.js b/api/lib/schedule.js index 4ba473cf..809cc7b6 100644 --- a/api/lib/schedule.js +++ b/api/lib/schedule.js @@ -11,8 +11,8 @@ class Schedule { static async event(pool, event) { if (event.type === 'collect') { await Schedule.collect(); - } else if (event.type === 'sources') { - await Schedule.sources(pool); + } else if (['fabric', 'collect', 'sources'].includes(event.type)) { + await Schedule.batch(event.type, pool); } else if (event.type === 'close') { await Schedule.close(pool); } else if (event.type === 'level') { @@ -30,13 +30,19 @@ class Schedule { } } - static async collect() { + /** + * Generic function for triggering a batch job + * @param {String} type Type of batch job to trigger + */ + static async batch(type, pool) { + if (type === 'sources') await JobError.clear(pool); + try { return await batch.trigger({ - type: 'collect' + type: type }); } catch (err) { - throw new Err(500, err, 'failed to submit collect job to batch'); + throw new Err(500, err, 'Failed to submit job to batch'); } } @@ -50,18 +56,6 @@ class Schedule { } } - static async sources(pool) { - await JobError.clear(pool); - - try { - return await batch.trigger({ - type: 'sources' - }); - } catch (err) { - throw new Err(500, err, 'failed to submit sources job to batch'); - } - } - static async close(pool) { // TODO Close old run/jobs diff --git a/api/lib/user.js b/api/lib/user.js index 7fe7671e..adfb26fb 100644 --- a/api/lib/user.js +++ b/api/lib/user.js @@ -187,7 +187,11 @@ class User { SELECT id, username, - email + email, + validated, + flags, + level, + access FROM users WHERE @@ -200,7 +204,10 @@ class User { if (pgres.rows.length !== 1) return; const u = pgres.rows[0]; - u.id = parseInt(u.id); + + if (action === 'verify' && u.validated) { + throw new Err(400, null, 'User is already verified'); + } try { await this.pool.query(sql` @@ -229,9 +236,12 @@ class User { `); return { - uid: u.id, + id: u.id, username: u.username, email: u.email, + flags: u.flags, + level: u.level, + access: u.access, token: buffer.toString('hex') }; } catch (err) { diff --git a/api/schema/req.body.CreateUser.json b/api/schema/req.body.CreateUser.json index 267a76cf..0616d313 100644 --- a/api/schema/req.body.CreateUser.json +++ b/api/schema/req.body.CreateUser.json @@ -1,23 +1,35 @@ { - "type": "object", - "required": [ - "username", - "password", - "email" - ], - "additionalProperties": false, - "properties": { - "username": { - "type": "string", - "description": "username" - }, - "password": { - "type": "string", - "description": "password" - }, - "email": { - "type": "string", - "description": "email" + "oneOf": [{ + "type": "object", + "required": [ + "username", + "password", + "email" + ], + "additionalProperties": false, + "properties": { + "username": { + "type": "string", + "description": "username" + }, + "password": { + "type": "string", + "description": "password" + }, + "email": { + "type": "string", + "description": "email" + } } - } + },{ + "type": "object", + "required": [ "username" ], + "additionalProperties": false, + "properties": { + "username": { + "type": "string", + "description": "username" + } + } + }] } diff --git a/api/schema/req.body.Schedule.json b/api/schema/req.body.Schedule.json index 6a41d73d..230dbc84 100644 --- a/api/schema/req.body.Schedule.json +++ b/api/schema/req.body.Schedule.json @@ -9,6 +9,7 @@ "type": "string", "enum": [ "close", + "fabric", "scale", "level", "collect", diff --git a/api/web/src/components/Register.vue b/api/web/src/components/Register.vue index 236a9b6b..d50d100e 100644 --- a/api/web/src/components/Register.vue +++ b/api/web/src/components/Register.vue @@ -1,8 +1,8 @@Please check your email for a verification link!