Skip to content

Commit

Permalink
Check all 6 collections when select set as admin for 6
Browse files Browse the repository at this point in the history
Fixes #2695
  • Loading branch information
CarolineDenis committed Mar 14, 2024
1 parent 960e250 commit 268443a
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import type { SpecifyResource } from '../DataModel/legacyTypes';
import type { SpecifyUser } from '../DataModel/types';
import { userInformation } from '../InitialContext/userInformation';
import { hasPermission } from '../Permissions/helpers';
import { ping } from '../../utils/ajax/ping';
import { useAsyncState } from '../../hooks/useAsyncState';
import { fetchCollection } from '../DataModel/collection';

export function AdminStatusPlugin({
user: resource,
Expand All @@ -28,7 +31,17 @@ export function AdminStatusPlugin({
const loading = React.useContext(LoadingContext);
const [user] = useResource(resource);
const isCurrentUser = userInformation.id === user.id;

const [allCollections] = useAsyncState(
React.useCallback(
async () =>
fetchCollection('Collection', { limit: 0, domainFilter: false }).then(
({ records }) => records
),
[]
),
true
);
const allCollectionIds = allCollections?.map((collection) => collection.id);
return (
<Button.Small
className="w-fit"
Expand Down Expand Up @@ -60,7 +73,19 @@ export function AdminStatusPlugin({
headers: {
Accept: 'text/plain',
},
}).then(({ data }) => handleChange(data === 'true'))
})
.then(({ data }) => {
handleChange(data === 'true');
return data;
})
.then((data) => {
data === 'true'
? ping(`/context/user_collection_access_for_sp6/${user.id}/`, {
method: 'PUT',
body: allCollectionIds,
})
: undefined;
})
)
}
>
Expand Down

0 comments on commit 268443a

Please sign in to comment.