Skip to content

Commit

Permalink
button correctly dis- and enables iff instructor logs in
Browse files Browse the repository at this point in the history
  • Loading branch information
CDaut committed Nov 1, 2024
1 parent f935ef8 commit b919649
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 0 additions & 3 deletions .idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ExercisePanel extends SimpleToolWindowPanel {
private JPanel generalPanel;
private JButton startGradingRound1Button;
private JButton startGradingRound2Button;
private JButton startGradingRound3Button;
private TextFieldWithBrowseButton gradingConfigPathInput;

private JPanel statisticsPanel;
Expand Down Expand Up @@ -142,10 +143,21 @@ private void createGeneralPanel() {
a -> PluginState.getInstance().startNextAssessment(1));
generalPanel.add(startGradingRound2Button, "growx");

//only add the third grading round button iff the permissions are sufficient
PluginState.getInstance().registerConnectedListener(connectionOptional -> {
connectionOptional.flatMap(PermissionUtils::getAssessorPermissionLevel).ifPresent(System.out::println);
});
//add button for third correction round but disable it by default
startGradingRound3Button = new JButton("Start Grading Round 3");
startGradingRound3Button.setForeground(JBColor.GREEN);
startGradingRound3Button.addActionListener(
a -> PluginState.getInstance().startNextAssessment(3));
startGradingRound3Button.setEnabled(false);
generalPanel.add(startGradingRound3Button, "growx");

//only enable the third grading round button iff the permissions are sufficient
PluginState.getInstance().registerConnectedListener(connectionOptional -> connectionOptional.ifPresent(connection -> {
List<PermissionUtils.PermissionLevel> perms = PermissionUtils.getAssessorPermissionLevel(connection);
if (perms.contains(PermissionUtils.PermissionLevel.INSTRUCTOR)) {
startGradingRound3Button.setEnabled(true);
}
}));

gradingConfigPathInput = new TextFieldWithBrowseButton();
gradingConfigPathInput.addBrowseFolderListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import edu.kit.kastel.sdq.artemis4j.ArtemisNetworkException;
import edu.kit.kastel.sdq.artemis4j.grading.ArtemisConnection;
import edu.kit.kastel.sdq.intelligrade.state.PluginState;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -54,14 +53,14 @@ public static List<PermissionLevel> getAssessorPermissionLevel(ArtemisConnection
permissionLevels.add(PermissionLevel.NONE);
}

return permissionLevels;
return permissionLevels.stream().distinct().toList();
}

/**
* Map the string based permission level from the groups
* to some cleanly switchable enum
*/
public enum PermissionLevel implements Comparable<PermissionLevel> {
public enum PermissionLevel {
INSTRUCTOR,
TUTOR,
STUDENT,
Expand Down

0 comments on commit b919649

Please sign in to comment.