Add showEvenIfPermissionDoesNotExist property to Field interface

This commit is contained in:
Simon Larsen
2023-12-19 17:42:54 +00:00
parent 9a6d8c9459
commit d67ee57bf0
12 changed files with 28 additions and 24 deletions

View File

@@ -167,7 +167,7 @@ const RegisterPage: () => JSX.Element = () => {
title: 'Confirm Password',
overrideFieldKey: 'confirmPassword',
required: true,
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
},
]);

View File

@@ -118,7 +118,11 @@ const ModelForm: <TBaseModel extends BaseModel>(
? (Object.keys(field.field)[0] as string)
: null;
if (key && (hasPermissionOnField(key) || field.forceShow)) {
if (
key &&
(hasPermissionOnField(key) ||
field.showEvenIfPermissionDoesNotExist)
) {
(select as Dictionary<boolean>)[key] = true;
}
}
@@ -224,7 +228,7 @@ const ModelForm: <TBaseModel extends BaseModel>(
const hasPermission: boolean = hasPermissionOnField(key);
if (
(field.forceShow || hasPermission) &&
(field.showEvenIfPermissionDoesNotExist || hasPermission) &&
fieldsToSet.filter((i: ModelField<TBaseModel>) => {
const fieldObj:
| {

View File

@@ -45,7 +45,7 @@ export default interface Field<TEntity> {
description?: string;
field?: SelectFormFields<TEntity> | undefined;
placeholder?: string;
forceShow?: boolean; // show this field even if user does not have permissions to view.
showEvenIfPermissionDoesNotExist?: boolean; // show this field even if user does not have permissions to view.
disabled?: boolean;
stepId?: string | undefined;
required?: boolean | ((item: FormValues<TEntity>) => boolean) | undefined;

View File

@@ -343,7 +343,7 @@ const IncidentsTable: FunctionComponent<ComponentProps> = (
overrideField: {
ownerTeams: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Teams',
stepId: 'owners',
description:
@@ -362,7 +362,7 @@ const IncidentsTable: FunctionComponent<ComponentProps> = (
overrideField: {
ownerUsers: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Users',
stepId: 'owners',
description:

View File

@@ -174,7 +174,7 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
overrideField: {
ownerTeams: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Teams',
stepId: 'owners',
description:
@@ -193,7 +193,7 @@ const ScheduledMaintenancesTable: FunctionComponent<ComponentProps> = (
overrideField: {
ownerUsers: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Users',
stepId: 'owners',
description:

View File

@@ -150,7 +150,7 @@ const OnCallPolicyDelete: FunctionComponent<PageComponentProps> = (
overrideField: {
teams: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Teams',
stepId: 'notification',
description:
@@ -169,7 +169,7 @@ const OnCallPolicyDelete: FunctionComponent<PageComponentProps> = (
overrideField: {
onCallSchedules: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'On Call Duty Schedules',
stepId: 'notification',
description:
@@ -188,7 +188,7 @@ const OnCallPolicyDelete: FunctionComponent<PageComponentProps> = (
overrideField: {
users: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Users',
stepId: 'notification',
description:

View File

@@ -210,7 +210,7 @@ const IncidentTemplates: FunctionComponent<PageComponentProps> = (
overrideField: {
ownerTeams: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Teams',
stepId: 'owners',
description:
@@ -229,7 +229,7 @@ const IncidentTemplates: FunctionComponent<PageComponentProps> = (
overrideField: {
ownerUsers: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Owner - Users',
stepId: 'owners',
description:

View File

@@ -146,7 +146,7 @@ const Settings: FunctionComponent<PageComponentProps> = (
overrideField: {
notificationMethod: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
overrideFieldKey: 'notificationMethod',
title: 'Notification Method',
description: 'How do you want to be notified?',

View File

@@ -117,7 +117,7 @@ const ForgotPassword: FunctionComponent<ComponentProps> = (
email: true,
},
title: 'Email',
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
fieldType: FormFieldSchemaType.Email,
required: true,
},

View File

@@ -132,7 +132,7 @@ const LoginPage: FunctionComponent<ComponentProps> = (
field: {
email: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Email',
fieldType: FormFieldSchemaType.Email,
required: true,
@@ -143,7 +143,7 @@ const LoginPage: FunctionComponent<ComponentProps> = (
},
title: 'Password',
required: true,
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
validation: {
minLength: 6,
},

View File

@@ -122,7 +122,7 @@ const ResetPassword: FunctionComponent<ComponentProps> = (
field: {
password: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
fieldType: FormFieldSchemaType.Password,
validation: {
minLength: 6,
@@ -139,7 +139,7 @@ const ResetPassword: FunctionComponent<ComponentProps> = (
minLength: 6,
toMatchField: 'password',
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
fieldType: FormFieldSchemaType.Password,
placeholder: 'Confirm Password',
title: 'Confirm Password',

View File

@@ -107,7 +107,7 @@ const SubscribePage: FunctionComponent<SubscribePageProps> = (
field: {
subscriberEmail: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Your Email',
fieldType: FormFieldSchemaType.Email,
required: (model: FormValues<StatusPageSubscriber>) => {
@@ -123,7 +123,7 @@ const SubscribePage: FunctionComponent<SubscribePageProps> = (
field: {
subscriberPhone: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Your Phone Number',
fieldType: FormFieldSchemaType.Email,
required: (model: FormValues<StatusPageSubscriber>) => {
@@ -142,7 +142,7 @@ const SubscribePage: FunctionComponent<SubscribePageProps> = (
field: {
isSubscribedToAllResources: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Subscribe to All Resources',
description:
'Select this option if you want to subscribe to all resources.',
@@ -155,7 +155,7 @@ const SubscribePage: FunctionComponent<SubscribePageProps> = (
field: {
statusPageResources: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Select Resources to Subscribe',
description:
'Please select the resources you want to subscribe to.',
@@ -172,7 +172,7 @@ const SubscribePage: FunctionComponent<SubscribePageProps> = (
field: {
isUnsubscribed: true,
},
forceShow: true,
showEvenIfPermissionDoesNotExist: true,
title: 'Unsubscribe',
description:
'Please select this if you would like to unsubscribe from all resources.',