@@ -3,15 +3,16 @@ import { useTranslation } from 'react-i18next';
33
44import { Button , ButtonWithConfirmation , Header , ListEmptyMessage , Modal , Pagination , SpaceBetween , Table } from 'components' ;
55
6- import { useCollection , useNotifications } from 'hooks' ;
6+ import { useCollection , useNotifications , usePermissionGuard } from 'hooks' ;
7+ import { getServerError } from 'libs' ;
78import {
89 useDeleteSecretsMutation ,
910 useGetAllSecretsQuery ,
1011 useLazyGetSecretQuery ,
1112 useUpdateSecretMutation ,
1213} from 'services/secrets' ;
14+ import { GlobalUserRole , ProjectUserRole } from 'types' ;
1315
14- import { getServerError } from '../../../libs' ;
1516import { SecretForm } from './Form' ;
1617
1718import { IProps , TFormValues } from './types' ;
@@ -24,18 +25,31 @@ export const ProjectSecrets: React.FC<IProps> = ({ project, loading }) => {
2425 const projectName = project ?. project_name ?? '' ;
2526 const [ pushNotification ] = useNotifications ( ) ;
2627
27- const { data, isLoading, isFetching } = useGetAllSecretsQuery ( { project_name : projectName } ) ;
28+ const [ hasPermissionForSecretsManaging ] = usePermissionGuard ( {
29+ allowedProjectRoles : [ ProjectUserRole . ADMIN ] ,
30+ allowedGlobalRoles : [ GlobalUserRole . ADMIN ] ,
31+ } ) ;
32+
33+ const { data, isLoading, isFetching } = useGetAllSecretsQuery (
34+ { project_name : projectName } ,
35+ { skip : ! hasPermissionForSecretsManaging } ,
36+ ) ;
2837 const [ updateSecret , { isLoading : isUpdating } ] = useUpdateSecretMutation ( ) ;
2938 const [ deleteSecret , { isLoading : isDeleting } ] = useDeleteSecretsMutation ( ) ;
3039 const [ getSecret , { isLoading : isGettingSecrets } ] = useLazyGetSecretQuery ( ) ;
3140
3241 const { items, paginationProps, collectionProps } = useCollection ( data ?? [ ] , {
3342 filtering : {
34- empty : (
43+ empty : hasPermissionForSecretsManaging ? (
3544 < ListEmptyMessage
3645 title = { t ( 'projects.edit.secrets.empty_message_title' ) }
3746 message = { t ( 'projects.edit.secrets.empty_message_text' ) }
3847 />
48+ ) : (
49+ < ListEmptyMessage
50+ title = { t ( 'projects.edit.secrets.not_permissions_title' ) }
51+ message = { t ( 'projects.edit.secrets.not_permissions_description' ) }
52+ />
3953 ) ,
4054 } ,
4155 pagination : { pageSize : 10 } ,
@@ -126,6 +140,10 @@ export const ProjectSecrets: React.FC<IProps> = ({ project, loading }) => {
126140 } ;
127141
128142 const renderActions = ( ) => {
143+ if ( ! hasPermissionForSecretsManaging ) {
144+ return null ;
145+ }
146+
129147 const actions = [
130148 < Button key = "add" formAction = "none" onClick = { addSecretHandler } >
131149 { t ( 'common.add' ) }
@@ -161,29 +179,37 @@ export const ProjectSecrets: React.FC<IProps> = ({ project, loading }) => {
161179 items = { items }
162180 loading = { isLoading }
163181 header = {
164- < Header variant = "h2" counter = { `(${ items ?. length } )` } actions = { renderActions ( ) } >
182+ < Header
183+ variant = "h2"
184+ counter = { hasPermissionForSecretsManaging ? `(${ items ?. length } )` : '' }
185+ actions = { renderActions ( ) }
186+ >
165187 { t ( 'projects.edit.secrets.section_title' ) }
166188 </ Header >
167189 }
168190 pagination = { < Pagination { ...paginationProps } /> }
169191 />
170192
171- < Modal
172- header = {
173- initialFormValues ?. id ? t ( 'projects.edit.secrets.update_secret' ) : t ( 'projects.edit.secrets.create_secret' )
174- }
175- visible = { isShowModal }
176- onDismiss = { closeModal }
177- >
178- { isShowModal && (
179- < SecretForm
180- initialValues = { initialFormValues }
181- onSubmit = { updateOrCreateSecret }
182- loading = { isLoading || isUpdating }
183- onCancel = { closeModal }
184- />
185- ) }
186- </ Modal >
193+ { hasPermissionForSecretsManaging && (
194+ < Modal
195+ header = {
196+ initialFormValues ?. id
197+ ? t ( 'projects.edit.secrets.update_secret' )
198+ : t ( 'projects.edit.secrets.create_secret' )
199+ }
200+ visible = { isShowModal }
201+ onDismiss = { closeModal }
202+ >
203+ { isShowModal && (
204+ < SecretForm
205+ initialValues = { initialFormValues }
206+ onSubmit = { updateOrCreateSecret }
207+ loading = { isLoading || isUpdating }
208+ onCancel = { closeModal }
209+ />
210+ ) }
211+ </ Modal >
212+ ) }
187213 </ >
188214 ) ;
189215} ;
0 commit comments