Skip to content

Commit

Permalink
Merge pull request #1022 from Giveth/f_1021_refresh_materialized_view…
Browse files Browse the repository at this point in the history
…s_when_editing_qf_rounds

Refresh materialized views after any changes on qfRounds by admin panel
  • Loading branch information
mohammadranjbarz authored Jun 13, 2023
2 parents 0ad2462 + 6bad577 commit 1293e28
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/server/adminJs/tabs/qfRoundTab.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { QfRound } from '../../../entities/qfRound';
import { canAccessQfRoundAction, ResourceActions } from '../adminJsPermissions';
import {
canAccessQfRoundAction,
canAccessUserAction,
ResourceActions,
} from '../adminJsPermissions';
ActionResponse,
After,
} from 'adminjs/src/backend/actions/action.interface';
import {
refreshProjectDonationSummaryView,
refreshProjectEstimatedMatchingView,
} from '../../../services/projectViewsService';

export const refreshMaterializedViews = async (
response,
): Promise<After<ActionResponse>> => {
await refreshProjectEstimatedMatchingView();
await refreshProjectDonationSummaryView();
return response;
};

export const qfRoundTab = {
resource: QfRound,
Expand Down Expand Up @@ -54,29 +66,25 @@ export const qfRoundTab = {
},
},
},
// TODO should call below expression after any changes on qfRounds
// if (!isTestEnv) {
// // They will fail in test env, because we run migrations after bootstrap so refreshing them will cause this error
// // relation "project_estimated_matching_view" does not exist
// await refreshProjectEstimatedMatchingView();
// await refreshProjectDonationSummaryView();
// }
actions: {
delete: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessQfRoundAction({ currentAdmin }, ResourceActions.DELETE),
after: refreshMaterializedViews,
},
bulkDelete: {
isVisible: false,
},
new: {
isAccessible: ({ currentAdmin }) =>
canAccessQfRoundAction({ currentAdmin }, ResourceActions.NEW),
after: refreshMaterializedViews,
},
edit: {
isAccessible: ({ currentAdmin }) =>
canAccessQfRoundAction({ currentAdmin }, ResourceActions.EDIT),
after: refreshMaterializedViews,
},
},
},
Expand Down

0 comments on commit 1293e28

Please sign in to comment.