11import { VStack , Box , Flex , Text , Avatar , IconButton , Modal , ModalOverlay , ModalContent , ModalHeader , ModalCloseButton , ModalBody , ModalFooter , Button , useColorMode , Badge , HStack , Divider , useToast , FormControl , FormLabel , Input , Tooltip } from '@chakra-ui/react' ;
22import { FaClipboard , FaEye , FaFolder , FaLock , FaPen , FaQuestionCircle , FaTools , FaTrash , FaUnlock , FaUserPlus , FaUsers } from 'react-icons/fa' ;
3+ import { getIpHeaders , makeResObject , makeResponse , securityUtils } from '~/utils/functions.server' ;
34import { getAll , GrantedEntry , PermUser , ResourceType } from '@excali-boards/boards-api-client' ;
4- import { makeResObject , makeResponse , securityUtils } from '~/utils/functions.server' ;
55import { FetcherWithComponents , useFetcher , useLoaderData } from '@remix-run/react' ;
66import { firstToUpperCase , getGrantInfo , getRoleColor } from '~/other/utils' ;
77import { ActionFunctionArgs , LoaderFunctionArgs } from '@remix-run/node' ;
@@ -20,20 +20,23 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2020 if ( ! token ) throw makeResponse ( null , 'You are not authorized to view this page.' ) ;
2121 if ( ! api ) throw makeResponse ( null , 'API client not initialized.' ) ;
2222
23- const DBUsers = await getAll ( ( page , limit ) => api ! . admin . getUsers ( { auth : token , page, limit } ) ) ;
23+ const ipHeaders = getIpHeaders ( request ) ;
24+ if ( ! ipHeaders ) throw makeResponse ( null , 'Failed to get client IP.' ) ;
25+
26+ const DBUsers = await getAll ( ( page , limit ) => api ! . admin . getUsers ( { auth : token , page, limit, headers : ipHeaders } ) ) ;
2427 if ( ! DBUsers || 'error' in DBUsers ) throw makeResponse ( DBUsers , 'Failed to get users.' ) ;
2528
2629 const userIds = DBUsers . data . data . map ( ( user ) => user . userId ) ;
27- const allPermissions = await api ?. permissions . viewAllPermissions ( { auth : token , userIds } ) ;
28- if ( ! allPermissions || 'error' in allPermissions ) throw makeResponse ( allPermissions , 'Failed to get user permissions.' ) ;
30+ const DBAllPermissions = await api ?. permissions . viewAllPermissions ( { auth : token , userIds, headers : ipHeaders } ) ;
31+ if ( ! DBAllPermissions || 'error' in DBAllPermissions ) throw makeResponse ( DBAllPermissions , 'Failed to get user permissions.' ) ;
2932
3033 const findInviter = ( invitedByUserId : string | null ) => {
3134 if ( ! invitedByUserId ) return null ;
3235 return DBUsers . data . data . find ( ( u ) => u . userId === invitedByUserId ) || null ;
3336 } ;
3437
3538 return {
36- userPermissions : allPermissions . data ,
39+ userPermissions : DBAllPermissions . data ,
3740 allUsers : DBUsers . data . data . map ( ( user ) => {
3841 const inviter = findInviter ( user . invitedBy ) ;
3942 return {
@@ -61,6 +64,9 @@ export const action = async ({ request }: ActionFunctionArgs) => {
6164 const formData = await request . formData ( ) ;
6265 const type = formData . get ( 'type' ) as string ;
6366
67+ const ipHeaders = getIpHeaders ( request ) ;
68+ if ( ! ipHeaders ) return makeResObject ( null , 'Failed to get client IP.' ) ;
69+
6470 switch ( type ) {
6571 case 'revokePermission' : {
6672 const userId = formData . get ( 'userId' ) as string ;
@@ -72,7 +78,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
7278 }
7379
7480 const result = await api ?. permissions . revokePermissions ( {
75- auth : token ,
81+ auth : token , headers : ipHeaders ,
7682 body : { userId, resourceType : resourceType as ResourceType , resourceId } ,
7783 } ) ;
7884
@@ -85,7 +91,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
8591 if ( ! userId || ! newUsername ) return { status : 400 , error : 'Missing required fields.' } ;
8692
8793 const result = await api ?. users . updateUser ( {
88- auth : token , userId,
94+ auth : token , userId, headers : ipHeaders ,
8995 body : { displayName : newUsername } ,
9096 } ) ;
9197
@@ -95,7 +101,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
95101 const userId = formData . get ( 'userId' ) as string ;
96102 if ( ! userId ) return { status : 400 , error : 'Invalid user id.' } ;
97103
98- const result = await api ?. users . deleteAccount ( { auth : token , userId } ) ;
104+ const result = await api ?. users . deleteAccount ( { auth : token , userId, headers : ipHeaders } ) ;
99105 return makeResObject ( result , 'Failed to delete user.' ) ;
100106 }
101107 default : {
0 commit comments