-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feature/conditionally hide UI based on roles #1377
Changes from all commits
31f3cb7
3ae8800
2dd7cb3
5c5af1e
2987f27
0f4ec5f
18add51
49bb0a5
ebf7c14
f4796e2
3c7b8b4
64e471b
b24cde8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import ArrowBack from '@mui/icons-material/ArrowBack' | ||
import { Button, Container, Divider, Paper, Stack, Typography } from '@mui/material' | ||
import { useGetModel } from 'actions/model' | ||
import { useGetRelease } from 'actions/release' | ||
import { useGetReviewRequestsForModel, useGetReviewRequestsForUser } from 'actions/review' | ||
import { useGetCurrentUser } from 'actions/user' | ||
import { useRouter } from 'next/router' | ||
import { useState } from 'react' | ||
import { useMemo, useState } from 'react' | ||
import CopyToClipboardButton from 'src/common/CopyToClipboardButton' | ||
import Loading from 'src/common/Loading' | ||
import Title from 'src/common/Title' | ||
|
@@ -12,6 +14,8 @@ import ReviewBanner from 'src/entry/model/reviews/ReviewBanner' | |
import MultipleErrorWrapper from 'src/errors/MultipleErrorWrapper' | ||
import Link from 'src/Link' | ||
import ReviewComments from 'src/reviews/ReviewComments' | ||
import { EntryKind } from 'types/types' | ||
import { getCurrentUserRoles, hasRole } from 'utils/roles' | ||
|
||
export default function Release() { | ||
const router = useRouter() | ||
|
@@ -29,24 +33,41 @@ export default function Release() { | |
isReviewsLoading: isUserReviewsLoading, | ||
isReviewsError: isUserReviewsError, | ||
} = useGetReviewRequestsForUser() | ||
const { model, isModelLoading, isModelError } = useGetModel(modelId, EntryKind.MODEL) | ||
const { currentUser, isCurrentUserLoading, isCurrentUserError } = useGetCurrentUser() | ||
|
||
const userCanReview = | ||
reviews.filter((review) => | ||
userReviews.some( | ||
(userReview) => | ||
userReview.model.id === review.model.id && userReview.accessRequestId === review.accessRequestId, | ||
), | ||
).length > 0 | ||
const currentUserRoles = useMemo(() => getCurrentUserRoles(model, currentUser), [model, currentUser]) | ||
|
||
const userCanReview = useMemo( | ||
() => | ||
hasRole(currentUserRoles, ['msro', 'mtr']) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little apprehensive about having authorisation now in both the frontend as well as the backend as it's duplication that will not be good for maintainability. Specifically here it's important to remember that in the near future that the roles for reviews will be dynamic and defined in the schema. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I was conscious of that when writing this and have made a mental note to prepare for the amount of added effort this work will add to dynamic roles. I've tried to limit that by using the same util functions for most of this. There's definitely some changes that will need to be made once dynamic roles come in, but I'm hoping that's as simple as updating the As for the duplication of authorisation being in the frontend and backend, I'm not sure what we can do to solve that right now. This also leads into the read-only logic for mirrored models, which adds another layer of complexity, so I think we need to design a better solution that works for both. If we can come up with a solution that contains auth to the backend, even better. It's worth noting that this work only expands on our existing roles implementation in the frontend, so imo we should create a ticket to address this issue for both roles and mirrored models rather than doing it in this PR. |
||
reviews.filter((review) => | ||
userReviews.some( | ||
(userReview) => | ||
userReview.model.id === review.model.id && userReview.accessRequestId === review.accessRequestId, | ||
), | ||
).length > 0, | ||
[currentUserRoles, reviews, userReviews], | ||
) | ||
|
||
const error = MultipleErrorWrapper('Unable to load release', { | ||
isReleaseError, | ||
isReviewsError, | ||
isUserReviewsError, | ||
isModelError, | ||
isCurrentUserError, | ||
}) | ||
|
||
if (error) return error | ||
|
||
if (!release || (isReleaseLoading && isReviewsLoading && isUserReviewsLoading)) { | ||
if ( | ||
!release || | ||
isReleaseLoading || | ||
isReviewsLoading || | ||
isUserReviewsLoading || | ||
isModelLoading || | ||
isCurrentUserLoading | ||
) { | ||
return <Loading /> | ||
} | ||
|
||
|
@@ -79,7 +100,14 @@ export default function Release() { | |
/> | ||
</Stack> | ||
</Stack> | ||
{release && <EditableRelease release={release} isEdit={isEdit} onIsEditChange={setIsEdit} />} | ||
{release && ( | ||
<EditableRelease | ||
release={release} | ||
currentUserRoles={currentUserRoles} | ||
isEdit={isEdit} | ||
onIsEditChange={setIsEdit} | ||
/> | ||
)} | ||
<ReviewComments release={release} isEdit={isEdit} /> | ||
</Stack> | ||
</> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel about this. In my opinion the settings tab itself should be restricted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked the same thing, but it's important for any user to be able to see the collaborators in the entry access tab. We could simplify a lot of the settings roles logic if we find another place to display that information. I'll make a ticket to explore this idea.