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} {
|
match /groups/{groupId} {
|
||||||
allow read;
|
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)
|
&& request.resource.data.diff(resource.data)
|
||||||
.affectedKeys()
|
.affectedKeys()
|
||||||
.hasOnly(['name', 'about', 'contractIds', 'memberIds', 'anyoneCanJoin', 'aboutPostId' ]);
|
.hasOnly(['name', 'about', 'contractIds', 'memberIds', 'anyoneCanJoin', 'aboutPostId' ]);
|
||||||
|
@ -183,11 +183,11 @@ service cloud.firestore {
|
||||||
|
|
||||||
match /posts/{postId} {
|
match /posts/{postId} {
|
||||||
allow read;
|
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)
|
&& request.resource.data.diff(resource.data)
|
||||||
.affectedKeys()
|
.affectedKeys()
|
||||||
.hasOnly(['name', 'content']);
|
.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 { Row } from '../layout/row'
|
||||||
import { Content } from '../editor'
|
import { Content } from '../editor'
|
||||||
import { TextEditor, useTextEditor } from 'web/components/editor'
|
import { TextEditor, useTextEditor } from 'web/components/editor'
|
||||||
|
@ -16,20 +15,15 @@ import { usePost } from 'web/hooks/use-post'
|
||||||
|
|
||||||
export function GroupAboutPost(props: {
|
export function GroupAboutPost(props: {
|
||||||
group: Group
|
group: Group
|
||||||
isCreator: boolean
|
isEditable: boolean
|
||||||
post: Post
|
post: Post
|
||||||
}) {
|
}) {
|
||||||
const { group, isCreator } = props
|
const { group, isEditable } = props
|
||||||
const post = usePost(group.aboutPostId) ?? props.post
|
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 (
|
return (
|
||||||
<div className="rounded-md bg-white p-4">
|
<div className="rounded-md bg-white p-4">
|
||||||
{isCreator || isAdmin ? (
|
{isEditable ? (
|
||||||
<RichEditGroupAboutPost group={group} post={post} />
|
<RichEditGroupAboutPost group={group} post={post} />
|
||||||
) : (
|
) : (
|
||||||
<Content content={post.content} />
|
<Content content={post.content} />
|
||||||
|
|
|
@ -50,6 +50,7 @@ import { getPost } from 'web/lib/firebase/posts'
|
||||||
import { Post } from 'common/post'
|
import { Post } from 'common/post'
|
||||||
import { Spacer } from 'web/components/layout/spacer'
|
import { Spacer } from 'web/components/layout/spacer'
|
||||||
import { usePost } from 'web/hooks/use-post'
|
import { usePost } from 'web/hooks/use-post'
|
||||||
|
import { useAdmin } from 'web/hooks/use-admin'
|
||||||
|
|
||||||
export const getStaticProps = fromPropz(getStaticPropz)
|
export const getStaticProps = fromPropz(getStaticPropz)
|
||||||
export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
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 aboutPost = usePost(props.aboutPost?.id) ?? props.aboutPost
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
const isAdmin = useAdmin()
|
||||||
|
|
||||||
useSaveReferral(user, {
|
useSaveReferral(user, {
|
||||||
defaultReferrerUsername: creator.username,
|
defaultReferrerUsername: creator.username,
|
||||||
|
@ -186,14 +188,12 @@ export default function GroupPage(props: {
|
||||||
|
|
||||||
const aboutTab = (
|
const aboutTab = (
|
||||||
<Col>
|
<Col>
|
||||||
{group.aboutPostId != null || isCreator ? (
|
{(group.aboutPostId != null || isCreator || isAdmin) && (
|
||||||
<GroupAboutPost
|
<GroupAboutPost
|
||||||
group={group}
|
group={group}
|
||||||
isCreator={!!isCreator}
|
isEditable={!!isCreator || isAdmin}
|
||||||
post={aboutPost}
|
post={aboutPost}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<div></div>
|
|
||||||
)}
|
)}
|
||||||
<Spacer h={3} />
|
<Spacer h={3} />
|
||||||
<GroupOverview
|
<GroupOverview
|
||||||
|
|
Loading…
Reference in New Issue
Block a user