Skip to content

Commit

Permalink
record re-submit and cancel operations for auth (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull authored Oct 29, 2024
1 parent cec46c3 commit 543612d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public boolean approving() {
return this.ordinal() == Approving.ordinal() || this.ordinal() == ToConfirm.ordinal();
}

public boolean cancel() {
return this.ordinal() == ApproveCanceled.ordinal();
}

public boolean approveSuccess() {
return this.ordinal() == ApproveSuccess.ordinal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
public enum AuthResultStatus {
Submit("Submit"),
Agree("Agree"),
Reject("Reject");
Reject("Reject"),
Cancel("Cancel");

private final String name;

Expand All @@ -40,6 +41,10 @@ public boolean reject() {
return this.ordinal() == Reject.ordinal();
}

public boolean cancel() {
return this.ordinal() == Cancel.ordinal();
}

public static AuthResultStatus deserialize(String result) {
if (StringUtils.isBlank(result)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,31 @@ public WeDPRResponse updateAuthResult(String authorizer, AuthResultRequest authR
updatedAuth.setAuthChain(result.getAuthChain());
// update the authResult
updatedAuth.updateResult(authorizer, authResultRequest.getAuthResultDetail());
boolean progressToNextAuditor = false;
if (authResultRequest.getAuthResultDetail().getAuthResultStatus().agree()) {
// progress to next applyNode if the auth-result is agreed
updatedAuth.progressToNextAuthNode();
progressToNextAuditor = true;
// update the status to approving
if (result.getAuthStatus().toConfirmed()) {
updatedAuth.setAuthStatus(AuthorizationDO.AuthStatus.Approving);
}
} else {
} else if (authResultRequest.getAuthResultDetail().getAuthResultStatus().reject()) {
// return to the applicant if the auth-result is rejected
updatedAuth.progressToApplicant(result.getApplicant(), result.getApplicantAgency());
progressToNextAuditor = true;
}
if (progressToNextAuditor) {
// set the CurrentApplyNode to the follower
FollowerDO followerDO =
new FollowerDO(
updatedAuth.getCurrentApplyNode(),
updatedAuth.getCurrentApplyNodeAgency(),
updatedAuth.getId(),
FollowerDO.FollowerType.AUTH_AUDITOR.getType());
updatedAuth.setFollowerDOList(
new ArrayList<>(Collections.singletonList(followerDO)));
}
// set the CurrentApplyNode to the follower
FollowerDO followerDO =
new FollowerDO(
updatedAuth.getCurrentApplyNode(),
updatedAuth.getCurrentApplyNodeAgency(),
updatedAuth.getId(),
FollowerDO.FollowerType.AUTH_AUDITOR.getType());
updatedAuth.setFollowerDOList(new ArrayList<>(Collections.singletonList(followerDO)));
return updateAuth(authorizer, new AuthRequest(updatedAuth, false), false);
} catch (Exception e) {
logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import java.util.List;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ParamChecker {

private static final Logger logger = LoggerFactory.getLogger(ParamChecker.class);
private final AuthMapperWrapper authMapperWrapper;
private final String agency;

Expand Down Expand Up @@ -140,7 +142,16 @@ public void checkUpdateAuth(
}
// update the authStatus to ToConfirm when original status is AuthReject
if (authorizationDO.getAuthStatus() == null && result.get(0).getAuthStatus().rejected()) {
logger.info(
"Reset the rejected auth to ToConfirm status, authInfo: {}",
authorizationDO.toString());
authorizationDO.setAuthStatus(AuthorizationDO.AuthStatus.ToConfirm);
updateAuthResult(applicant, authorizationDO, result.get(0), AuthResultStatus.Submit);
}
// the cancel case
if (authorizationDO.getAuthStatus().cancel()) {
logger.info("The auth {} canceled, record the result", authorizationDO.toString());
updateAuthResult(applicant, authorizationDO, result.get(0), AuthResultStatus.Cancel);
}
// not first AuthNode, can't update the content
if (result.get(0).getCurrentApplyNode().compareToIgnoreCase(applicant) != 0
Expand All @@ -150,6 +161,19 @@ public void checkUpdateAuth(
}
}

private void updateAuthResult(
String applicant,
AuthorizationDO authorizationDO,
AuthorizationDO lastRecorder,
AuthResultStatus authResultStatus) {
authorizationDO.setAuthChain(lastRecorder.getAuthChain());
authorizationDO.setResult(lastRecorder.getResult());
// update the authResult
AuthResult.AuthResultDetail authResultDetail = new AuthResult.AuthResultDetail();
authResultDetail.setAuthResultStatus(authResultStatus);
authorizationDO.updateResult(applicant, authResultDetail);
}

@SneakyThrows(WeDPRException.class)
public AuthorizationDO checkAuthResultRequest(
String authorizer, AuthResultRequest authResultRequest) {
Expand Down

0 comments on commit 543612d

Please sign in to comment.