Skip to content

Restrict creating Host Taxons #3431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const globalFieldOverrides: {
Attachment: {
tableID: 'optional',
},
CollectingEventAttribute: {
hostTaxon: 'readOnly',
},
Taxon: {
parent: 'required',
isAccepted: 'readOnly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function QueryComboBox({
typeSearch: initialTypeSearch,
forceCollection,
relatedModel: initialRelatedModel,
disableCanAdd = false,
}: {
readonly id: string | undefined;
readonly resource: SpecifyResource<AnySchema> | undefined;
Expand All @@ -75,6 +76,7 @@ export function QueryComboBox({
readonly typeSearch: Element | string | undefined;
readonly forceCollection: number | undefined;
readonly relatedModel?: SpecifyModel | undefined;
readonly disableCanAdd: boolean;
}): JSX.Element {
React.useEffect(() => {
if (resource === undefined || !resource.isNew()) return;
Expand Down Expand Up @@ -344,7 +346,8 @@ export function QueryComboBox({

const canAdd =
!RESTRICT_ADDING.has(field.relatedModel.name) &&
hasTablePermission(field.relatedModel.name, 'create');
hasTablePermission(field.relatedModel.name, 'create') &&
!disableCanAdd;

return (
<div className="flex w-full min-w-[theme(spacing.40)] items-center sm:min-w-[unset]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,29 @@ export function HostTaxon({
.maybe(records[0], deserializeResource)
?.rgetPromise('rightSideCollection')
)
.then((collection) => collection?.get('id')),
.then((collection) => collection),
[relationship]
),
false
);
return rightSideCollection === undefined ? (
return rightSideCollection === null || rightSideCollection === undefined ? (
<Input.Text isReadOnly />
) : hasTreeAccess('Taxon', 'read') ? (
<QueryComboBox
field={schema.models.CollectingEventAttribute.strictGetRelationship(
'hostTaxon'
)}
forceCollection={rightSideCollection}
forceCollection={rightSideCollection.get('id')}
formType={formType}
id={id}
isRequired={isRequired}
mode={mode}
relatedModel={schema.models.Taxon}
resource={resource}
typeSearch={hostTaxonTypeSearch}
disableCanAdd={
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good fix.
The query combo box receives forceCollection prop, which it can use to figure out if current collection is equal to forceCollection

In fact, this fix is already implemented. See #3283

In there, I added support for properly creating resource into a correct discipline: https://github.com/specify/specify7/pull/3283/files#diff-11908f1e0fbcca3761cf5d0d0635a57bbedbb34f38675283d64fa843a9af23f0R263-R268

But also, it disables the add feature (temporary). It's disabled only because tree rank pick list is loading data from a wrong discipline:
https://github.com/specify/specify7/pull/3283/files#diff-11908f1e0fbcca3761cf5d0d0635a57bbedbb34f38675283d64fa843a9af23f0R359-R364

Can you please review the code change on that pull request, and undo the query combo box changes on this branch

rightSideCollection.get('discipline') !== resource.get('discipline')
}
/>
) : null;
}