Change the measure model: less pre-determined, more configurable.
This commit is contained in:
parent
b629ec1a14
commit
4965d162ad
@ -1,4 +1,4 @@
|
|||||||
import cliutils, docopt, logging, jester, json, os, strutils, tables
|
import cliutils, docopt, logging, jester, json, os, sequtils, strutils, tables
|
||||||
|
|
||||||
import personal_measure_apipkg/api
|
import personal_measure_apipkg/api
|
||||||
import personal_measure_apipkg/configuration
|
import personal_measure_apipkg/configuration
|
||||||
@ -64,6 +64,7 @@ Usage:
|
|||||||
personal_measure_api test [options]
|
personal_measure_api test [options]
|
||||||
personal_measure_api serve [options]
|
personal_measure_api serve [options]
|
||||||
personal_measure_api hashpwd <password> [options]
|
personal_measure_api hashpwd <password> [options]
|
||||||
|
personal_measure_api create-admin <email> <password>
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
@ -77,6 +78,22 @@ Options:
|
|||||||
let args = docopt(doc, version = PM_API_VERSION)
|
let args = docopt(doc, version = PM_API_VERSION)
|
||||||
let ctx = initContext(args)
|
let ctx = initContext(args)
|
||||||
|
|
||||||
|
if args["create-admin"]:
|
||||||
|
let allUsers = ctx.db.getAllUsers();
|
||||||
|
if allUsers.anyIt(it.isAdmin):
|
||||||
|
raise newException(Exception, "admin user already exists, refusing to create a new admin")
|
||||||
|
|
||||||
|
let pwdAndSalt = hashPwd($args["<password>"], ctx.cfg.pwdCost)
|
||||||
|
|
||||||
|
let adminUser = User(
|
||||||
|
displayName: "Admin",
|
||||||
|
email: $args["<email>"],
|
||||||
|
hashedPwd: pwdAndSalt.pwd,
|
||||||
|
salt: pwdAndSalt.salt,
|
||||||
|
isAdmin: true)
|
||||||
|
|
||||||
|
echo ctx.db.createUser(adminUser)
|
||||||
|
|
||||||
if args["hashpwd"]:
|
if args["hashpwd"]:
|
||||||
if args["--salt"]:
|
if args["--salt"]:
|
||||||
echo hashWithSalt($args["<password>"], $args["--salt"])
|
echo hashWithSalt($args["<password>"], $args["--salt"])
|
||||||
|
@ -251,6 +251,25 @@ proc start*(ctx: PMApiContext): void =
|
|||||||
|
|
||||||
resp(Http200, $(%session.user), JSON)
|
resp(Http200, $(%session.user), JSON)
|
||||||
|
|
||||||
|
put "/user":
|
||||||
|
checkAuth()
|
||||||
|
|
||||||
|
try:
|
||||||
|
let jsonBody = parseJson(request.body)
|
||||||
|
var updatedUser = session.user
|
||||||
|
|
||||||
|
# if jsonBody.hasKey("email") # TODO: add verification?
|
||||||
|
if jsonBody.hasKey("displayName"):
|
||||||
|
updatedUser.displayName = jsonBody["displayName"].getStr()
|
||||||
|
|
||||||
|
jsonResp(Http200, $(%ctx.db.updateUser(updatedUser)))
|
||||||
|
|
||||||
|
except JsonParsingError: jsonResp(Http400, getCurrentExceptionMsg())
|
||||||
|
except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg())
|
||||||
|
except:
|
||||||
|
error "Could not update user information:\n\t" & getCurrentExceptionMsg()
|
||||||
|
jsonResp(Http500)
|
||||||
|
|
||||||
get "/users":
|
get "/users":
|
||||||
checkAuth(true)
|
checkAuth(true)
|
||||||
|
|
||||||
@ -381,19 +400,7 @@ proc start*(ctx: PMApiContext): void =
|
|||||||
slug: slug,
|
slug: slug,
|
||||||
name: name,
|
name: name,
|
||||||
description: jsonBody.getIfExists("description").getStr(""),
|
description: jsonBody.getIfExists("description").getStr(""),
|
||||||
domainSource:
|
config: jsonBody.getOrFail("config"))
|
||||||
if jsonBody.hasKey("domainSource"): some(jsonBody["domainSource"].getStr)
|
|
||||||
else: none[string](),
|
|
||||||
domainUnits: jsonBody.getIfExists("domainUnits").getStr(""),
|
|
||||||
rangeSource:
|
|
||||||
if jsonBody.hasKey("rangeSource"): some(jsonBody["rangeSource"].getStr)
|
|
||||||
else: none[string](),
|
|
||||||
rangeUnits: jsonBody.getIfExists("rangeUnits").getStr(""),
|
|
||||||
analysis: @[])
|
|
||||||
|
|
||||||
if jsonBody.hasKey("analysis"):
|
|
||||||
for a in jsonBody["analysis"].getElems:
|
|
||||||
newMeasure.analysis.add(a.getStr)
|
|
||||||
|
|
||||||
resp($(%ctx.db.createMeasure(newMeasure)), JSON)
|
resp($(%ctx.db.createMeasure(newMeasure)), JSON)
|
||||||
|
|
||||||
|
@ -23,11 +23,7 @@ type
|
|||||||
slug*: string
|
slug*: string
|
||||||
name*: string
|
name*: string
|
||||||
description*: string
|
description*: string
|
||||||
domainSource*: Option[string]
|
config*: JsonNode
|
||||||
domainUnits*: string
|
|
||||||
rangeSource*: Option[string]
|
|
||||||
rangeUnits*: string
|
|
||||||
analysis*: seq[string]
|
|
||||||
|
|
||||||
Measurement* = object
|
Measurement* = object
|
||||||
id*: UUID
|
id*: UUID
|
||||||
@ -81,18 +77,3 @@ proc `%`*(tok: ApiToken): JsonNode =
|
|||||||
|
|
||||||
if tok.expires.isSome:
|
if tok.expires.isSome:
|
||||||
result["expires"] = %(tok.expires.get.formatIso8601)
|
result["expires"] = %(tok.expires.get.formatIso8601)
|
||||||
|
|
||||||
proc `%`*(m: Measure): JsonNode =
|
|
||||||
result = %*{
|
|
||||||
"id": $m.id,
|
|
||||||
"userId": $m.userId,
|
|
||||||
"slug": m.slug,
|
|
||||||
"name": m.name,
|
|
||||||
"description": m.description,
|
|
||||||
"domainUnits": m.domainUnits,
|
|
||||||
"rangeUnits": m.rangeUnits,
|
|
||||||
"analysis": m.analysis
|
|
||||||
}
|
|
||||||
|
|
||||||
if m.domainSource.isSome: result["domainSource"] = %(m.domainSource.get)
|
|
||||||
if m.rangeSource.isSome: result["rangeSource"] = %(m.rangeSource.get)
|
|
||||||
|
@ -26,11 +26,6 @@ create table "measures" (
|
|||||||
name varchar not null,
|
name varchar not null,
|
||||||
description varchar not null default '',
|
description varchar not null default '',
|
||||||
config jsonb not null default '{}'::json,
|
config jsonb not null default '{}'::json,
|
||||||
domain_source varchar default null,
|
|
||||||
domain_units varchar not null default '',
|
|
||||||
range_source varchar default null,
|
|
||||||
range_units varchar not null default '',
|
|
||||||
analysis varchar[] not null default '{}',
|
|
||||||
unique(user_id, slug)
|
unique(user_id, slug)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
1
api/temp/auth-token-jdb.txt
Normal file
1
api/temp/auth-token-jdb.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Imp3dCJ9.eyJleHAiOjE1NTIzMjYxODMsInN1YiI6IjA3NWJjYzhmLWE4N2QtNDRjZS04MDk5LWQ3ZGExZjYxYTc1YSIsImlhdCI6MTU1MjIzOTc4M30.RjE0MjYzMkFDOTc4RjZFNTYyMDVBMTY5MjExNkJGQ0QzNkQ1QjZFNzVCODBDMThENTc1M0Y0MjhDMkNFMjE3RA
|
1
api/temp/credential
Symbolic link
1
api/temp/credential
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
auth-token-jdb.txt
|
1
api/temp/pm-api
Symbolic link
1
api/temp/pm-api
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../src/util/bash/client.sh
|
6
web/src/models.d.ts
vendored
6
web/src/models.d.ts
vendored
@ -18,11 +18,7 @@ export interface Measure {
|
|||||||
slug: string;
|
slug: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
domainSource?: string;
|
config: object;
|
||||||
domainUnites: string;
|
|
||||||
rangeSource?: string;
|
|
||||||
rangeUnits: string;
|
|
||||||
analysis: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Measurement {
|
export interface Measurement {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user