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

fix: Crowdin proofreader cancelling event is not well triggered - Meeds-io/meeds#2655 #64

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ -22,8 +22,11 @@
import io.meeds.crowdin.gamification.model.RemoteApproval;
import io.meeds.crowdin.gamification.services.CrowdinTriggerService;
import io.meeds.crowdin.gamification.services.WebhookService;
import io.meeds.gamification.model.RealizationDTO;
import io.meeds.gamification.service.RealizationService;
import jakarta.annotation.PostConstruct;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -36,6 +39,8 @@
@Component
public class SuggestionApprovedTriggerPlugin extends CrowdinTriggerPlugin {

private static final Log LOG = ExoLogger.getLogger(SuggestionApprovedTriggerPlugin.class);

@Autowired
private CrowdinTriggerService crowdinTriggerService;

Expand Down Expand Up @@ -67,24 +72,51 @@ public List<Event> getEvents(String trigger, Map<String, Object> payload) {
trigger.equals(SUGGESTION_DISAPPROVED_TRIGGER),
countWords(extractSubItem(payload, TRANSLATION, STRING, TEXT))));

// Retrieve who made that approval by calling Crowdin API
String translationId = extractSubItem(payload, TRANSLATION, ID);
RemoteApproval remoteApproval = webhookService.getApproval(getProjectId(payload), translationId);

if (remoteApproval != null) {
eventList.add(new Event(APPROVE_SUGGESTION_EVENT_NAME,
remoteApproval.getUserName(),
remoteApproval.getUserName(),
objectId,
TRANSLATION,
getProjectId(payload),
extractSubItem(payload, TRANSLATION, TARGET_LANGUAGE, ID),
extractSubItem(payload, TRANSLATION, PROVIDER) == null,
extractSubItem(payload, TRANSLATION, STRING, FILE, DIRECTORY_ID),
trigger.equals(SUGGESTION_DISAPPROVED_TRIGGER),
countWords(extractSubItem(payload, TRANSLATION, STRING, TEXT))));

if (trigger.equals(SUGGESTION_APPROVED_TRIGGER)) {
// Retrieve who made that approval by calling Crowdin API
String translationId = extractSubItem(payload, TRANSLATION, ID);
RemoteApproval remoteApproval = webhookService.getApproval(getProjectId(payload), translationId);

if (remoteApproval != null) {
eventList.add(new Event(APPROVE_SUGGESTION_EVENT_NAME,
remoteApproval.getUserName(),
remoteApproval.getUserName(),
objectId,
APPROVAL,
getProjectId(payload),
extractSubItem(payload, TRANSLATION, TARGET_LANGUAGE, ID),
extractSubItem(payload, TRANSLATION, PROVIDER) == null,
extractSubItem(payload, TRANSLATION, STRING, FILE, DIRECTORY_ID),
false,
countWords(extractSubItem(payload, TRANSLATION, STRING, TEXT))));
}
}

if (trigger.equals(SUGGESTION_DISAPPROVED_TRIGGER)) {
// Retrieve who made that approval from the database

List<RealizationDTO> realizations = realizationService.
findRealizationsByObjectIdAndObjectType(objectId, APPROVAL);

if ( ! realizations.isEmpty()) {
String approvalUsername = realizations.get(0).getEarnerId();

eventList.add(new Event(APPROVE_SUGGESTION_EVENT_NAME,
approvalUsername,
approvalUsername,
objectId,
TRANSLATION,
getProjectId(payload),
extractSubItem(payload, TRANSLATION, TARGET_LANGUAGE, ID),
extractSubItem(payload, TRANSLATION, PROVIDER) == null,
extractSubItem(payload, TRANSLATION, STRING, FILE, DIRECTORY_ID),
true,
countWords(extractSubItem(payload, TRANSLATION, STRING, TEXT))));
}

}

return eventList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class Utils {

public static final String TRANSLATION = "translation";

public static final String APPROVAL = "approval";

public static final String SUGGESTION_ADDED_TRIGGER = "suggestion.added";

public static final String SUGGESTION_DELETED_TRIGGER = "suggestion.deleted";
Expand Down
Loading