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