Skip to content

Commit f08df95

Browse files
authored
Merge pull request #4072 from sarkapalkovicova/reject_applications_bulk
feat(core): reject applications method
2 parents 7d9cd86 + a2d270c commit f08df95

File tree

5 files changed

+110
-4
lines changed

5 files changed

+110
-4
lines changed

perun-openapi/openapi.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16387,6 +16387,23 @@ paths:
1638716387
default:
1638816388
$ref: '#/components/responses/ExceptionResponse'
1638916389

16390+
/urlinjsonout/registrarManager/rejectApplications:
16391+
post:
16392+
tags:
16393+
- RegistrarManager
16394+
operationId: rejectApplications
16395+
summary: Manually rejects multiple applications at once.
16396+
description: |
16397+
Expected to be called as a result of direct VO administrator action in the web UI.
16398+
parameters:
16399+
- $ref: '#/components/parameters/ids'
16400+
- { name: reason, schema: { type: string }, in: query, description: "description of reason", required: false }
16401+
responses:
16402+
'200':
16403+
$ref: '#/components/responses/VoidResponse'
16404+
default:
16405+
$ref: '#/components/responses/ExceptionResponse'
16406+
1639016407
/urlinjsonout/registrarManager/deleteApplication:
1639116408
post:
1639216409
tags:

perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/RegistrarManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@ public interface RegistrarManager {
420420
*/
421421
Application rejectApplication(PerunSession session, int appId, String reason) throws PerunException;
422422

423+
/**
424+
* Manually rejects multiple applications at once. Expected to be called as a result of direct VO administrator action in the web UI.
425+
*
426+
* @param sess perun session
427+
* @param applicationIds list of application IDs
428+
* @param reason optional reason of rejection displayed to user
429+
* @throws PerunException
430+
*/
431+
void rejectApplications(PerunSession sess, List<Integer> applicationIds, String reason) throws PerunException;
432+
423433
/**
424434
* Returns data submitted by user in given application (by id)
425435
*

perun-registrar-lib/src/main/java/cz/metacentrum/perun/registrar/impl/RegistrarManagerImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ public Application verifyApplication(PerunSession sess, int appId) throws PerunE
16411641
public Application rejectApplication(PerunSession sess, int appId, String reason) throws PerunException {
16421642

16431643
Application app = getApplicationById(appId);
1644-
if (app == null) throw new RegistrarException("Application with ID="+appId+" doesn't exists.");
1644+
if (app == null) throw new RegistrarException("Application with ID=" + appId + " doesn't exists.");
16451645

16461646
//Authorization
16471647
if (app.getGroup() == null) {
@@ -1656,15 +1656,15 @@ public Application rejectApplication(PerunSession sess, int appId, String reason
16561656

16571657
// only VERIFIED applications can be rejected
16581658
if (AppState.APPROVED.equals(app.getState())) {
1659-
throw new RegistrarException("Approved application can't be rejected ! Try to refresh the view to see changes.");
1659+
throw new RegistrarException("Approved application " + appId + " can't be rejected ! Try to refresh the view to see changes.");
16601660
} else if (AppState.REJECTED.equals(app.getState())) {
1661-
throw new RegistrarException("Application is already rejected. Try to refresh the view to see changes.");
1661+
throw new RegistrarException("Application " + appId + " is already rejected. Try to refresh the view to see changes.");
16621662
}
16631663

16641664
// lock to prevent concurrent runs
16651665
synchronized(runningRejectApplication) {
16661666
if (runningRejectApplication.contains(appId)) {
1667-
throw new AlreadyProcessingException("Application rejection is already processing.");
1667+
throw new AlreadyProcessingException("Application " + appId + " rejection is already processing.");
16681668
} else {
16691669
runningRejectApplication.add(appId);
16701670
}
@@ -1731,6 +1731,15 @@ public Application rejectApplication(PerunSession sess, int appId, String reason
17311731

17321732
}
17331733

1734+
@Override
1735+
@Transactional(rollbackFor = Exception.class)
1736+
public void rejectApplications(PerunSession sess, List<Integer> applicationIds, String reason) throws PerunException {
1737+
Collections.sort(applicationIds, Collections.reverseOrder());
1738+
for (Integer id : applicationIds) {
1739+
rejectApplication(sess, id, reason);
1740+
}
1741+
}
1742+
17341743
/**
17351744
* Deletes reserved logins which are used only by the given application.
17361745
* Deletes them from both KDC and DB.

perun-registrar-lib/src/test/java/cz/metacentrum/perun/registrar/RegistrarBaseIntegrationTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,47 @@ public void testRejectApplicationsAfterMemberRemoval() throws PerunException {
13061306
assertEquals(1, group1Apps.size());
13071307
}
13081308

1309+
@Test
1310+
public void testRejectApplications() throws PerunException {
1311+
User user1 = new User(1, "User1", "Test1", "", "", "");
1312+
User user2 = new User(2, "User2", "Test2", "", "", "");
1313+
user1 = perun.getUsersManagerBl().createUser(session, user1);
1314+
user2 = perun.getUsersManagerBl().createUser(session, user2);
1315+
1316+
Application application1 = prepareApplicationToVo(user1);
1317+
application1 = registrarManager.submitApplication(session, application1, new ArrayList<>());
1318+
1319+
Application application2 = prepareApplicationToVo(user2);
1320+
application2.setCreatedBy("perunTests2");
1321+
application2 = registrarManager.submitApplication(session, application2, new ArrayList<>());
1322+
1323+
registrarManager.rejectApplications(session, new ArrayList<>(Arrays.asList(application1.getId(), application2.getId())), null);
1324+
1325+
List<Integer> rejectedAppIdsVO = registrarManager.getApplicationsForVo(session, vo, List.of("REJECTED"), false).stream().map(Application::getId).toList();
1326+
assertThat(rejectedAppIdsVO).containsOnly(application1.getId(), application2.getId());
1327+
}
1328+
1329+
@Test
1330+
public void testRejectApplicationsOrder() throws PerunException {
1331+
User user = new User(1, "User1", "Test1", "", "", "");
1332+
user = perun.getUsersManagerBl().createUser(session, user);
1333+
1334+
Group group = new Group("Test", "Test group");
1335+
perun.getGroupsManagerBl().createGroup(session, vo, group);
1336+
registrarManager.createApplicationFormInGroup(session, group);
1337+
1338+
Application applicationToVo = prepareApplicationToVo(user);
1339+
applicationToVo = registrarManager.submitApplication(session, applicationToVo, new ArrayList<>());
1340+
1341+
Application applicationToGroup = prepareApplicationToGroup(user, group);
1342+
applicationToGroup = registrarManager.submitApplication(session, applicationToGroup, new ArrayList<>());
1343+
1344+
registrarManager.rejectApplications(session, new ArrayList<>(Arrays.asList(applicationToVo.getId(), applicationToGroup.getId())), null);
1345+
1346+
List<Integer> rejectedAppIds = registrarManager.getApplicationsForVo(session, vo, List.of("REJECTED"), true).stream().map(Application::getId).toList();
1347+
assertThat(rejectedAppIds).containsOnly(applicationToVo.getId(), applicationToGroup.getId());
1348+
}
1349+
13091350
private Application prepareApplicationToVo(User user) {
13101351
Application application = new Application();
13111352
application.setVo(vo);

perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/RegistrarManagerMethod.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,35 @@ public Application call(ApiCaller ac, Deserializer parms) throws PerunException
949949

950950
},
951951

952+
/*#
953+
* Manually rejects multiple applications at once.
954+
* Expected to be called as a result of direct VO administrator action in the web UI.
955+
*
956+
* @param ids int[] List of Application IDs
957+
*/
958+
/*#
959+
* Manually rejects multiple applications at once with a reason.
960+
* Expected to be called as a result of direct VO administrator action in the web UI.
961+
*
962+
* @param ids int[] List of Application IDs
963+
* @param reason String Reason description
964+
*/
965+
rejectApplications {
966+
967+
@Override
968+
public Application call(ApiCaller ac, Deserializer parms) throws PerunException {
969+
parms.stateChangingCheck();
970+
971+
if (parms.contains("reason")) {
972+
ac.getRegistrarManager().rejectApplications(ac.getSession(), parms.readList("ids", Integer.class), parms.readString("reason"));
973+
} else {
974+
ac.getRegistrarManager().rejectApplications(ac.getSession(), parms.readList("ids", Integer.class), null);
975+
}
976+
977+
return null;
978+
}
979+
},
980+
952981
/*#
953982
* Forcefully marks application as verified
954983
* (only when application was in NEW state)

0 commit comments

Comments
 (0)