Skip to content

Commit

Permalink
Implement git manager link
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelGusse committed Apr 3, 2024
1 parent 3d25bd9 commit 95d2b76
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aplus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# You can copy local_settings.example.py and start from there.
##
from os.path import abspath, dirname, join

from lib.logging import skip_unreadable_post
from os import environ
from r_django_essentials.conf import (
Expand Down Expand Up @@ -313,6 +314,7 @@
LOGIN_REDIRECT_URL = "/"
LOGIN_ERROR_URL = "/accounts/login/"


TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand All @@ -332,6 +334,7 @@
"django.contrib.messages.context_processors.messages",
"lib.context_processors.aplus_version",
"lib.context_processors.gitmanager_enabled",
"lib.context_processors.gitmanager_url"
],
},
},
Expand Down
58 changes: 58 additions & 0 deletions edit_course/templates/edit_course/edit_gitmanager.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<button type="submit" class="aplus-button--default aplus-button--md">
{% translate "SUBMIT" %}
</button>
<a class="aplus-button aplus-button--md" role="button" value="{{GITMANAGER_URL}}" href="" id="gitmanager-link"> {% csrf_token %}
{% translate "GO_TO_GITMANAGER_PAGE" %}
</a>
<div class="hidden progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width:100%;">
{% translate "UPDATING_GITMANAGER" %}
Expand All @@ -31,6 +34,7 @@

{% block scripts %}
{{ block.super }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js"></script>
<script>
$(function() {
var form = $("#gitmanager-form");
Expand All @@ -39,5 +43,59 @@
form.find('.progress').removeClass("hidden");
});
});

$(function() {
$("#gitmanager-link").on("click", async function(event) {
event.preventDefault();

const course_id = document.getElementById('id_remote_id').value;

console.log(course_id)

const csrftoken = Cookies.get('csrftoken');
var data = {
"taud": "gitmanager",
"exp": "01:00:00",
"permissions": [
["instance", 1, {"id": course_id}],
["instance", 2, {"id": course_id}]
]
};

var jsonData = JSON.stringify(data);

console.log(jsonData)

const response = await fetch('/api/v2/get-token/', {
method: 'POST',
headers: {'X-CSRFToken': csrftoken,
'Content-type': 'application/json'
},
body: jsonData
});

var resp_data = await response.json();

// Set the cookie such that it is also visible to gitmanager
// document.cookie = "AuthToken=" + resp_data + ";domain=.aalto.fi; SameSite=None; Secure; path=/; max-age=3600;";

var gitman_url = String("{{GITMANAGER_URL}}/login");

const response2 = await fetch(gitman_url, {
method: 'POST',
headers: {'Authorization': 'Bearer ' + resp_data,
},
xhrFields: {
'withCredentials': true
},
});

var resp_data2 = await response2;
console.log(response2)

window.location = gitman_url;

});
});
</script>
{% endblock %}
5 changes: 5 additions & 0 deletions lib/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ def gitmanager_enabled(request):
return {
'GITMANAGER_ENABLED': bool(settings.GITMANAGER_URL),
}

def gitmanager_url(request):
return {
'GITMANAGER_URL': settings.GITMANAGER_URL,
}
4 changes: 4 additions & 0 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,10 @@ msgstr "Edit Git manager settings"
msgid "EDIT_GITMANAGER_DESCRIPTION"
msgstr "This action will update the course instance settings on Git manager."

#: edit_course/templates/edit_course/edit_gitmanager.html
msgid "GO_TO_GITMANAGER_PAGE"
msgstr "Open the gitmanager page"

#: edit_course/templates/edit_course/edit_gitmanager.html
msgid "UPDATING_GITMANAGER"
msgstr "Updating Git manager..."
Expand Down
4 changes: 4 additions & 0 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,10 @@ msgstr "Muokkaa Git managerin asetuksia"
msgid "EDIT_GITMANAGER_DESCRIPTION"
msgstr "Tämä toiminto päivittää kurssikerran asetuksia Git managerissa."

#: edit_course/templates/edit_course/edit_gitmanager.html
msgid "GO_TO_GITMANAGER_PAGE"
msgstr "Mene gitmanager sivulle"

#: edit_course/templates/edit_course/edit_gitmanager.html
msgid "UPDATING_GITMANAGER"
msgstr "Päivitetään Git manageria..."
Expand Down

0 comments on commit 95d2b76

Please sign in to comment.