Update user editing to support new email field

This commit is contained in:
Andrew Kingston 2020-12-08 11:43:37 +00:00
parent 1acdcd173c
commit d0f2d4c2cd
3 changed files with 30 additions and 26 deletions

View File

@ -50,7 +50,7 @@
$: isUsersTable = tableId === TableNames.USERS
$: {
if (isUsersTable) {
schema.username.displayFieldName = "Username"
schema.email.displayFieldName = "Email"
schema.roleId.displayFieldName = "Role"
}
}

View File

@ -31,7 +31,7 @@
const getCustomSchemaKeys = schema => {
let customSchema = { ...schema }
delete customSchema["username"]
delete customSchema["email"]
delete customSchema["roleId"]
return Object.entries(customSchema)
}
@ -72,8 +72,8 @@
onConfirm={saveRow}>
<ErrorsBox {errors} />
<RowFieldControl
meta={{ ...tableSchema.username, name: 'Username' }}
bind:value={row.username}
meta={{ ...tableSchema.email, name: 'Email' }}
bind:value={row.email}
readonly={!creating} />
{#if creating}
<RowFieldControl

View File

@ -1,16 +1,20 @@
const {
const {
createApplication,
createTable,
createView,
supertest,
defaultHeaders
defaultHeaders,
} = require("./couchTestUtils")
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles")
const {
BUILTIN_ROLE_IDS,
} = require("../../../utilities/security/roles")
const { BUILTIN_PERMISSION_IDS } = require("../../../utilities/security/permissions")
BUILTIN_PERMISSION_IDS,
} = require("../../../utilities/security/permissions")
const roleBody = { name: "NewRole", inherits: BUILTIN_ROLE_IDS.BASIC, permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY }
const roleBody = {
name: "NewRole",
inherits: BUILTIN_ROLE_IDS.BASIC,
permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY,
}
describe("/roles", () => {
let server
@ -20,8 +24,8 @@ describe("/roles", () => {
let view
beforeAll(async () => {
({ request, server } = await supertest())
});
;({ request, server } = await supertest())
})
afterAll(() => {
server.close()
@ -35,30 +39,29 @@ describe("/roles", () => {
})
describe("create", () => {
it("returns a success message when role is successfully created", async () => {
const res = await request
.post(`/api/roles`)
.send(roleBody)
.set(defaultHeaders(appId))
.expect('Content-Type', /json/)
.expect("Content-Type", /json/)
.expect(200)
expect(res.res.statusMessage).toEqual("Role 'NewRole' created successfully.")
expect(res.res.statusMessage).toEqual(
"Role 'NewRole' created successfully."
)
expect(res.body._id).toBeDefined()
expect(res.body._rev).toBeDefined()
})
});
})
describe("fetch", () => {
it("should list custom roles, plus 2 default roles", async () => {
const createRes = await request
.post(`/api/roles`)
.send(roleBody)
.set(defaultHeaders(appId))
.expect('Content-Type', /json/)
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
@ -66,10 +69,10 @@ describe("/roles", () => {
const res = await request
.get(`/api/roles`)
.set(defaultHeaders(appId))
.expect('Content-Type', /json/)
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.length).toBe(3)
expect(res.body.length).toBe(5)
const adminRole = res.body.find(r => r._id === BUILTIN_ROLE_IDS.ADMIN)
expect(adminRole).toBeDefined()
@ -84,10 +87,11 @@ describe("/roles", () => {
const customRoleFetched = res.body.find(r => r._id === customRole._id)
expect(customRoleFetched).toBeDefined()
expect(customRoleFetched.inherits).toEqual(BUILTIN_ROLE_IDS.BASIC)
expect(customRoleFetched.permissionId).toEqual(BUILTIN_PERMISSION_IDS.READ_ONLY)
expect(customRoleFetched.permissionId).toEqual(
BUILTIN_PERMISSION_IDS.READ_ONLY
)
})
});
})
describe("destroy", () => {
it("should delete custom roles", async () => {
@ -95,7 +99,7 @@ describe("/roles", () => {
.post(`/api/roles`)
.send({ name: "user", permissionId: BUILTIN_PERMISSION_IDS.READ_ONLY })
.set(defaultHeaders(appId))
.expect('Content-Type', /json/)
.expect("Content-Type", /json/)
.expect(200)
const customRole = createRes.body
@ -111,4 +115,4 @@ describe("/roles", () => {
.expect(404)
})
})
});
})