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 Mar 25, 2024
1 parent 3d25bd9 commit 698486e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
6 changes: 6 additions & 0 deletions aplus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# You can copy local_settings.example.py and start from there.
##
from os.path import abspath, dirname, join

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

def gitmanager_url(request):
return {'gitmanager_url': settings.GITMANAGER_URL}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand All @@ -332,6 +337,7 @@
"django.contrib.messages.context_processors.messages",
"lib.context_processors.aplus_version",
"lib.context_processors.gitmanager_enabled",
"lib.context_processors.gitmanager_url"
],
},
},
Expand Down
45 changes: 45 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--secondary 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,46 @@
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();

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

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

window.location = gitman_url;

});
});
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion edit_course/templatetags/editcourse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template
from django.urls import reverse
from django.conf import settings

from course.models import CourseInstance

Expand Down Expand Up @@ -33,7 +34,6 @@ def removeurl(model_object, model_name):
id=model_object.id,
))


@register.filter
def createurl(model_object, model_name):
type_name = None
Expand Down
3 changes: 1 addition & 2 deletions edit_course/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django.urls import re_path

import authorization.api.views
from course.urls import EDIT_URL_PREFIX
from . import views


MODEL_URL_PREFIX = EDIT_URL_PREFIX + r'(?P<model>[\w\d\-]+)/'

urlpatterns = [
re_path(EDIT_URL_PREFIX + r'$',
views.EditContentView.as_view(),
Expand Down
1 change: 1 addition & 0 deletions edit_course/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def form_valid(self, form):
"git_branch": form.cleaned_data['git_branch'],
"update_hook": form.cleaned_data['update_hook'],
"webhook_secret": form.cleaned_data['webhook_secret'],
"gitmanager_url": settings.GITMANAGER_URL,
}

permissions = Permissions()
Expand Down
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,
}

0 comments on commit 698486e

Please sign in to comment.