mirror of
https://github.com/strapi/strapi.git
synced 2025-08-06 15:53:11 +00:00
Feat: Add private option field for relations (#8149)
* feat(content-type): add private option to relation field Signed-off-by: tanmoyopenroot <tanmoy.openroot@gmail.com> * test(content-type): add test for private option in relation field Signed-off-by: tanmoyopenroot <tanmoy.openroot@gmail.com>
This commit is contained in:
parent
4844ba9ebe
commit
012902d94f
@ -331,6 +331,7 @@ const forms = {
|
|||||||
const nameValue = get(data, 'name', null);
|
const nameValue = get(data, 'name', null);
|
||||||
const relationItems = [
|
const relationItems = [
|
||||||
[fields.divider],
|
[fields.divider],
|
||||||
|
[fields.private],
|
||||||
[fields.unique],
|
[fields.unique],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
import fields from '../forms';
|
||||||
|
|
||||||
|
describe('forms', () => {
|
||||||
|
it('should contain private field in relation input type', () => {
|
||||||
|
const { items } = fields.attribute.form.advanced({}, 'relation', null);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
items.find(relationItem => relationItem.find(item => item.name === 'private')).length
|
||||||
|
).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -189,4 +189,47 @@ describe('Content Type Builder - Content types', () => {
|
|||||||
expect(updateRes.body.error).toMatch('multiple entries in DB');
|
expect(updateRes.body.error).toMatch('multiple entries in DB');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Private relation field', () => {
|
||||||
|
const singleTypeUID = 'application::test-single-type.test-single-type';
|
||||||
|
|
||||||
|
test('should add a relation field', async () => {
|
||||||
|
const res = await rq({
|
||||||
|
method: 'PUT',
|
||||||
|
url: `/content-type-builder/content-types/${singleTypeUID}`,
|
||||||
|
body: {
|
||||||
|
contentType: {
|
||||||
|
kind: 'singleType',
|
||||||
|
name: 'test-collection',
|
||||||
|
attributes: {
|
||||||
|
relation: {
|
||||||
|
private: true,
|
||||||
|
nature: 'oneWay',
|
||||||
|
target: 'plugins::users-permissions.user',
|
||||||
|
targetAttribute: 'test',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(201);
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
data: {
|
||||||
|
uid: singleTypeUID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should contain a private relation field', async () => {
|
||||||
|
const res = await rq({
|
||||||
|
method: 'GET',
|
||||||
|
url: `/content-type-builder/content-types/${singleTypeUID}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body.data.schema.attributes.relation).toBeDefined();
|
||||||
|
expect(res.body.data.schema.attributes.relation.private).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -85,6 +85,7 @@ const formatAttribute = (key, attribute, { model }) => {
|
|||||||
['attributes', attribute.via, 'columnName'],
|
['attributes', attribute.via, 'columnName'],
|
||||||
undefined
|
undefined
|
||||||
),
|
),
|
||||||
|
private: attribute.private ? true : false,
|
||||||
unique: attribute.unique ? true : false,
|
unique: attribute.unique ? true : false,
|
||||||
autoPopulate: attribute.autoPopulate,
|
autoPopulate: attribute.autoPopulate,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user