Skip to content

Commit

Permalink
fix: add permissions checks on project inputs screen (#1854)
Browse files Browse the repository at this point in the history
* fix: hide add depth button from non-managers

* fix: hide required depth settings from non-managers

* chore: update snapshots
  • Loading branch information
paulschreiber authored Jul 29, 2024
1 parent 7975b37 commit 4d3ac31
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2259,94 +2259,6 @@ exports[`renders correctly 1`] = `
}
}
/>
<View
style={{}}
>
<View
style={
[
{
"flexDirection": "row",
},
{
"alignItems": "center",
"backgroundColor": "#00582B",
"justifyContent": "space-between",
"paddingHorizontal": 16,
},
]
}
>
<Text
letterSpacing="0.15px"
lineHeight="24px"
style={
{
"color": "#FFFFFF",
"fontSize": 16,
"fontWeight": "400",
"paddingBottom": 12,
"paddingTop": 12,
}
}
>
Data Collection Requirements
</Text>
<View
accessibilityRole="button"
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
colorScheme="primary"
dataSet={{}}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"alignItems": "center",
"borderRadius": 4,
"flexDirection": "row",
"justifyContent": "center",
"paddingBottom": 4,
"paddingLeft": 4,
"paddingRight": 4,
"paddingTop": 4,
}
}
>
<Icon
color="#FFFFFF"
name="expand-more"
size={24}
style={{}}
/>
</View>
</View>
</View>
</View>
</RCTScrollView>
</View>
Expand Down
21 changes: 13 additions & 8 deletions dev-client/src/screens/ProjectInputScreen/ProjectInputScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ export const ProjectInputScreen = ({
<SoilPitSettings projectId={projectId} />
</Accordion>
<Box height={4} />
<Accordion
Head={
<Text pt={3} pb={3} fontSize="md" color="primary.contrast">
{t('soil.project_settings.required_data_title')}
</Text>
}>
<RequiredDataSettings projectId={projectId} enabled={allowEditing} />
</Accordion>
<RestrictByProjectRole role="MANAGER">
<Accordion
Head={
<Text pt={3} pb={3} fontSize="md" color="primary.contrast">
{t('soil.project_settings.required_data_title')}
</Text>
}>
<RequiredDataSettings
projectId={projectId}
enabled={allowEditing}
/>
</Accordion>
</RestrictByProjectRole>
</ScrollView>
<RestrictByProjectRole role="MANAGER">
<Fab
Expand Down
41 changes: 23 additions & 18 deletions dev-client/src/screens/ProjectInputScreen/SoilPitSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
Box,
Heading,
} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {RestrictByProjectRole} from 'terraso-mobile-client/components/RestrictByRole';
import {useProjectRoleContext} from 'terraso-mobile-client/context/ProjectRoleContext';
import {DepthTable} from 'terraso-mobile-client/screens/ProjectInputScreen/DepthTable';
import {useDispatch} from 'terraso-mobile-client/store';
Expand Down Expand Up @@ -124,24 +125,28 @@ export const SoilPitSettings = ({projectId}: {projectId: string}) => {
/>
)}
{isCustom && (
<Modal
trigger={onOpen => (
<Button
onPress={onOpen}
alignSelf="flex-start"
backgroundColor="primary.main"
shadow={5}
_text={{textTransform: 'uppercase'}}
leftIcon={<Icon name="add" />}>
{t('soil.add_depth_label')}
</Button>
)}
Header={<Heading variant="h6">{t('soil.depth.add_title')}</Heading>}>
<AddDepthModalBody
onSubmit={onAddDepth}
existingDepths={settings.depthIntervals}
/>
</Modal>
<RestrictByProjectRole role="MANAGER">
<Modal
trigger={onOpen => (
<Button
onPress={onOpen}
alignSelf="flex-start"
backgroundColor="primary.main"
shadow={5}
_text={{textTransform: 'uppercase'}}
leftIcon={<Icon name="add" />}>
{t('soil.add_depth_label')}
</Button>
)}
Header={
<Heading variant="h6">{t('soil.depth.add_title')}</Heading>
}>
<AddDepthModalBody
onSubmit={onAddDepth}
existingDepths={settings.depthIntervals}
/>
</Modal>
</RestrictByProjectRole>
)}
</Box>
);
Expand Down

0 comments on commit 4d3ac31

Please sign in to comment.