@@ -25,15 +25,14 @@ import { TopcoderMembersService } from 'src/shared/topcoder/members.service';
2525import { Role } from 'src/core/auth/auth.constants' ;
2626import { Roles , User } from 'src/core/auth/decorators' ;
2727
28- import { UserInfo } from 'src/dto/user.type' ;
29-
3028import { AdminService } from './admin.service' ;
3129import { ResponseDto , ResponseStatusType } from 'src/dto/api-response.dto' ;
3230import { WinningAuditDto , AuditPayoutDto } from './dto/audit.dto' ;
3331
3432import { WinningRequestDto , SearchWinningResult } from 'src/dto/winning.dto' ;
3533import { WinningsRepository } from '../repository/winnings.repo' ;
3634import { WinningUpdateRequestDto } from './dto/winnings.dto' ;
35+ import { AccessControlService } from 'src/shared/access-control' ;
3736
3837@ApiTags ( 'AdminWinnings' )
3938@Controller ( '/admin' )
@@ -45,20 +44,14 @@ export class AdminController {
4544 private readonly adminService : AdminService ,
4645 private readonly winningsRepo : WinningsRepository ,
4746 private readonly tcMembersService : TopcoderMembersService ,
47+ private readonly accessControlService : AccessControlService ,
4848 ) { }
4949
50- private isBaAdmin ( user ?: { roles ?: string [ ] } ) {
51- return ( user ?. roles || [ ] ) . some (
52- ( r ) =>
53- r &&
54- r . trim ( ) . toLowerCase ( ) === Role . PaymentBaAdmin . trim ( ) . toLowerCase ( ) ,
55- ) ;
56- }
57-
5850 @Post ( '/winnings/search' )
5951 @Roles (
6052 Role . PaymentAdmin ,
6153 Role . PaymentBaAdmin ,
54+ Role . EngagementPaymentApprover ,
6255 Role . PaymentEditor ,
6356 Role . PaymentViewer ,
6457 )
@@ -80,13 +73,14 @@ export class AdminController {
8073 @Body ( ) body : WinningRequestDto ,
8174 @User ( ) user : any ,
8275 ) : Promise < ResponseDto < SearchWinningResult > > {
83- const result = await this . winningsRepo . searchWinnings (
84- await this . adminService . applyBaAdminUserFilters (
76+ const filters =
77+ await this . accessControlService . applyFilters < WinningRequestDto > (
8578 user . id ,
86- this . isBaAdmin ( user ) ,
79+ user . roles ,
8780 body ,
88- ) ,
89- ) ;
81+ ) ;
82+
83+ const result = await this . winningsRepo . searchWinnings ( filters ) ;
9084
9185 if ( result . error ) {
9286 result . status = ResponseStatusType . ERROR ;
@@ -101,6 +95,7 @@ export class AdminController {
10195 @Roles (
10296 Role . PaymentAdmin ,
10397 Role . PaymentBaAdmin ,
98+ Role . EngagementPaymentApprover ,
10499 Role . PaymentEditor ,
105100 Role . PaymentViewer ,
106101 )
@@ -121,15 +116,16 @@ export class AdminController {
121116 @Header ( 'Content-Type' , 'text/csv' )
122117 @Header ( 'Content-Disposition' , 'attachment; filename="winnings.csv"' )
123118 async exportWinnings ( @Body ( ) body : WinningRequestDto , @User ( ) user : any ) {
124- const baseFilters = await this . adminService . applyBaAdminUserFilters (
125- user . id ,
126- this . isBaAdmin ( user ) ,
127- {
128- ...body ,
129- limit : undefined ,
130- offset : undefined ,
131- } ,
132- ) ;
119+ const baseFilters =
120+ await this . accessControlService . applyFilters < WinningRequestDto > (
121+ user . id ,
122+ user . roles ,
123+ {
124+ ...body ,
125+ limit : undefined ,
126+ offset : undefined ,
127+ } ,
128+ ) ;
133129
134130 const winnings : SearchWinningResult [ 'winnings' ] = [ ] ;
135131 let offset = 0 ;
@@ -214,7 +210,12 @@ export class AdminController {
214210 }
215211
216212 @Patch ( '/winnings' )
217- @Roles ( Role . PaymentAdmin , Role . PaymentBaAdmin , Role . PaymentEditor )
213+ @Roles (
214+ Role . PaymentAdmin ,
215+ Role . PaymentBaAdmin ,
216+ Role . EngagementPaymentApprover ,
217+ Role . PaymentEditor ,
218+ )
218219 @ApiOperation ( {
219220 summary : 'Update winnings with given parameter' ,
220221 description :
@@ -227,7 +228,7 @@ export class AdminController {
227228 } )
228229 async updateWinning (
229230 @Body ( ) body : WinningUpdateRequestDto ,
230- @User ( ) user : UserInfo ,
231+ @User ( ) user : any ,
231232 ) : Promise < ResponseDto < string > > {
232233 if (
233234 ! body . paymentAmount &&
@@ -243,7 +244,7 @@ export class AdminController {
243244 const result = await this . adminService . updateWinnings (
244245 body ,
245246 user . id ,
246- this . isBaAdmin ( user ) ,
247+ user . roles ,
247248 ) ;
248249
249250 result . status = ResponseStatusType . SUCCESS ;
@@ -258,6 +259,7 @@ export class AdminController {
258259 @Roles (
259260 Role . PaymentAdmin ,
260261 Role . PaymentBaAdmin ,
262+ Role . EngagementPaymentApprover ,
261263 Role . PaymentEditor ,
262264 Role . PaymentViewer ,
263265 )
@@ -279,9 +281,11 @@ export class AdminController {
279281 @Param ( 'winningID' ) winningId : string ,
280282 @User ( ) user : any ,
281283 ) : Promise < ResponseDto < WinningAuditDto [ ] > > {
282- if ( this . isBaAdmin ( user ) ) {
283- await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
284- }
284+ await this . adminService . verifyUserAccessToWinning (
285+ winningId ,
286+ user . id ,
287+ user . roles ,
288+ ) ;
285289
286290 const result = await this . adminService . getWinningAudit ( winningId ) ;
287291
@@ -297,6 +301,7 @@ export class AdminController {
297301 @Roles (
298302 Role . PaymentAdmin ,
299303 Role . PaymentBaAdmin ,
304+ Role . EngagementPaymentApprover ,
300305 Role . PaymentEditor ,
301306 Role . PaymentViewer ,
302307 )
@@ -319,9 +324,11 @@ export class AdminController {
319324 @Param ( 'winningID' ) winningId : string ,
320325 @User ( ) user : any ,
321326 ) : Promise < ResponseDto < AuditPayoutDto [ ] > > {
322- if ( this . isBaAdmin ( user ) ) {
323- await this . adminService . verifyBaAdminAccessToWinning ( winningId , user . id ) ;
324- }
327+ await this . adminService . verifyUserAccessToWinning (
328+ winningId ,
329+ user . id ,
330+ user . roles ,
331+ ) ;
325332
326333 const result = await this . adminService . getWinningAuditPayout ( winningId ) ;
327334
0 commit comments