diff --git a/firestore.rules b/firestore.rules index 7b263e1a..e42e3ed7 100644 --- a/firestore.rules +++ b/firestore.rules @@ -162,7 +162,7 @@ service cloud.firestore { match /groups/{groupId} { allow read; - allow update: if request.auth.uid == resource.data.creatorId + allow update: if (request.auth.uid == resource.data.creatorId || isAdmin()) && request.resource.data.diff(resource.data) .affectedKeys() .hasOnly(['name', 'about', 'contractIds', 'memberIds', 'anyoneCanJoin', 'aboutPostId' ]); @@ -183,11 +183,11 @@ service cloud.firestore { match /posts/{postId} { allow read; - allow update: if request.auth.uid == resource.data.creatorId + allow update: if isAdmin() || request.auth.uid == resource.data.creatorId && request.resource.data.diff(resource.data) .affectedKeys() .hasOnly(['name', 'content']); - allow delete: if request.auth.uid == resource.data.creatorId; + allow delete: if isAdmin() || request.auth.uid == resource.data.creatorId; } } } diff --git a/web/components/groups/group-about-post.tsx b/web/components/groups/group-about-post.tsx index 1b42c04d..ed5c20cc 100644 --- a/web/components/groups/group-about-post.tsx +++ b/web/components/groups/group-about-post.tsx @@ -1,4 +1,3 @@ -import { useAdmin } from 'web/hooks/use-admin' import { Row } from '../layout/row' import { Content } from '../editor' import { TextEditor, useTextEditor } from 'web/components/editor' @@ -16,20 +15,15 @@ import { usePost } from 'web/hooks/use-post' export function GroupAboutPost(props: { group: Group - isCreator: boolean + isEditable: boolean post: Post }) { - const { group, isCreator } = props + const { group, isEditable } = props const post = usePost(group.aboutPostId) ?? props.post - const isAdmin = useAdmin() - - if (group.aboutPostId == null && !isCreator) { - return

No post has been created

- } return (
- {isCreator || isAdmin ? ( + {isEditable ? ( ) : ( diff --git a/web/pages/group/[...slugs]/index.tsx b/web/pages/group/[...slugs]/index.tsx index 5c22dbb6..4b391b36 100644 --- a/web/pages/group/[...slugs]/index.tsx +++ b/web/pages/group/[...slugs]/index.tsx @@ -50,6 +50,7 @@ import { getPost } from 'web/lib/firebase/posts' import { Post } from 'common/post' import { Spacer } from 'web/components/layout/spacer' import { usePost } from 'web/hooks/use-post' +import { useAdmin } from 'web/hooks/use-admin' export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz(props: { params: { slugs: string[] } }) { @@ -158,6 +159,7 @@ export default function GroupPage(props: { const aboutPost = usePost(props.aboutPost?.id) ?? props.aboutPost const user = useUser() + const isAdmin = useAdmin() useSaveReferral(user, { defaultReferrerUsername: creator.username, @@ -186,14 +188,12 @@ export default function GroupPage(props: { const aboutTab = ( - {group.aboutPostId != null || isCreator ? ( + {(group.aboutPostId != null || isCreator || isAdmin) && ( - ) : ( -
)}