mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 17:49:57 +00:00
allow null defaultRole on backend
This commit is contained in:
parent
f33ad9cc29
commit
64c995d4cc
@ -103,7 +103,7 @@ describeOnCondition(edition === 'EE')('SSO Provider Options', () => {
|
|||||||
])('can be %s', async (name, value) => {
|
])('can be %s', async (name, value) => {
|
||||||
const newData = {
|
const newData = {
|
||||||
ssoLockedRoles: value,
|
ssoLockedRoles: value,
|
||||||
defaultRole: localData.restrictedRole.id, // TODO: there seems to be a bug with not setting a default role
|
defaultRole: null,
|
||||||
autoRegister: false,
|
autoRegister: false,
|
||||||
};
|
};
|
||||||
const res = await requests.admin.put('/admin/providers/options', {
|
const res = await requests.admin.put('/admin/providers/options', {
|
||||||
@ -127,7 +127,7 @@ describeOnCondition(edition === 'EE')('SSO Provider Options', () => {
|
|||||||
const res = await requests.admin.put('/admin/providers/options', {
|
const res = await requests.admin.put('/admin/providers/options', {
|
||||||
body: {
|
body: {
|
||||||
ssoLockedRoles: value,
|
ssoLockedRoles: value,
|
||||||
defaultRole: localData.restrictedRole.id, // TODO: there seems to be a bug with not setting a default role
|
defaultRole: null,
|
||||||
autoRegister: false,
|
autoRegister: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -138,5 +138,49 @@ describeOnCondition(edition === 'EE')('SSO Provider Options', () => {
|
|||||||
expect(Array.isArray(res.body)).toBeFalsy();
|
expect(Array.isArray(res.body)).toBeFalsy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('autoRegister and defaultRole', () => {
|
||||||
|
test.each([
|
||||||
|
[null, false],
|
||||||
|
[1, false],
|
||||||
|
[1, true],
|
||||||
|
])('defaultRole can be %s when autoRegister is %s', async (defaultRole, autoRegister) => {
|
||||||
|
const newData = {
|
||||||
|
defaultRole,
|
||||||
|
autoRegister,
|
||||||
|
};
|
||||||
|
const res = await requests.admin.put('/admin/providers/options', {
|
||||||
|
body: newData,
|
||||||
|
});
|
||||||
|
if (hasSSO) {
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
const parsed = JSON.parse(res.text);
|
||||||
|
expect(parsed.data).toMatchObject(newData);
|
||||||
|
} else {
|
||||||
|
expect(res.status).toBe(404);
|
||||||
|
expect(Array.isArray(res.body)).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
[null, true],
|
||||||
|
[{}, true],
|
||||||
|
[9999, true],
|
||||||
|
])('defaultRole cannot be %s when autoRegister is %s', async (defaultRole, autoRegister) => {
|
||||||
|
const newData = {
|
||||||
|
defaultRole,
|
||||||
|
autoRegister,
|
||||||
|
};
|
||||||
|
const res = await requests.admin.put('/admin/providers/options', {
|
||||||
|
body: newData,
|
||||||
|
});
|
||||||
|
if (hasSSO) {
|
||||||
|
expect(res.status).toEqual(400);
|
||||||
|
} else {
|
||||||
|
expect(res.status).toBe(404);
|
||||||
|
expect(Array.isArray(res.body)).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,8 +6,13 @@ const providerOptionsUpdateSchema = yup.object().shape({
|
|||||||
autoRegister: yup.boolean().required(),
|
autoRegister: yup.boolean().required(),
|
||||||
defaultRole: yup
|
defaultRole: yup
|
||||||
.strapiID()
|
.strapiID()
|
||||||
.required()
|
.when('autoRegister', (value, initSchema) => {
|
||||||
|
return value ? initSchema.required() : initSchema.nullable();
|
||||||
|
})
|
||||||
.test('is-valid-role', 'You must submit a valid default role', (roleId) => {
|
.test('is-valid-role', 'You must submit a valid default role', (roleId) => {
|
||||||
|
if (roleId === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return strapi.admin.services.role.exists({ id: roleId });
|
return strapi.admin.services.role.exists({ id: roleId });
|
||||||
}),
|
}),
|
||||||
ssoLockedRoles: yup
|
ssoLockedRoles: yup
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user