Skip to content

Commit 8fe5936

Browse files
Ajout des schémas d'agents dans les composables
1 parent 2fcaf99 commit 8fe5936

File tree

1 file changed

+274
-0
lines changed

1 file changed

+274
-0
lines changed
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
import { type JSONSchema7 as JSONSchema } from 'json-schema';
2+
import { type UISchemaElement } from '@jsonforms/core';
3+
4+
type FormSchema = {
5+
schema: JSONSchema;
6+
uiSchema: UISchemaElement;
7+
};
8+
9+
type useAgentSchemasReturnType = {
10+
getAgentSchema: () => JSONSchema;
11+
getAgentUiSchema: () => UISchemaElement;
12+
getEditAgentSchema: () => JSONSchema;
13+
getEditAgentUiSchema: () => UISchemaElement;
14+
getEditAgentFormSchema: () => FormSchema;
15+
getAgentFormSchema: () => FormSchema;
16+
};
17+
18+
const agentSchema = {
19+
$schema: 'http://json-schema.org/draft-07/schema#',
20+
type: "object",
21+
properties: {
22+
username: {
23+
type: 'string',
24+
minLength: 1,
25+
},
26+
displayName: {
27+
type: 'string',
28+
},
29+
email: {
30+
type: 'string',
31+
format: 'email',
32+
},
33+
password: {
34+
type: 'string',
35+
minLength: 8,
36+
},
37+
thirdPartyAuth: {
38+
type: 'string',
39+
default: 'DEFAULT_THIRD_PARTY_AUTH',
40+
},
41+
state: {
42+
type: 'object',
43+
properties: {
44+
current: {
45+
type: 'string',
46+
},
47+
lastChangedAt: {
48+
type: 'string',
49+
format: 'date-time',
50+
},
51+
suspendedAt: {
52+
type: 'string',
53+
format: 'date-time',
54+
},
55+
suspendedUntil: {
56+
type: 'string',
57+
format: 'date-time',
58+
},
59+
suspendedReason: {
60+
type: 'string',
61+
},
62+
},
63+
required: ['current'],
64+
},
65+
baseURL: {
66+
type: 'string',
67+
default: '/',
68+
},
69+
security: {
70+
type: 'object',
71+
properties: {
72+
oldPasswords: {
73+
type: 'array',
74+
items: {
75+
type: 'string',
76+
},
77+
},
78+
otpKey: {
79+
type: 'string',
80+
},
81+
u2fKey: {
82+
type: 'array',
83+
items: {
84+
type: 'string',
85+
},
86+
},
87+
allowedNetworks: {
88+
type: 'array',
89+
items: {
90+
type: 'string',
91+
},
92+
},
93+
changePwdAtNextLogin: {
94+
type: 'boolean',
95+
default: false,
96+
},
97+
secretKey: {
98+
type: 'boolean',
99+
},
100+
},
101+
},
102+
customFields: {
103+
type: 'object',
104+
additionalProperties: true,
105+
},
106+
},
107+
required: ['username', 'email', 'password', 'state'],
108+
}
109+
110+
const agentUiSchema = {
111+
type: 'Group',
112+
label: 'Agent Information',
113+
elements: [
114+
{
115+
type: 'HorizontalLayout',
116+
elements: [
117+
{
118+
type: 'Control',
119+
label: 'Username',
120+
scope: '#/properties/username',
121+
options: {
122+
required: true,
123+
},
124+
},
125+
{
126+
type: 'Control',
127+
label: 'Display Name',
128+
scope: '#/properties/displayName',
129+
},
130+
{
131+
type: 'Control',
132+
label: 'Email',
133+
scope: '#/properties/email',
134+
options: {
135+
required: true,
136+
},
137+
},
138+
],
139+
},
140+
{
141+
type: 'HorizontalLayout',
142+
elements: [
143+
{
144+
type: 'Control',
145+
label: 'Mot de passe',
146+
scope: '#/properties/password',
147+
options: {
148+
required: true,
149+
type: 'password',
150+
},
151+
},
152+
{
153+
type: 'Control',
154+
label: 'Actif/Inactif',
155+
scope: '#/properties/state/properties/current',
156+
options: {
157+
required: true,
158+
suggestion: [
159+
{ value: -1, label: 'Inactif' },
160+
// { value: 0, label: 'En cours' },
161+
{ value: 1, label: 'Actif' },
162+
],
163+
},
164+
},
165+
// {
166+
// type: 'Control',
167+
// label: 'Third Party Auth',
168+
// scope: '#/properties/thirdPartyAuth',
169+
// },
170+
// {
171+
// type: 'Control',
172+
// label: 'Base URL',
173+
// scope: '#/properties/baseURL',
174+
// },
175+
],
176+
},
177+
// {
178+
// type: 'HorizontalLayout',
179+
// elements: [
180+
// // {
181+
// // type: 'Control',
182+
// // label: 'Last Changed At',
183+
// // scope: '#/properties/state/properties/lastChangedAt',
184+
// // options: {
185+
// // format: 'date',
186+
// // dateFormat: 'dd/MM/yyyy',
187+
// // },
188+
// // },
189+
// // {
190+
// // type: 'Control',
191+
// // label: 'Suspended At',
192+
// // scope: '#/properties/state/properties/suspendedAt',
193+
// // options: {
194+
// // format: 'date',
195+
// // dateFormat: 'dd/MM/yyyy',
196+
// // },
197+
// // },
198+
// ],
199+
// },
200+
// {
201+
// type: 'HorizontalLayout',
202+
// elements: [
203+
// {
204+
// type: 'Control',
205+
// label: 'Change Password at Next Login',
206+
// scope: '#/properties/security/properties/changePwdAtNextLogin',
207+
// options: {
208+
// required: false,
209+
// },
210+
// },
211+
// {
212+
// type: 'Control',
213+
// label: 'Anciens mots de passe',
214+
// scope: '#/properties/security/properties/oldPasswords',
215+
// options: {
216+
// required: false,
217+
// },
218+
// },
219+
// {
220+
// type: 'Control',
221+
// label: 'Allowed Networks',
222+
// scope: '#/properties/security/properties/allowedNetworks',
223+
// options: {
224+
// required: false,
225+
// },
226+
// },
227+
// ],
228+
// },
229+
],
230+
}
231+
232+
const agentEditSchema = null
233+
const agentEditUiSchema = null
234+
235+
export function useAgentSchemas(): useAgentSchemasReturnType {
236+
function getAgentSchema(): JSONSchema {
237+
return agentSchema
238+
}
239+
240+
function getAgentUiSchema(): UISchemaElement {
241+
return agentUiSchema
242+
}
243+
244+
function getEditAgentSchema(): JSONSchema {
245+
return agentEditSchema ?? agentSchema
246+
}
247+
248+
function getEditAgentUiSchema(): UISchemaElement {
249+
return agentEditUiSchema ?? agentUiSchema
250+
}
251+
252+
function getEditAgentFormSchema(): FormSchema {
253+
return {
254+
schema: getEditAgentSchema(),
255+
uiSchema: getEditAgentUiSchema(),
256+
}
257+
}
258+
259+
function getAgentFormSchema(): FormSchema {
260+
return {
261+
schema: getAgentSchema(),
262+
uiSchema: getAgentUiSchema(),
263+
}
264+
}
265+
266+
return {
267+
getAgentSchema,
268+
getAgentUiSchema,
269+
getEditAgentSchema,
270+
getEditAgentUiSchema,
271+
getEditAgentFormSchema,
272+
getAgentFormSchema,
273+
}
274+
}

0 commit comments

Comments
 (0)