Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin access to the campaign expneses #1400

Merged
merged 14 commits into from
Mar 29, 2023
Merged
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
4 changes: 3 additions & 1 deletion src/common/hooks/campaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { DonationStatus } from 'gql/donations.enums'
import { apiClient } from 'service/apiClient'
import { useCurrentPerson } from 'common/util/useCurrentPerson'
import { isAdmin } from 'common/util/roles'

// NOTE: shuffling the campaigns so that each gets its fair chance to be on top row
export const campaignsOrderQueryFunction: QueryFunction<CampaignResponse[]> = async ({
Expand Down Expand Up @@ -128,7 +129,8 @@ export function useCanEditCampaign(slug: string) {

const canEdit =
userData.user.id === campaignData.campaign.organizer?.person.id ||
session?.user?.realm_access?.roles?.includes('podkrepi-admin')
session?.user?.realm_access?.roles?.includes('podkrepi-admin') ||
isAdmin(session)

return canEdit
}
4 changes: 3 additions & 1 deletion src/components/client/campaign-expenses/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { downloadCampaignExpenseFile, deleteExpenseFile } from 'service/expense'
import { useSession } from 'next-auth/react'
import DeleteForeverIcon from '@mui/icons-material/DeleteForever'
import { useViewPersonByKeylockId } from 'common/hooks/person'
import { isAdmin } from 'common/util/roles'

const validTypes = Object.keys(ExpenseType)
const validStatuses = Object.keys(ExpenseStatus)
Expand All @@ -53,7 +54,8 @@ export default function Form() {
const { data: expenseFiles } = useCampaignExpenseFiles(id)
const { data: session } = useSession()

const canApprove = !!session?.user?.realm_access?.roles?.includes('podkrepi-admin')
const canApprove =
!!session?.user?.realm_access?.roles?.includes('podkrepi-admin') || isAdmin(session)

const { data: person } = useViewPersonByKeylockId(session?.user?.sub as string)

Expand Down