Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const Popup = dynamic(() => import('react-map-gl').then(mod => mod.Popup), {
ssr: false,
});

type Props = Pick<PostFilesProps, 'files' | 'mapboxToken' | 'isAdmin'> & {
type Props = Pick<
PostFilesProps,
'files' | 'mapboxToken' | 'canViewPrivatePost'
> & {
privateFiles: boolean;
privateLocations: boolean;
filesPreviews: FilesPreviews;
Expand All @@ -58,7 +61,7 @@ type Props = Pick<PostFilesProps, 'files' | 'mapboxToken' | 'isAdmin'> & {
const PostFilesPublic = ({
files,
mapboxToken,
isAdmin,
canViewPrivatePost,
privateFiles,
privateLocations,
filesPreviews,
Expand Down Expand Up @@ -291,7 +294,7 @@ const PostFilesPublic = ({
canDownloadFiles={canDownloadFiles}
/>
)}
{isAdmin && (privateLocations || privateFiles) && (
{canViewPrivatePost && (privateLocations || privateFiles) && (
<Tag
className="top-20 left-20 sm:left-[110px] absolute bg-error-300"
icon={<LockIcon width="18" height="18" />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Public.args = {
mapboxToken: import.meta.env.STORYBOOK_MAPBOX_TOKEN,
files,
photoCredit: 'Photo credit',
canViewPrivatePost: false,
readMoreText,
};

Expand All @@ -32,6 +33,7 @@ PrivateLocations.args = {
privacyType: 'private_locations',
mapboxToken: import.meta.env.STORYBOOK_MAPBOX_TOKEN,
files: [],
canViewPrivatePost: false,
readMoreText,
};

Expand All @@ -43,6 +45,7 @@ PrivateFiles.args = {
privacyType: 'private_files',
mapboxToken: import.meta.env.STORYBOOK_MAPBOX_TOKEN,
files: [],
canViewPrivatePost: false,
readMoreText,
};

Expand All @@ -54,7 +57,7 @@ PrivateLocationsAsAdmin.args = {
privacyType: 'private_locations',
mapboxToken: import.meta.env.STORYBOOK_MAPBOX_TOKEN,
files: [],
isAdmin: true,
canViewPrivatePost: true,
readMoreText,
};

Expand All @@ -66,6 +69,6 @@ PrivateFilesAsAdmin.args = {
privacyType: 'private_files',
mapboxToken: import.meta.env.STORYBOOK_MAPBOX_TOKEN,
files: [],
isAdmin: true,
canViewPrivatePost: true,
readMoreText,
};
14 changes: 7 additions & 7 deletions web-components/src/components/organisms/PostFiles/PostFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type PostFilesProps = {
privacyType: PostPrivacyType;
files: Array<PostFile>;
mapboxToken?: string;
isAdmin: boolean;
canViewPrivatePost: boolean;
hasToken?: boolean;
photoCredit: string;
adminPrivateLabel: string;
Expand All @@ -37,7 +37,7 @@ const PostFiles = ({
privacyType,
files,
mapboxToken,
isAdmin = false,
canViewPrivatePost,
hasToken = false,
photoCredit,
adminPrivateLabel,
Expand Down Expand Up @@ -73,31 +73,31 @@ const PostFiles = ({
<div
className={cn(
'w-[100%]',
(isPublic || privateLocations || isAdmin) && 'lg:h-[550px]',
(isPublic || privateLocations || canViewPrivatePost) && 'lg:h-[550px]',
)}
>
{(isPublic || isAdmin || hasToken) && (
{(isPublic || hasToken) && (
<PostFilesPublic
files={files}
filesPreviews={filesPreviews}
mapboxToken={mapboxToken}
isAdmin={isAdmin}
canViewPrivatePost={canViewPrivatePost}
privateLocations={privateLocations}
privateFiles={privateFiles}
adminPrivateLabel={adminPrivateLabel}
readMoreText={readMoreText}
canDownloadFiles={canDownloadFiles}
/>
)}
{!isAdmin && !hasToken && privateLocations && (
{!canViewPrivatePost && !hasToken && privateLocations && (
<PostFilesPrivateLocations
photoCredit={photoCredit}
files={files}
filesPreviews={filesPreviews}
label={privateLocationsLabel}
/>
)}
{!isAdmin && !hasToken && privateFiles && (
{!canViewPrivatePost && !hasToken && privateFiles && (
<PostFilesPrivateFiles label={privateFilesLabel} />
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ROLE_EDITOR_LABEL = msg`Editor`;
export const ROLE_EDITOR_DESCRIPTION = msg`Can edit all project page info and posts. Cannot manage users or credits.`;

export const ROLE_AUTHOR_LABEL = msg`Author`;
export const ROLE_AUTHOR_DESCRIPTION = msg`Can create, edit, and delete data posts.`;
export const ROLE_AUTHOR_DESCRIPTION = msg`Can create, edit, and delete their own data posts. Cannot see private post data.`;

export const ROLE_VIEWER_LABEL = msg`Viewer`;
export const ROLE_VIEWER_DESCRIPTION = msg`Can view all posts, documents, and location data, even when private.`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import {
ApolloClient,
NormalizedCacheObject,
Expand Down Expand Up @@ -49,15 +49,21 @@ import copyTextToClipboard from 'web-components/src/utils/copy';

import { bannerTextAtom } from 'lib/atoms/banner.atoms';
import { selectedLanguageAtom } from 'lib/atoms/languageSwitcher.atoms';
import { useAuth } from 'lib/auth/auth';
import { COPY_SUCCESS } from 'lib/constants/shared.constants';
import { LINK_PREFIX } from 'lib/env';
import { Post } from 'lib/queries/react-query/registry-server/getPostQuery/getPostQuery.types';
import { getAccountByIdQuery } from 'lib/queries/react-query/registry-server/graphql/getAccountByIdQuery/getAccountByIdQuery';

import { Link } from 'components/atoms';
import { ProjectRole } from 'components/organisms/BaseMembersTable/BaseMembersTable.types';
import { DeletePostWarningModal } from 'components/organisms/DeletePostWarningModal/DeletePostWarningModal';
import { PostFormSchemaType } from 'components/organisms/PostForm/PostForm.schema';

import {
getCanSeeOrManagePost,
getCanViewPrivatePost,
} from '../ProjectFormTemplate/ProjectFormAccessTemplate.utils';
import {
FILES_ARE_PRIVATE,
LOCATIONS_ARE_PRIVATE,
Expand All @@ -74,8 +80,7 @@ type Props = {
setDraftPost: UseStateSetter<Partial<PostFormSchemaType> | undefined>;
projectLocation: GeocodeFeature;
openCreatePostModal: () => void;
canManagePost: boolean;
canViewPost: boolean;
role?: ProjectRole;
};
export const DataStreamPost = ({
offChainProjectId,
Expand All @@ -87,8 +92,7 @@ export const DataStreamPost = ({
setDraftPost,
projectLocation,
openCreatePostModal,
canManagePost,
canViewPost,
role,
}: Props) => {
const { _ } = useLingui();
const [selectedLanguage] = useAtom(selectedLanguageAtom);
Expand All @@ -104,18 +108,39 @@ export const DataStreamPost = ({
iri,
offChainProjectId,
});
const { activeAccountId: currentAccountId } = useAuth();

const creatorAccountId = post.creatorAccountId;
const { data: creatorAccountData } = useQuery(
getAccountByIdQuery({
client: graphqlClient,
id: post.creatorAccountId,
id: creatorAccountId,
enabled: !!graphqlClient,
languageCode: selectedLanguage,
}),
);
const creatorAccount = creatorAccountData?.accountById;
const creatorIsAdmin = creatorAccount?.id === adminAccountId;

const canManagePost = useMemo(
() =>
getCanSeeOrManagePost({
role,
creatorAccountId,
currentAccountId,
}),
[role, creatorAccountId, currentAccountId],
);
const canViewPost = useMemo(
() =>
getCanViewPrivatePost({
role,
creatorAccountId,
currentAccountId,
}),
[role, creatorAccountId, currentAccountId],
);

const { events } = useAttestEvents({
iri,
createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { DATA_STREAM_LIMIT } from 'lib/queries/react-query/registry-server/getPo
import { PostsQueryResponse } from 'lib/queries/react-query/registry-server/getPostsQuery/getPostsQuery.types';
import { getPostsQueryKey } from 'lib/queries/react-query/registry-server/getPostsQuery/getPostsQuery.utils';

import { ProjectRole } from 'components/organisms/BaseMembersTable/BaseMembersTable.types';
import { PostFormSchemaType } from 'components/organisms/PostForm/PostForm.schema';
import { useHash } from 'hooks/useHash';

Expand All @@ -48,8 +49,8 @@ type Props = {
projectLocation?: GeocodeFeature;
openCreatePostModal: () => void;
setDraftPost: UseStateSetter<Partial<PostFormSchemaType> | undefined>;
canManagePost: boolean;
canViewPost: boolean;
role?: ProjectRole;
canCreatePost: boolean;
};

export const DataStream = ({
Expand All @@ -60,8 +61,8 @@ export const DataStream = ({
projectLocation,
openCreatePostModal,
setDraftPost,
canManagePost,
canViewPost,
role,
canCreatePost,
}: Props) => {
const { _ } = useLingui();
const [selectedLanguage] = useAtom(selectedLanguageAtom);
Expand Down Expand Up @@ -110,7 +111,7 @@ export const DataStream = ({
titleAlign="left"
className="mb-50 sm:mb-[100px] pt-0"
>
{canManagePost && adminDescription && projectLocation && (
{canCreatePost && adminDescription && projectLocation && (
<div className="mt-15">
<Body className="mb-15 max-w-[683px]" size="lg" component="div">
<BlockContent content={adminDescription} />
Expand Down Expand Up @@ -157,14 +158,13 @@ export const DataStream = ({
post={post}
index={i}
postsLength={posts.length}
canManagePost={canManagePost}
adminAccountId={adminAccountId}
offChainProjectId={offChainProjectId}
adminAddr={adminAddr}
setDraftPost={setDraftPost}
projectLocation={projectLocation}
openCreatePostModal={openCreatePostModal}
canViewPost={canViewPost}
role={role}
/>
))}
</Timeline>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ import { ProjectStorySection } from 'components/organisms/ProjectStorySection/Pr
import { SellOrdersActionsBar } from 'components/organisms/SellOrdersActionsBar/SellOrdersActionsBar';
import { AVG_PRICE_TOOLTIP_PROJECT } from 'components/organisms/SellOrdersActionsBar/SellOrdersActionsBar.constants';
import {
getCanCreatePost,
getCanEditProject,
getCanManagePost,
getCanViewPost,
getCanSeeOrManagePost,
getCanViewPrivatePost,
} from 'components/templates/ProjectFormTemplate/ProjectFormAccessTemplate.utils';
import { useFetchPaginatedBatches } from 'hooks/batches/useFetchPaginatedBatches';
import { useOnBuyButtonClick } from 'hooks/useOnBuyButtonClick';
Expand Down Expand Up @@ -337,8 +338,9 @@ function ProjectDetails(): JSX.Element {
const { canEdit: canEditProject } = getCanEditProject({
role,
});
const canManagePost = getCanManagePost({ role });
const canViewPost = getCanViewPost({ role });
const canCreatePost = getCanCreatePost({
role,
});

// Fetch organization data if project belongs to an organization
const organizationId =
Expand Down Expand Up @@ -386,7 +388,7 @@ function ProjectDetails(): JSX.Element {
isCommunityCredit={isCommunityCredit}
onBookCallButtonClick={onBookCallButtonClick}
canEditProject={canEditProject}
canCreatePost={canManagePost}
canCreatePost={canCreatePost}
onBuyButtonClick={() => {
onBuyButtonClick({
projectId,
Expand Down Expand Up @@ -516,8 +518,8 @@ function ProjectDetails(): JSX.Element {
projectLocation={projectLocation}
openCreatePostModal={openCreatePostModal}
setDraftPost={setDraftPost}
canManagePost={canManagePost}
canViewPost={canViewPost}
role={role}
canCreatePost={canCreatePost}
/>

<ProjectDetailsTableTabs
Expand Down
Loading
Loading