Skip to content

Commit

Permalink
Merge pull request #561 from bcgsc/release/v6.31.1
Browse files Browse the repository at this point in the history
Release/v6.31.1
  • Loading branch information
elewis2 authored Aug 15, 2024
2 parents 5f4315b + cb909b1 commit 8cac622
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 181 deletions.
31 changes: 21 additions & 10 deletions app/components/SignatureCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,44 @@ const SignatureCard = ({
const { userDetails } = useSecurity();

const [userSignature, setUserSignature] = useState<UserType>();
const [role, setRole] = useState('');
const [role, setRole] = useState<string>();

useEffect(() => {
if (type) { // need to do these separately because signatures may be null
if (type === 'author') {
setRole('author');
} else if (type === 'reviewer') {
setRole('reviewer');
} else if (type === 'creator') {
setRole('creator');
}
}
if (signatures && type) {
if (type === 'author') {
setUserSignature(signatures.authorSignature);
setRole('author');
} else if (type === 'reviewer') {
setUserSignature(signatures.reviewerSignature);
setRole('reviewer');
} else if (type === 'creator') {
setUserSignature(signatures.creatorSignature);
setRole('bioinformatician');
}
}
}, [signatures, type, setRole]);

const handleSign = useCallback(async () => {
let newReport = null;

let reportRole = role;
// Assign user
try {
if (role === 'creator') {
reportRole = 'bioinformatician';
} else if (role === 'author') {
// Hardcode analyst role here because report does not accept 'author'
reportRole = 'analyst';
}
newReport = await api.post(
`/reports/${report.ident}/user`,
// Hardcode analyst role here because report does not accept 'author'
{ user: userDetails.ident, role: 'analyst' },
{ user: userDetails.ident, role: reportRole },
{},
).request();
} catch (e) {
Expand All @@ -79,7 +91,6 @@ const SignatureCard = ({
snackbar.error('Error assigning user to report: ', e.message);
}
}

// Do signature
try {
const newSignature = await api.put(
Expand Down Expand Up @@ -198,9 +209,9 @@ const SignatureCard = ({
Date
</Typography>
{renderDate ?? (
<Typography>
{NON_BREAKING_SPACE}
</Typography>
<Typography>
{NON_BREAKING_SPACE}
</Typography>
)}
</div>
{userSignature?.ident && canEdit && (
Expand Down
98 changes: 58 additions & 40 deletions app/context/ResourceContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const useResources = (): ResourceContextType => {
*/
const [reportAssignmentAccess, setReportAssignmentAccess] = useState(false);
const [adminAccess, setAdminAccess] = useState(false);
const [allProjectsAccess, setAllProjectsAccess] = useState(false);
const [managerAccess, setManagerAccess] = useState(false);
/**
* Is the user allowed to see the settings page
Expand All @@ -67,6 +68,10 @@ const useResources = (): ResourceContextType => {
setAdminAccess(true);
}

if (checkAccess(groups, [...ADMIN_ACCESS, 'all projects access'], ADMIN_BLOCK)) {
setAllProjectsAccess(true);
}

if (checkAccess(groups, [...ADMIN_ACCESS, 'manager'], ADMIN_BLOCK)) {
setManagerAccess(true);
}
Expand Down Expand Up @@ -99,38 +104,40 @@ const useResources = (): ResourceContextType => {
}, [groups]);

return {
germlineAccess,
reportsAccess,
adminAccess,
allProjectsAccess,
allStates: ALL_STATES,
appendixEditAccess,
germlineAccess,
managerAccess,
reportSettingAccess,
reportEditAccess,
reportAssignmentAccess,
unreviewedAccess,
nonproductionAccess,
nonproductionStates: NONPRODUCTION_STATES,
reportAssignmentAccess,
reportEditAccess,
reportSettingAccess,
reportsAccess,
templateEditAccess,
appendixEditAccess,
allStates: ALL_STATES,
unreviewedAccess,
unreviewedStates: UNREVIEWED_STATES,
nonproductionStates: NONPRODUCTION_STATES,
};
};

const ResourceContext = createContext<ResourceContextType>({
germlineAccess: false,
reportsAccess: false,
adminAccess: false,
allProjectsAccess: false,
allStates: ALL_STATES,
appendixEditAccess: false,
germlineAccess: false,
managerAccess: false,
reportSettingAccess: false,
reportEditAccess: false,
reportAssignmentAccess: false,
unreviewedAccess: false,
nonproductionAccess: false,
nonproductionStates: NONPRODUCTION_STATES,
reportAssignmentAccess: false,
reportEditAccess: false,
reportSettingAccess: false,
reportsAccess: false,
templateEditAccess: false,
appendixEditAccess: false,
allStates: ALL_STATES,
unreviewedAccess: false,
unreviewedStates: UNREVIEWED_STATES,
nonproductionStates: NONPRODUCTION_STATES,
});

type ResourceContextProviderProps = {
Expand All @@ -139,44 +146,55 @@ type ResourceContextProviderProps = {

const ResourceContextProvider = ({ children }: ResourceContextProviderProps): JSX.Element => {
const {
germlineAccess, reportsAccess, adminAccess, managerAccess, reportSettingAccess, reportEditAccess, reportAssignmentAccess, unreviewedAccess, nonproductionAccess,
templateEditAccess,
appendixEditAccess,
adminAccess,
allProjectsAccess,
allStates,
unreviewedStates,
appendixEditAccess,
germlineAccess,
managerAccess,
nonproductionAccess,
nonproductionStates,
reportAssignmentAccess,
reportEditAccess,
reportSettingAccess,
reportsAccess,
templateEditAccess,
unreviewedAccess,
unreviewedStates,
} = useResources();

const providerValue = useMemo(() => ({
germlineAccess,
reportsAccess,
adminAccess,
allProjectsAccess,
allStates,
appendixEditAccess,
germlineAccess,
managerAccess,
reportSettingAccess,
reportEditAccess,
reportAssignmentAccess,
unreviewedAccess,
nonproductionAccess,
nonproductionStates,
reportAssignmentAccess,
reportEditAccess,
reportSettingAccess,
reportsAccess,
templateEditAccess,
appendixEditAccess,
allStates,
unreviewedAccess,
unreviewedStates,
nonproductionStates,
}), [
germlineAccess,
reportsAccess,
adminAccess,
allProjectsAccess,
allStates,
appendixEditAccess,
germlineAccess,
managerAccess,
reportSettingAccess,
reportEditAccess,
reportAssignmentAccess,
unreviewedAccess,
nonproductionAccess,
nonproductionStates,
reportAssignmentAccess,
reportEditAccess,
reportSettingAccess,
reportsAccess,
templateEditAccess,
appendixEditAccess,
allStates,
unreviewedAccess,
unreviewedStates,
nonproductionStates,
]);

return (
Expand Down
19 changes: 10 additions & 9 deletions app/context/ResourceContext/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
type ResourceContextType = {
germlineAccess: boolean;
reportsAccess: boolean;
adminAccess: boolean;
managerAccess: boolean;
templateEditAccess: boolean;
allStates: string[];
allProjectsAccess: boolean;
appendixEditAccess: boolean;
reportSettingAccess: boolean;
reportEditAccess: boolean;
germlineAccess: boolean;
managerAccess: boolean;
nonproductionAccess: boolean;
nonproductionStates: string[];
reportAssignmentAccess: boolean;
reportEditAccess: boolean;
reportSettingAccess: boolean;
reportsAccess: boolean;
templateEditAccess: boolean;
unreviewedAccess: boolean;
nonproductionAccess: boolean;
allStates: string[];
unreviewedStates: string[];
nonproductionStates: string[];
};

export default ResourceContextType;
Loading

0 comments on commit 8cac622

Please sign in to comment.