Switching user activity state to an options field rather than boolean (more extensible).
This commit is contained in:
parent
3dd927e15e
commit
d9aa1a4890
|
@ -29,7 +29,7 @@
|
||||||
let customSchema = { ...schema }
|
let customSchema = { ...schema }
|
||||||
delete customSchema["email"]
|
delete customSchema["email"]
|
||||||
delete customSchema["roleId"]
|
delete customSchema["roleId"]
|
||||||
delete customSchema["active"]
|
delete customSchema["status"]
|
||||||
return Object.entries(customSchema)
|
return Object.entries(customSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,9 +81,9 @@
|
||||||
{/each}
|
{/each}
|
||||||
</Select>
|
</Select>
|
||||||
<RowFieldControl
|
<RowFieldControl
|
||||||
meta={{ name: 'active', type: 'boolean' }}
|
meta={{ name: 'status', type: 'options', constraints: {inclusion: ['active', 'inactive']} }}
|
||||||
bind:value={row.active}
|
bind:value={row.status}
|
||||||
defaultValue={true} />
|
defaultValue={'active'} />
|
||||||
{#each customSchemaKeys as [key, meta]}
|
{#each customSchemaKeys as [key, meta]}
|
||||||
{#if !meta.autocolumn}
|
{#if !meta.autocolumn}
|
||||||
<RowFieldControl {meta} bind:value={row[key]} {creating} />
|
<RowFieldControl {meta} bind:value={row[key]} {creating} />
|
||||||
|
|
|
@ -7,6 +7,7 @@ const { generateUserID } = require("../../db/utils")
|
||||||
const { setCookie } = require("../../utilities")
|
const { setCookie } = require("../../utilities")
|
||||||
const { outputProcessing } = require("../../utilities/rowProcessor")
|
const { outputProcessing } = require("../../utilities/rowProcessor")
|
||||||
const { ViewNames } = require("../../db/utils")
|
const { ViewNames } = require("../../db/utils")
|
||||||
|
const { UserStatus } = require("../../constants")
|
||||||
|
|
||||||
const INVALID_ERR = "Invalid Credentials"
|
const INVALID_ERR = "Invalid Credentials"
|
||||||
|
|
||||||
|
@ -32,9 +33,8 @@ exports.authenticate = async ctx => {
|
||||||
ctx.throw(401, INVALID_ERR)
|
ctx.throw(401, INVALID_ERR)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the user is currently active, make sure its a boolean false
|
// check that the user is currently inactive, if this is the case throw invalid
|
||||||
// so that older users which don't have this set are handled
|
if (dbUser.status === UserStatus.INACTIVE) {
|
||||||
if (typeof dbUser.active === "boolean" && !dbUser.active) {
|
|
||||||
ctx.throw(401, INVALID_ERR)
|
ctx.throw(401, INVALID_ERR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ const CouchDB = require("../../db")
|
||||||
const bcrypt = require("../../utilities/bcrypt")
|
const bcrypt = require("../../utilities/bcrypt")
|
||||||
const { generateUserID, getUserParams, ViewNames } = require("../../db/utils")
|
const { generateUserID, getUserParams, ViewNames } = require("../../db/utils")
|
||||||
const { getRole } = require("../../utilities/security/roles")
|
const { getRole } = require("../../utilities/security/roles")
|
||||||
|
const { UserStatus } = require("../../constants")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const database = new CouchDB(ctx.user.appId)
|
const database = new CouchDB(ctx.user.appId)
|
||||||
|
@ -43,8 +44,8 @@ exports.create = async function(ctx) {
|
||||||
tableId: ViewNames.USERS,
|
tableId: ViewNames.USERS,
|
||||||
}
|
}
|
||||||
// add the active status to a user if its not provided
|
// add the active status to a user if its not provided
|
||||||
if (typeof user.active !== "boolean") {
|
if (user.status == null) {
|
||||||
user.active = true
|
user.status = UserStatus.ACTIVE
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,6 +18,11 @@ exports.AuthTypes = {
|
||||||
EXTERNAL: "external",
|
EXTERNAL: "external",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.UserStatus = {
|
||||||
|
ACTIVE: "active",
|
||||||
|
INACTIVE: "inactive",
|
||||||
|
}
|
||||||
|
|
||||||
exports.USERS_TABLE_SCHEMA = {
|
exports.USERS_TABLE_SCHEMA = {
|
||||||
_id: "ta_users",
|
_id: "ta_users",
|
||||||
type: "table",
|
type: "table",
|
||||||
|
@ -47,13 +52,14 @@ exports.USERS_TABLE_SCHEMA = {
|
||||||
inclusion: Object.values(BUILTIN_ROLE_IDS),
|
inclusion: Object.values(BUILTIN_ROLE_IDS),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
active: {
|
status: {
|
||||||
fieldName: "active",
|
fieldName: "status",
|
||||||
name: "active",
|
name: "status",
|
||||||
type: exports.FieldTypes.BOOLEAN,
|
type: exports.FieldTypes.OPTIONS,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: exports.FieldTypes.BOOLEAN,
|
type: exports.FieldTypes.STRING,
|
||||||
presence: false,
|
presence: false,
|
||||||
|
inclusion: Object.values(exports.UserStatus),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue