Skip to content

Commit

Permalink
Merge pull request #967 from Giveth/feature_donation_csv_export
Browse files Browse the repository at this point in the history
Feature donation csv export
  • Loading branch information
CarlosQ96 authored Apr 25, 2023
2 parents 430a328 + 01e9a8e commit 1d3089d
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 56 deletions.
42 changes: 41 additions & 1 deletion src/server/adminJs/adminJs-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ export interface AdminJsProjectsQuery {
reviewStatus: ReviewStatus;
}

export interface AdminJsDonationsQuery {
projectId?: string;
contactEmail?: string;
referrerWallet?: string;
userId?: string;
fromWalletAddress?: string;
toWalletAddress?: string;
status?: string;
createdAt?: string;
currency?: string;
transactionNetworkId?: string;
isProjectVerified?: string;
}

// headers defined by the verification team for exporting
export const headers = [
export const projectHeaders = [
'id',
'title',
'slug',
Expand All @@ -54,3 +68,29 @@ export const headers = [
'secondWalletAddress',
'secondWalletAddressNetwork',
];

export const donationHeaders = [
'id',
'transactionId',
'transactionNetworkId',
'isProjectVerified',
'status',
'toWalletAddress',
'fromWalletAddress',
'tokenAddress',
'currency',
'anonymous',
'amount',
'isFiat',
'isCustomToken',
'valueEth',
'valueUsd',
'priceEth',
'priceUsd',
'projectId',
'userId',
'contactEmail',
'createdAt',
'referrerWallet',
'isTokenEligibleForGivback',
];
19 changes: 12 additions & 7 deletions src/server/adminJs/adminJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,29 @@ export const getAdminJsRouter = async () => {
// Express Middleware to save query of a search
export const adminJsQueryCache = async (req, res, next) => {
if (
req.url.startsWith('/admin/api/resources/Project/actions/list') &&
req.headers.cookie.includes('adminjs')
req.url.startsWith('/admin/api/resources/') &&
req.headers.cookie.includes('adminbro')
) {
const admin = await getCurrentAdminJsSession(req);
if (!admin) return next(); // skip saving queries

const matches = req.url.match(/\/admin\/api\/resources\/(.+?)(\/|$)/);
if (!matches) return next(); // invalid URL

const resourceName = matches[1];
const queryStrings = {};
// get URL query strings

// Extract filter names and values from URL query string parameters
for (const key of Object.keys(req.query)) {
const [_, filter] = key.split('.');
if (!filter) continue;

queryStrings[filter] = req.query[key];
}
// save query string for later use with an expiration
await redis.set(
`adminjs_${admin.id}_qs`,
JSON.stringify(queryStrings),
// Save query strings to Redis hash with an expiration
await redis.hset(
`adminbro:${admin.id}:${resourceName}`,
queryStrings,
'ex',
1800,
);
Expand Down
3 changes: 3 additions & 0 deletions src/server/adminJs/adminJsPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,15 @@ const donationPermissions = {
new: true,
show: true,
edit: true,
exportFilterToCsv: true,
},
[UserRole.OPERATOR]: {
show: true,
exportFilterToCsv: true,
},
[UserRole.VERIFICATION_FORM_REVIEWER]: {
show: true,
exportFilterToCsv: true,
},
[UserRole.CAMPAIGN_MANAGER]: {
show: true,
Expand Down
Loading

0 comments on commit 1d3089d

Please sign in to comment.