Skip to content

Commit

Permalink
Manage the case of a Document without download permissions (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
luorlandini authored Oct 13, 2021
1 parent eededb1 commit e1348e7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Message from '@mapstore/framework/components/I18N/Message';
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
import moment from 'moment';
import { getUserName } from '@js/utils/SearchUtils';
import { getResourceTypesInfo } from '@js/utils/ResourceUtils';
import { getResourceTypesInfo, getMetadataDetailUrl } from '@js/utils/ResourceUtils';
import debounce from 'lodash/debounce';
import CopyToClipboardCmp from 'react-copy-to-clipboard';
import { TextEditable, ThumbnailEditable } from '@js/components/ContentsEditable/';
Expand Down Expand Up @@ -118,7 +118,6 @@ const DefinitionListMoreItem = ({itemslist, extraItemsList}) => {
);
};


function DetailsPanel({
resource,
formatHref,
Expand Down Expand Up @@ -167,13 +166,16 @@ function DetailsPanel({
const {
formatEmbedUrl = res => res?.embed_url,
formatDetailUrl = res => res?.detail_url,
canPreviewed,
icon,
name
} = resource && (types[resource.subtype] || types[resource.resource_type]) || {};
const embedUrl = resource?.embed_url && formatEmbedUrl(resource);
const detailUrl = resource?.pk && formatDetailUrl(resource);
const resourceCanPreviewed = resource?.pk && canPreviewed && canPreviewed(resource);
const documentDownloadUrl = (resource?.href && resource?.href.includes('download')) ? resource?.href : undefined;
const attributeSet = resource?.attribute_set;
const metadataDetailUrl = resource?.pk && getMetadataDetailUrl(resource);

const validateDataType = (data) => {

Expand All @@ -191,7 +193,6 @@ function DetailsPanel({
return dataType;
};


const infoField = [
{
"label": "Title",
Expand Down Expand Up @@ -355,7 +356,7 @@ function DetailsPanel({
</Button>
</div>
}
{!activeEditMode && !editThumbnail && <div className="gn-details-panel-preview">
{resourceCanPreviewed && !activeEditMode && !editThumbnail && <div className="gn-details-panel-preview">
<div
className="gn-loader-placeholder"
style={{
Expand Down Expand Up @@ -463,9 +464,9 @@ function DetailsPanel({
}
{detailUrl && !editThumbnail && <Button
variant="default"
href={detailUrl}
href={(resourceCanPreviewed) ? detailUrl : metadataDetailUrl}
rel="noopener noreferrer">
<Message msgId={`gnhome.view${name || ''}`} />
<Message msgId={`gnhome.view${((resourceCanPreviewed) ? name : 'Metadata')}`} />
</Button>}
</div>
}
Expand Down
15 changes: 9 additions & 6 deletions geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export function getGeoLimitsFromCompactPermissions({ groups = [], users = [], or
return entries;
}

export const resourseHasPermission = (resource, perm) => {
return resource?.perms?.includes(perm);
};


export const ResourceTypes = {
DATASET: 'dataset',
MAP: 'map',
Expand All @@ -191,6 +196,7 @@ export const ResourceTypes = {
export const getResourceTypesInfo = () => ({
[ResourceTypes.DATASET]: {
icon: 'database',
canPreviewed: (resource) => resourseHasPermission(resource, 'view_resourcebase'),
formatEmbedUrl: (resource) => parseDevHostname(updateUrlQueryParameter(resource.embed_url, {
config: 'dataset_preview'
})),
Expand All @@ -201,6 +207,7 @@ export const getResourceTypesInfo = () => ({
[ResourceTypes.MAP]: {
icon: 'map',
name: 'Map',
canPreviewed: (resource) => resourseHasPermission(resource, 'view_resourcebase'),
formatEmbedUrl: (resource) => parseDevHostname(updateUrlQueryParameter(resource.embed_url, {
config: 'map_preview'
})),
Expand All @@ -210,13 +217,15 @@ export const getResourceTypesInfo = () => ({
[ResourceTypes.DOCUMENT]: {
icon: 'file',
name: 'Document',
canPreviewed: (resource) => resourseHasPermission(resource, 'download_resourcebase'),
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => resource?.detail_url && parseDevHostname(resource.detail_url),
formatMetadataUrl: (resource) => (`/documents/${resource.pk}/metadata`)
},
[ResourceTypes.GEOSTORY]: {
icon: 'book',
name: 'GeoStory',
canPreviewed: (resource) => resourseHasPermission(resource, 'view_resourcebase'),
formatEmbedUrl: (resource) => resource?.embed_url && parseDevHostname(resource.embed_url),
formatDetailUrl: (resource) => resource?.detail_url && parseDevHostname(resource.detail_url),
formatMetadataUrl: (resource) => (`/apps/${resource.pk}/metadata`)
Expand All @@ -238,16 +247,10 @@ export const getMetadataUrl = (resource) => {
return '';
};


export const getMetadataDetailUrl = (resource) => {
return (getMetadataUrl(resource)) ? getMetadataUrl(resource) + '_detail' : '';
};

export const resourseHasPermission = (resource, perm) => {
return resource?.perms?.includes(perm);
};


export const getResourceStatuses = (resource) => {
const { processes } = resource || {};
const isProcessing = processes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"viewImage": "Bild ansehen",
"viewVideo": "Video ansehen",
"viewDashboard": "Dashboard ansehen",
"viewMetadata": "Metadaten ansehen",
"author": "Autor",
"publication": "Veröffentlichung",
"creation": "Erstellungsdatum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"viewImage": "View image",
"viewVideo": "View video",
"viewDashboard": "View dashboard",
"viewMetadata": "View metadata",
"author": "Author",
"publication": "Publication",
"creation": "Creation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"viewImage": "Ver imágenes",
"viewVideo": "Ver video",
"viewDashboard": "Ver dashboard",
"viewMetadata": "Voir metadatos",
"author": "Autor",
"publication": "Publicación",
"creation": "Creación",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"viewImage": "Voir images",
"viewVideo": "Voir video",
"viewDashboard": "Voir dashboard",
"viewMetadata": "Voir métadonnées",
"author": "Auteur",
"publication": "Publication",
"creation": "Création",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"viewImage": "Visualizza immagine",
"viewVideo": "Visualizza video",
"viewDashboard": "Visualizza dashboard",
"viewMetadata": "Visualizza metadati",
"author": "Autore",
"publication": "Pubblicazione",
"creation": "Creazione",
Expand Down

0 comments on commit e1348e7

Please sign in to comment.