Skip to content

Commit

Permalink
Show other submissions of solved chapter problems correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Aug 15, 2024
1 parent 70f75a2 commit 5dbd63b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
package judgels.jerahmeel.submission;

import javax.inject.Inject;
import judgels.gabriel.api.Verdict;
import judgels.gabriel.api.Verdicts;
import judgels.jerahmeel.persistence.StatsUserProblemDao;
import judgels.jerahmeel.persistence.StatsUserProblemModel;
import judgels.jerahmeel.role.RoleChecker;
import java.util.Optional;

public class SubmissionRoleChecker {
private final RoleChecker roleChecker;
private final StatsUserProblemDao statsUserProblemDao;

@Inject
public SubmissionRoleChecker(RoleChecker roleChecker) {
public SubmissionRoleChecker(RoleChecker roleChecker, StatsUserProblemDao statsUserProblemDao) {
this.roleChecker = roleChecker;
this.statsUserProblemDao = statsUserProblemDao;
}

public boolean canViewSource(String userJid, String submissionUserJid) {
public boolean canViewProblemSetSource(String userJid, String submissionUserJid, String problemJid) {
if (roleChecker.isAdmin(userJid)) {
return true;
}
return userJid.equals(submissionUserJid);
}

public boolean canViewChapterSource(String userJid, String submissionUserJid, String problemJid) {
if (roleChecker.isAdmin(userJid)) {
return true;
}
if (userJid.equals(submissionUserJid)) {
return true;
}

Optional<StatsUserProblemModel> model = statsUserProblemDao.selectByUserJidAndProblemJid(userJid, problemJid);
return model.isPresent() && Verdicts.fromCode(model.get().verdict) == Verdict.ACCEPTED;
}

public boolean canManage(String userJid) {
return roleChecker.isAdmin(userJid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,35 @@ public SubmissionWithSourceResponse getSubmissionWithSourceById(

String containerJid = submission.getContainerJid();
String problemJid = submission.getProblemJid();
String userJid = submission.getUserJid();

List<String> containerPath;
String containerName;
String problemAlias;
boolean canViewSource;

if (SubmissionUtils.isProblemSet(containerJid)) {
ProblemSet problemSet = checkFound(problemSetStore.getProblemSetByJid(containerJid));
ProblemSetProblem problem = checkFound(problemSetProblemStore.getProblem(problemSet.getJid(), problemJid));
containerPath = checkFound(problemSetStore.getProblemSetPathByJid(containerJid));
containerName = problemSet.getName();
problemAlias = problem.getAlias();
canViewSource = submissionRoleChecker.canViewProblemSetSource(actorJid, userJid, problemJid);
} else {
Chapter chapter = checkFound(chapterStore.getChapterByJid(containerJid));
ChapterProblem problem = checkFound(chapterProblemStore.getProblem(problemJid));
containerPath = checkFound(chapterStore.getChapterPathByJid(containerJid));
containerName = chapter.getName();
problemAlias = problem.getAlias();
canViewSource = submissionRoleChecker.canViewChapterSource(actorJid, userJid, problemJid);
}

ProblemInfo problem = sandalphonClient.getProblem(submission.getProblemJid());

String userJid = submission.getUserJid();
Profile profile = checkFound(Optional.ofNullable(jophielClient.getProfile(userJid)));

SubmissionWithSource submissionWithSource;
if (submissionRoleChecker.canViewSource(actorJid, submission.getUserJid())) {
if (canViewSource) {
SubmissionSource source = submissionSourceBuilder.fromPastSubmission(submission.getJid(), true);
submissionWithSource = new SubmissionWithSource.Builder()
.submission(submission)
Expand Down

0 comments on commit 5dbd63b

Please sign in to comment.