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 21, 2024
1 parent 3d25bd9 commit 0de2bce
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
49 changes: 49 additions & 0 deletions edit_course/static/gitmanager_redir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as Cookies from "https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js"

const copyToClipboard = (btnClassSelector, targetIdSelector) => {
$(function() {
var form = $("#gitmanager-form");
form.on("submit", function(event) {
form.find('[type="submit"]').attr("disabled", true);
form.find('.progress').removeClass("hidden");
});
});

$(function() {
$("#gitmanager-link").on("click", async function(event) {
event.preventDefault();
const csrftoken = Cookies.get('csrftoken');
var data = {
"taud": "gitmanager",
"exp": "01:00:00",
"permissions": [
["instance", 1, {"id": 169}],
["instance", 2, {"id": 169}]
]
};

var jsonData = JSON.stringify(data);

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

const resp_data = await response.json(); // Convert the data to JSON
console.log(resp_data); // Logs the result in the console

window.location = `https://gitmanager.cs.aalto.fi/login?referer=%2F&login=${encodeURIComponent(resp_data)}`;

window.onload = function() {
var token_field = document.getElementById('login-form');
token_field.value = resp_data;
console.log(token_field.value);
document.getElementById('login-form').submit();
};

});
});
};
44 changes: 44 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" 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,45 @@
form.find('.progress').removeClass("hidden");
});
});

$(function() {
$("#gitmanager-link").on("click", async function(event) {
event.preventDefault();
const csrftoken = Cookies.get('csrftoken');
var data = {
"taud": "gitmanager",
"exp": "01:00:00",
"permissions": [
["instance", 1, {"id": 169}],
["instance", 2, {"id": 169}]
]
};

var jsonData = JSON.stringify(data);

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

const resp_data = await response.json(); // Convert the data to JSON
console.log(resp_data); // Logs the result in the console

localStorage.setItem('token', resp_data);

window.location = `https://gitmanager.cs.aalto.fi/login?referer=%2F&token=${encodeURIComponent(resp_data)}`;

window.onload = function() {
var token_field = document.getElementById('login-form');
token_field.value = resp_data;
console.log(token_field.value);
$(('#Login').submit();
};

});
});
</script>
{% endblock %}
7 changes: 5 additions & 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 Expand Up @@ -62,4 +61,8 @@
re_path(MODEL_URL_PREFIX + r'(?P<id>\d+)/delete/$',
views.ModelDeleteView.as_view(),
name='model-remove'),
re_path(r"^get-token",
authorization.api.views.RemoteAuthenticationView.as_view(),
name="get-token"),

]
5 changes: 5 additions & 0 deletions edit_course/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ def form_valid(self, form):

return self.redirect(self.instance.get_url('gitmanager-details'))

class GoToGitmanagerView(CourseInstanceMixin, BaseRedirectView):
template_name = "edit_course/edit_gitmanager.html"
def get_success_url(self):
return self.instance.get_url('course-index')


class ConfigureContentView(CourseInstanceMixin, BaseRedirectView):
access_mode = ACCESS.TEACHER
Expand Down

0 comments on commit 0de2bce

Please sign in to comment.