import type { ComponentType, FormType } from "../../../interfaces";
export function getRoleComponent({ label, key, description, choices, data }: any): ComponentType {
return {
label,
key,
description,
type: "select",
labelPosition: "top",
widget: "choicesjs",
placeholder: "Select roles...",
tooltip: "",
multiple: true,
input: true,
dataSrc: "values",
defaultValue: "",
data: {
values: choices
},
template: "{{ item.label }}",
searchEnabled: true,
selectThreshold: 0,
validate: {
required: false,
custom: "",
customPrivate: false
},
values: data
};
}
function toDescription(description: string, hr = true): string {
return '' + description + " " + (hr ? '
' : "");
}
export function getSubmissionPermissionForm({ choices }: any): FormType {
return {
description: "Elevated permissions allow users to access and modify other user's entities. Assign with caution.",
components: [
getRoleComponent({
key: "create_own",
label: 'Create Own Submissions
',
description: toDescription(
"The Create Own Submissions permission will allow a user with one of the Roles to create a Submission. Upon creating the Submission, the user will be defined as its owner."
),
choices
}),
getRoleComponent({
key: "create_all",
label: 'Create All Submissions
',
description: toDescription(
'Elevated Permission: The Create All Submissions permission will allow a user with one of the Roles to create a new Submission and assign ownership of that Submission to another user.'
),
choices
}),
getRoleComponent({
key: "read_own",
label: 'Read Own Submissions
',
description: toDescription(
"The Read Own Submissions permission will allow a user with one of the Roles to read a Submission. A user can only read a Submission if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "read_all",
label: 'Read All Submissions
',
description: toDescription(
'Elevated Permission: The Read All Submissions permission will allow a user with one of the Roles to read all Submissions regardless of who owns them.'
),
choices
}),
getRoleComponent({
key: "update_own",
label: 'Update Own Submissions
',
description: toDescription(
"The Update Own Submissions permission will allow a user with one of the Roles to update a Submission. A user can only update a Submission if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "update_all",
label: 'Update All Submissions
',
description: toDescription(
'Elevated Permission: The Update All Submissions permission will allow a user with one of the Roles to update a Submission, regardless of who owns the Submission. Additionally with this permission, a user can change the owner of a Submission.'
),
choices
}),
getRoleComponent({
key: "delete_own",
label: 'Delete Own Submissions
',
description: toDescription(
"The Delete Own Submissions permission will allow a user with one of the Roles, to delete a Submission. A user can only delete a Submission if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "delete_all",
label: 'Delete All Submissions
',
description: toDescription(
'Elevated Permission: The Delete All Submissions permission will allow a user with one of the Roles to delete a Submission, regardless of who owns the Submission.',
false
),
choices
})
]
};
}
export function getAccessPermissionForm({ choices }: any): FormType {
return {
description: "Elevated permissions allow users to access and modify other user's entities. Assign with caution.",
components: [
getRoleComponent({
key: "read_own",
label: 'Read Form Definition (Restricted to owner)
',
description: toDescription(
"The Read Own permission will allow a user, with one of the given Roles, to read a form. A user can only read a form if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "read_all",
label: "Read Form Definition
",
description: toDescription(
'Elevated Permission: The Read permission will allow a user, with one of the given Roles, to read the form.'
),
choices
}),
getRoleComponent({
key: "update_own",
label: 'Update Form Definition (Restricted to owner)
',
description: toDescription(
"The Update Own permission will allow a user, with one of the given Roles, to update a form. A user can only update a form if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "update_all",
label: 'Update Form Definition
',
description: toDescription(
'Elevated Permission: The Update permission will allow a user, with one of the given Roles, to read and edit the form.'
),
choices
}),
getRoleComponent({
key: "delete_own",
label: 'Delete Form Definition (Restricted to owner)
',
description: toDescription(
"The Delete Own permission will allow a user, with one of the given Roles, to delete a form. A user can only delete a form if they are defined as its owner."
),
choices
}),
getRoleComponent({
key: "delete_all",
label: 'Delete Form Definition
',
description: toDescription(
'Elevated Permission: The Delete permission will allow a user, with one of the given Roles, to delete the form.',
false
),
choices
})
]
};
}