Skip to content

Commit

Permalink
Merge pull request #5607 from dodona-edu/fix/disable-plgiarism-lang
Browse files Browse the repository at this point in the history
Disable plagiarism detection when language is not supported by dolos
  • Loading branch information
jorg-vr authored Jun 13, 2024
2 parents b5a4db9 + 7dadb5d commit 59e11a2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
12 changes: 11 additions & 1 deletion app/assets/javascripts/dolos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { i18n } from "i18n/i18n";

const LOADER_ID = "dolos-loader";
const DOLOS_URL = "/dolos_reports";
// List from https://github.com/dodona-edu/dolos/issues/1029 on 2024-06-13
const SUPPORTED_LANGUAGES = new Set(["sh", "c", "cpp", "csharp", "elm", "java", "javascript", "python", "typescript", "tsx"]);

export function initDolosBtn(btnID: string, url: string): void {
export function initDolosBtn(btnID: string, url: string, lang: string): void {
const btn = document.getElementById(btnID) as HTMLLinkElement;

const langName = lang.toLowerCase();
if (!SUPPORTED_LANGUAGES.has(langName)) {
btn.classList.add("disabled-with-tooltip");
btn.title = i18n.t("js.dolos.unsupported_language", { lang: lang });
return;
}

btn.addEventListener("click", () => startDolos(btn, url));
}

Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"date_on": "on",
"description_languages": "Language of the description",
"dolos": {
"unsupported_language": "%{lang} is not supported by the plagiarism checker.",
"view_report": "Open plagiarism report"
},
"draft": "Draft",
Expand Down Expand Up @@ -722,6 +723,7 @@
"date_on": "op",
"description_languages": "Taal van de beschrijving",
"dolos": {
"unsupported_language": "%{lang} wordt niet ondersteund door Dolos",
"view_report": "Rapport bekijken"
},
"draft": "Concept",
Expand Down
14 changes: 13 additions & 1 deletion app/assets/stylesheets/components/btn.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
pointer-events: none;
}

&.disabled-with-tooltip {
opacity: 0.38;
pointer-events: auto;
cursor: default;
}

// define the default button colors
// makes it easier to combine with other classes such as d-btn-danger, d-btn-success, etc.
--d-btn-color: var(--d-primary);
Expand Down Expand Up @@ -95,6 +101,11 @@
&:active {
opacity: 1;
background: rgba(var(--d-btn-color-rgb), 0.1);

&.disabled-with-tooltip {
opacity: 0.38;
background: none;
}
}
}

Expand Down Expand Up @@ -135,7 +146,8 @@
}

&.disabled,
&:disabled {
&:disabled,
&.disabled-with-tooltip {
color: var(--d-on-surface);
border: 1px solid rgba(var(--d-on-surface-rgb), 0.12);
opacity: 0.38;
Expand Down
2 changes: 1 addition & 1 deletion app/views/evaluations/_exercises_progress_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</a>
<script>
dodona.ready.then(() =>{
dodona.initDolosBtn('dolos-btn-<%= meta[:exercise].id %>', "<%= series_exports_path(@evaluation.series, token: (@evaluation.series.access_token if @evaluation.series.hidden?), selected_ids: [meta[:exercise].id], evaluation: true) %>");
dodona.initDolosBtn('dolos-btn-<%= meta[:exercise].id %>', "<%= series_exports_path(@evaluation.series, token: (@evaluation.series.access_token if @evaluation.series.hidden?), selected_ids: [meta[:exercise].id], evaluation: true) %>", "<%= meta[:exercise].programming_language&.renderer_name %>");
})
</script>
</td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<% actions << {icon: 'graph-outline', text: t('.detect_plagiarism'), id: "dolos-btn" } if @series && @activity %>
<script>
dodona.ready.then(() => {
dodona.initDolosBtn("dolos-btn", "<%= series_exports_path(@series, token: (@series.access_token if @series.hidden?), selected_ids: [@activity.id]) %>");
dodona.initDolosBtn("dolos-btn", "<%= series_exports_path(@series, token: (@series.access_token if @series.hidden?), selected_ids: [@activity.id]) %>", "<%= @activity.programming_language&.renderer_name %>");
});
</script>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/js/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,4 @@ en:
popularity: Popularity
dolos:
view_report: Open plagiarism report
unsupported_language: "%{lang} is not supported by the plagiarism checker."
1 change: 1 addition & 0 deletions config/locales/js/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,5 @@ nl:
popularity: Populariteit
dolos:
view_report: Rapport bekijken
unsupported_language: "%{lang} wordt niet ondersteund door Dolos"

0 comments on commit 59e11a2

Please sign in to comment.