Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1955 | private repo versions without access…
Browse files Browse the repository at this point in the history
… are not selectable
  • Loading branch information
snyaggarwal committed Oct 30, 2024
1 parent 15d7e0d commit 55473f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ export const arrayToObject = arr => {
}, {});
}

export const currentUserHasAccess = () => {
export const currentUserHasAccess = () => hasAccessToURL(window.location.hash.replace('#/', ''))

export const hasAccessToURL = url => {
if(!isLoggedIn())
return false;
if(isAdminUser())
return true;

const url = window.location.hash.replace('#/', '');
if(!url)
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/components/repos/RepoSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CollapsedStatList = ({open, stat}) => {
<List dense component="div" sx={{padding: '0 16px'}}>
{
map(stat, value => (
<ListItemButton sx={{padding: '4px 0', fontSize: '12px'}}>
<ListItemButton key={value[0]} sx={{padding: '4px 0', fontSize: '12px'}}>
<ListItemText
primary={value[0]}
sx={{
Expand Down
20 changes: 11 additions & 9 deletions src/components/repos/VersionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,32 @@ import without from 'lodash/without'
import ConceptIcon from '../concepts/ConceptIcon'
import AccessIcon from '../common/AccessIcon'
import MappingIcon from '../mappings/MappingIcon';
import { formatDate } from '../../common/utils'
import { formatDate, hasAccessToURL } from '../../common/utils'
import { SURFACE_COLORS, BLACK } from '../../common/colors'
import Button from '../common/Button';

const Row = ({ version, disabled, checkbox, bodyCellStyle, onCheck, checked, onVersionChange, originVersion }) => {
const { t } = useTranslation()
const isPublic = ['view', 'edit'].includes(version.public_access.toLowerCase())
const tooltip = originVersion ? t('repo.compare_origin_version_disabled_tooltip') : t('repo.compare_destination_version_disabled_tooltip')
const isPrivateAndHasNoAccess = !isPublic && !hasAccessToURL(version.version_url || version.url)
const isDisabled = disabled || isPrivateAndHasNoAccess
return (
<Tooltip title={disabled ? tooltip : undefined} placement='right'>
<TableRow key={version.id} id={version.id} sx={{cursor: 'pointer'}} disabled={disabled}>
<TableRow key={version.id} id={version.id} sx={{cursor: isDisabled ? 'not-allowed' : 'pointer'}} disabled={isDisabled}>
{
checkbox &&
<TableCell padding="checkbox" sx={{...bodyCellStyle, borderTopLeftRadius: '50px', borderBottomLeftRadius: '50px'}} onClick={() => !disabled && onCheck(version)}>
<Checkbox color="primary" size='small' checked={!disabled && checked.includes(version.version_url)} onChange={() => onCheck(version)} disabled={disabled} />
<TableCell padding="checkbox" sx={{...bodyCellStyle, borderTopLeftRadius: '50px', borderBottomLeftRadius: '50px'}} onClick={() => !isDisabled && onCheck(version)}>
<Checkbox color="primary" size='small' checked={!isDisabled && checked.includes(version.version_url)} onChange={() => onCheck(version)} disabled={isDisabled} />
</TableCell>
}
<TableCell sx={{...bodyCellStyle, ...(checkbox ? {} : {borderTopLeftRadius: '50px', borderBottomLeftRadius: '50px'})}} onClick={() => onVersionChange(version)}>
<TableCell sx={{...bodyCellStyle, ...(checkbox ? {} : {borderTopLeftRadius: '50px', borderBottomLeftRadius: '50px'})}} onClick={isDisabled ? undefined : () => onVersionChange(version)}>
{version.id}
</TableCell>
<TableCell sx={{...bodyCellStyle}} onClick={() => onVersionChange(version)}>
<TableCell sx={{...bodyCellStyle}} onClick={isDisabled ? undefined : () => onVersionChange(version)}>
{moment(version.created_on).fromNow()}
</TableCell>
<TableCell sx={{...bodyCellStyle}} onClick={() => onVersionChange(version)}>
<TableCell sx={{...bodyCellStyle}} onClick={isDisabled ? undefined : () => onVersionChange(version)}>
<span style={{display: 'flex', alignItems: 'center'}}>
{
isNumber(version?.summary?.active_concepts) &&
Expand All @@ -58,12 +60,12 @@ const Row = ({ version, disabled, checkbox, bodyCellStyle, onCheck, checked, onV
}
</span>
</TableCell>
<TableCell sx={{...bodyCellStyle}} onClick={() => onVersionChange(version)}>
<TableCell sx={{...bodyCellStyle}} onClick={isDisabled ? undefined : () => onVersionChange(version)}>
<span style={{display: 'flex', alignItems: 'center'}}>
<AccessIcon sx={{width: '17px', height: '17px', marginRight: '4px'}} public_access={version.public_access} /> {isPublic ? t('common.public') : t('common.private')}
</span>
</TableCell>
<TableCell sx={{...bodyCellStyle, borderTopRightRadius: '50px', borderBottomRightRadius: '50px'}} onClick={() => onVersionChange(version)}>
<TableCell sx={{...bodyCellStyle, borderTopRightRadius: '50px', borderBottomRightRadius: '50px'}} onClick={isDisabled ? undefined : () => onVersionChange(version)}>
{
version.id === 'HEAD' &&
<span style={{display: 'flex', alignItems: 'center'}}>
Expand Down

0 comments on commit 55473f1

Please sign in to comment.