Skip to content

Commit

Permalink
donation V2 touchup
Browse files Browse the repository at this point in the history
- better search
- better tests
- better serialization
- anybody on the donation socket is required to have view bid permission
  for incoming pending bids

[#188791783]
  • Loading branch information
uraniumanchor committed Jan 18, 2025
1 parent de1c971 commit bd2dd08
Show file tree
Hide file tree
Showing 22 changed files with 516 additions and 766 deletions.
3 changes: 3 additions & 0 deletions bundles/processing/pages/ReadDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function useDonationGroupSyncOnLoad() {
for (const group of Object.values(groups)) {
group.donationIds.forEach(id => ids.add(id));
}
if (ids.size === 0) {
return;
}
const donations = await APIClient.getDonations(Array.from(ids).map(String));
loadDonations(donations);

Expand Down
14 changes: 4 additions & 10 deletions bundles/public/api/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { useSelector } from 'react-redux';

import { Permission } from '@common/Permissions';
import { Me } from '@public/apiv2/APITypes';

// FIXME: give these actual types

export function hasPermission(user: any, permission: Permission) {
export function hasPermission(user: Me, permission: Permission) {
return !!user?.staff && (user.superuser || (user.permissions || []).indexOf(permission) !== -1);
}

export function usePermission(permission: Permission) {
const me = useSelector((state: any) => state.singletons.me);
return hasPermission(me, permission);
}

export function usePermissions(permissions: Permission[]) {
const me = useSelector((state: any) => state.singletons.me);
export function usePermission(...permissions: Permission[]) {
const me = useSelector((state: any) => state.singletons.me as Me);
return permissions.every(p => hasPermission(me, p));
}

Expand Down
6 changes: 3 additions & 3 deletions bundles/public/apiv2/Endpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

const Endpoints = {
DONATIONS: `donations/`,
DONATIONS_UNPROCESSED: `donations/unprocessed/`,
DONATIONS_FLAGGED: `donations/flagged/`,
DONATIONS_UNREAD: `donations/unread/`,
DONATIONS_UNPROCESSED: (eventId?: number) => `${eventId == null ? '' : `events/${eventId}/`}donations/unprocessed/`,
DONATIONS_FLAGGED: (eventId?: number) => `${eventId == null ? '' : `events/${eventId}/`}donations/flagged/`,
DONATIONS_UNREAD: (eventId?: number) => `${eventId == null ? '' : `events/${eventId}/`}donations/unread/`,
DONATIONS_UNPROCESS: (donationId: string) => `donations/${donationId}/unprocess/`,
DONATIONS_APPROVE_COMMENT: (donationId: string) => `donations/${donationId}/approve_comment/`,
DONATIONS_DENY_COMMENT: (donationId: string) => `donations/${donationId}/deny_comment/`,
Expand Down
11 changes: 4 additions & 7 deletions bundles/public/apiv2/routes/donations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ interface DonationsFilterOptions {
}

export async function getUnprocessedDonations(eventId: string, options: DonationsFilterOptions = {}) {
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_UNPROCESSED, {
event_id: eventId,
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_UNPROCESSED(+eventId), {
after: options.after?.toISOString(),
});
return response.data;
}

export async function getFlaggedDonations(eventId: string, options: DonationsFilterOptions = {}) {
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_FLAGGED, {
event_id: eventId,
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_FLAGGED(+eventId), {
after: options.after?.toISOString(),
});
return response.data;
}

export async function getUnreadDonations(eventId: string, options: DonationsFilterOptions = {}) {
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_UNREAD, {
event_id: eventId,
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS_UNREAD(+eventId), {
after: options.after?.toISOString(),
});
return response.data;
Expand All @@ -37,7 +34,7 @@ export async function getUnreadDonations(eventId: string, options: DonationsFilt
*/
export async function getDonations(donationIds: string[]) {
const response = await HTTPUtils.get<Donation[]>(Endpoints.DONATIONS, {
ids: donationIds,
id: donationIds,
});
return response.data;
}
Expand Down
3 changes: 2 additions & 1 deletion bundles/tracker/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
return `${apiRoot}command/`;
},
get ME() {
return `${apiRoot}me/`;
// FIXME: grossssss
return `${apiRoot}../v2/me/`;
},
};
2 changes: 1 addition & 1 deletion spec/fixtures/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event } from '../../bundles/tracker/events/EventTypes';
import { Event } from '@tracker/events/EventTypes';

export function getFixtureEvent(overrides?: Partial<Event>): Event {
return {
Expand Down
10 changes: 5 additions & 5 deletions tests/apiv2/test_donation_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def test_fetch(self):
with self.saveSnapshot():
with self.subTest('via donation'):
data = self.get_noun(
'bids', self.donation, model_name='donations', user=self.view_user
'bids', self.donation, model_name='donation', user=self.view_user
)
self.assertExactV2Models([self.opened_child_bid], data)

data = self.get_noun(
'bids',
self.donation,
data={'all': ''},
model_name='donations',
model_name='donation',
user=self.view_user,
)
self.assertExactV2Models(
Expand All @@ -124,7 +124,7 @@ def test_fetch(self):
'bids',
self.other_donation,
data={'all': ''},
model_name='donations',
model_name='donation',
user=self.view_user,
)
self.assertExactV2Models(
Expand Down Expand Up @@ -207,14 +207,14 @@ def test_fetch(self):
'bids',
self.donation,
data={'all': ''},
model_name='donations',
model_name='donation',
user=None,
status_code=404,
)
self.get_noun(
'bids',
self.pending_donation,
model_name='donations',
model_name='donation',
user=None,
status_code=404,
)
Expand Down
Loading

0 comments on commit bd2dd08

Please sign in to comment.