Let admins add and edit posts to any group (#820)
- show add post UI to admins - change firebase permissions
This commit is contained in:
parent
149204f6ca
commit
d06b725f52
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <p className="text-center">No post has been created </p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-md bg-white p-4">
|
||||
{isCreator || isAdmin ? (
|
||||
{isEditable ? (
|
||||
<RichEditGroupAboutPost group={group} post={post} />
|
||||
) : (
|
||||
<Content content={post.content} />
|
||||
|
|
|
@ -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 = (
|
||||
<Col>
|
||||
{group.aboutPostId != null || isCreator ? (
|
||||
{(group.aboutPostId != null || isCreator || isAdmin) && (
|
||||
<GroupAboutPost
|
||||
group={group}
|
||||
isCreator={!!isCreator}
|
||||
isEditable={!!isCreator || isAdmin}
|
||||
post={aboutPost}
|
||||
/>
|
||||
) : (
|
||||
<div></div>
|
||||
)}
|
||||
<Spacer h={3} />
|
||||
<GroupOverview
|
||||
|
|
Loading…
Reference in New Issue
Block a user