Update user editing to support new email field

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

View File

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

View File

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

View File

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