Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Compute Kudos properties instead of relying on given parameters in HTTP call - MEED-7636 - Meeds-io/meeds#2485 #543

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,25 @@ public Kudos createKudos(Kudos kudos, String currentUser) throws IllegalAccessEx
throw new IllegalAccessException("User having username'" + currentUser + "' is not authorized to send more kudos");
}

if (kudos.getSenderIdentityId() == null) {
kudos.setSenderIdentityId(senderIdentity.getId());
}
kudos.setSenderId(senderIdentity.getRemoteId());
kudos.setSenderIdentityId(senderIdentity.getId());
Object receiverObject = checkStatusAndGetReceiver(kudos.getReceiverType(), kudos.getReceiverId());

if (kudos.getReceiverIdentityId() == null) {
if (receiverObject instanceof Identity identity) {
if (receiverObject instanceof Identity identity && identity.isUser()) {
kudos.setReceiverId(identity.getRemoteId());
kudos.setReceiverType(USER_ACCOUNT_TYPE);
kudos.setReceiverIdentityId(identity.getId());
} else if (receiverObject instanceof Identity identity && identity.isSpace()) {
Space space = getSpace(identity.getRemoteId());
kudos.setReceiverIdentityId(space.getId());
kudos.setReceiverId(space.getPrettyName());
kudos.setReceiverType(SPACE_ACCOUNT_TYPE);
} else if (receiverObject instanceof Space space) {
if (canSendKudosInSpace(kudos, space, currentUser)) {
kudos.setReceiverId(space.getPrettyName());
kudos.setReceiverIdentityId(space.getId());
kudos.setReceiverType(SPACE_ACCOUNT_TYPE);
} else {
throw new IllegalAccessException("User cannot redact on space");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,45 @@ public void testSendKudosToSpace() {
assertEquals(kudosToSendOnActivity.getEntityId(), retrievedKudos.getEntityId());
}

@Test
@SneakyThrows
public void testSendKudosUsingSpaceId() {
String spaceRemoteId = "space4";

Identity spaceIdentity = identityManager.getOrCreateSpaceIdentity(spaceRemoteId);
KudosPeriod currentKudosPeriod = kudosService.getCurrentKudosPeriod();

Kudos kudosToSend = newKudosDTO();
kudosToSend.setReceiverType(SpaceIdentityProvider.NAME);
kudosToSend.setReceiverId(spaceService.getSpaceByPrettyName(spaceIdentity.getRemoteId()).getId());
kudosToSend.setReceiverIdentityId(null);
kudosToSend.setSpacePrettyName(spaceRemoteId);

restartTransaction();

List<Kudos> list = kudosService.getKudosByPeriodAndReceiver(Long.parseLong(spaceIdentity.getId()),
currentKudosPeriod.getStartDateInSeconds(),
currentKudosPeriod.getEndDateInSeconds(),
10);
assertNotNull(list);
assertEquals(0, list.size());

SpaceServiceMock.setRedactor(SENDER_REMOTE_ID);
try {
Kudos kudos = kudosService.createKudos(kudosToSend, SENDER_REMOTE_ID);
assertNotNull(kudos);
} finally {
SpaceServiceMock.setRedactor(null);
}

list = kudosService.getKudosByPeriodAndReceiver(Long.parseLong(spaceIdentity.getId()),
currentKudosPeriod.getStartDateInSeconds(),
currentKudosPeriod.getEndDateInSeconds(),
10);
assertNotNull(list);
assertEquals(1, list.size());
}

@Test
public void testGetKudosByPeriodType() {
long startTime = getCurrentTimeInSeconds();
Expand Down