Commit bb66ccdb authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts] added all functionalities to change/add supervisor and for...

[accounts] added all functionalities to change/add supervisor and for godfather to validate/remove supervisee
parent e5f0631e
Pipeline #11613 passed with stage
in 38 minutes and 15 seconds
......@@ -44,3 +44,53 @@ div.renew_account span.documentation
color: #AAAAAA;
font-size: 0.8em;
}
div.change_supervisor.progress
{
margin: 40px auto;
}
div.change_supervisor #infos
{
text-align: center;
display: block;
margin-top: 10px;
margin-bottom: 10px;
color: #777777;
}
div.change_supervisor span.label
{
display: inline-block;
width: 50%;
color: black;
font-size: 1em;
}
div.change_supervisor input#new_godfather_username
{
display: inline-block;
width: 50%;
}
div.change_supervisor input#new_godfather_username
{
margin-top: 10px;
}
div.change_supervisor span.documentation
{
color: #AAAAAA;
font-size: 0.8em;
}
.btn-supervisee
{
padding-top: 0em;
padding-bottom: 0em;
}
......@@ -30,8 +30,8 @@ if (beat.accounts.dialogs === undefined) beat.accounts.dialogs = {};
/**
* Implements a modal dialog to renew a user account.
* The user is presented with a small modal window that will allow
* him to set the new experiment name. It is possible to cancel the action at
* any moment by pressing "Cancel" or hitting the ESC key.
* him to certify the wish to renew his account. It is possible to cancel
* the action at any moment by pressing "Cancel" or hitting the ESC key.
*
* Parameters:
*
......@@ -65,7 +65,338 @@ beat.accounts.dialogs.modal_renew_account = function(dialog_id, api_url, redirec
$.ajax({
type: "PUT",
url: api_url /*+ experiment_fullname + '/' */,
url: api_url,
data: JSON.stringify({
name: name,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#' + dialog_id).dialog("close");
window.location.href = redirect_url;
},
error: function(jqXHR, textStatus, errorThrown) {
if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0))
alert(jqXHR.responseText);
else
alert('Error: ' + errorThrown);
$(this).dialog("close");
}
});
}
},
{
id: 'button-' + dialog_id + '-cancel',
text: 'Cancel',
click: function() {
$(this).dialog("close");
}
}
]
});
// Display the dialog
$('#' + dialog_id).dialog("open");
}
/**
* Implements a modal dialog to change supervisor.
* The user is presented with a small modal window that will allow
* him to add the new supervisor username. It is possible to cancel the action at
* any moment by pressing "Cancel" or hitting the ESC key.
*
* Parameters:
*
* dialog_id: ID of the DOM element to use
* old_godfather_username: previous supervisor username
* api_url (str): The URL towards the API for changing the supervisor
* redirect_url (str): The URL where to redirect the user if the operation is
* successful
*/
beat.accounts.dialogs.modal_change_supervisor = function(dialog_id, old_godfather_username, api_url, redirect_url) {
var split_api_url = api_url.split(old_godfather_username);
// Create the dialog
$('#' + dialog_id).dialog({
autoOpen: false,
resizable: false,
width: Math.min($(window).width() * 0.6, 700),
position: { my: "center", at: "center", of: window },
modal: true,
closeOnEscape: true,
buttons: [
{
id: 'button-' + dialog_id + '-renameit',
text: 'New supervision request',
click: function() {
var new_godfather_username = $('#' + dialog_id + ' #new_godfather_username')[0].value;
var name = $('#' + dialog_id + ' input')[0].value.trim();
if (name.length == 0)
{
alert("You can't enter an empty godfather username!");
return;
}
if (new_godfather_username == old_godfather_username)
{
alert("The new godfather username is the same as the previous one!");
return;
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
});
$.ajax({
type: "POST",
url: split_api_url[0] + new_godfather_username + split_api_url[1],
data: JSON.stringify({
name: name,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#' + dialog_id).dialog("close");
window.location.href = redirect_url;
},
error: function(jqXHR, textStatus, errorThrown) {
if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0))
alert(jqXHR.responseText);
else
alert('Error: ' + errorThrown);
}
});
}
},
{
id: 'button-' + dialog_id + '-cancel',
text: 'Cancel',
click: function() {
$(this).dialog("close");
}
}
]
});
// Initialise the dialog content
$('#' + dialog_id + ' input')[0].value = old_godfather_username;
// Display the dialog
$('#' + dialog_id).dialog("open");
}
/**
* Implements a modal dialog to add a supervisor.
* The user is presented with a small modal window that will allow
* him to add to set the supervisor username. It is possible to cancel the action at
* any moment by pressing "Cancel" or hitting the ESC key.
*
* Parameters:
*
* dialog_id: ID of the DOM element to use
* api_url (str): The URL towards the API for adding a supervisor
* redirect_url (str): The URL where to redirect the user if the operation is
* successful
*/
beat.accounts.dialogs.modal_add_supervisor = function(dialog_id, api_url, redirect_url) {
var split_api_url = api_url.split("nogodfather");
// Create the dialog
$('#' + dialog_id).dialog({
autoOpen: false,
resizable: false,
width: Math.min($(window).width() * 0.6, 700),
position: { my: "center", at: "center", of: window },
modal: true,
closeOnEscape: true,
buttons: [
{
id: 'button-' + dialog_id + '-renameit',
text: 'New supervision request',
click: function() {
var new_godfather_username = $('#' + dialog_id + ' #new_godfather_username')[0].value;
var name = $('#' + dialog_id + ' input')[0].value.trim();
if (name.length == 0)
{
alert("You can't enter an empty godfather username!");
return;
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
});
$.ajax({
type: "POST",
url: split_api_url[0] + new_godfather_username + split_api_url[1],
data: JSON.stringify({
name: name,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#' + dialog_id).dialog("close");
window.location.href = redirect_url;
},
error: function(jqXHR, textStatus, errorThrown) {
if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0))
alert(jqXHR.responseText);
else
alert('Error: ' + errorThrown);
}
});
}
},
{
id: 'button-' + dialog_id + '-cancel',
text: 'Cancel',
click: function() {
$(this).dialog("close");
}
}
]
});
// Initialise the dialog content
$('#' + dialog_id + ' input')[0].value = '';
// Display the dialog
$('#' + dialog_id).dialog("open");
}
/**
* Implements a modal dialog for the supervisor to validate a supervisee
* account. It is possible to cancel the action at any moment by pressing
* "Cancel" or hitting the ESC key.
*
* Parameters:
*
* dialog_id: ID of the DOM element to use
* api_url (str): The URL towards the API to validate a supervisee
* redirect_url (str): The URL where to redirect the user if the operation is
* successful
*/
beat.accounts.dialogs.modal_validate_supervisee = function(dialog_id, api_url, redirect_url) {
// Create the dialog
$('#' + dialog_id).dialog({
autoOpen: false,
resizable: false,
width: Math.min($(window).width() * 0.6, 700),
position: { my: "center", at: "center", of: window },
modal: true,
closeOnEscape: true,
buttons: [
{
id: 'button-' + dialog_id + '-renameit',
text: 'Validation of supervisee account',
click: function() {
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
});
$.ajax({
type: "PUT",
url: api_url,
data: JSON.stringify({
name: name,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#' + dialog_id).dialog("close");
window.location.href = redirect_url;
},
error: function(jqXHR, textStatus, errorThrown) {
if ((jqXHR.status == 400) && (jqXHR.responseText.length > 0))
alert(jqXHR.responseText);
else
alert('Error: ' + errorThrown);
$(this).dialog("close");
}
});
}
},
{
id: 'button-' + dialog_id + '-cancel',
text: 'Cancel',
click: function() {
$(this).dialog("close");
}
}
]
});
// Display the dialog
$('#' + dialog_id).dialog("open");
}
/**
* Implements a modal dialog for the supervisor to remove a supervisee
* account. It is possible to cancel the action at any moment by pressing
* "Cancel" or hitting the ESC key.
*
* Parameters:
*
* dialog_id: ID of the DOM element to use
* api_url (str): The URL towards the API to remove a supervisee
* redirect_url (str): The URL where to redirect the user if the operation is
* successful
*/
beat.accounts.dialogs.modal_remove_supervisee = function(dialog_id, api_url, redirect_url) {
// Create the dialog
$('#' + dialog_id).dialog({
autoOpen: false,
resizable: false,
width: Math.min($(window).width() * 0.6, 700),
position: { my: "center", at: "center", of: window },
modal: true,
closeOnEscape: true,
buttons: [
{
id: 'button-' + dialog_id + '-renameit',
text: 'Removal of supervisee account',
click: function() {
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
});
$.ajax({
type: "PUT",
url: api_url,
data: JSON.stringify({
name: name,
}),
......
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
<div id="{{ dialog_id }}" class="change_supervisor" style="display:none;" title="Supervision update">
<div class="settings">
<div><span id="infos"></span></div>
Take into account that requesting a new supervision will temporarely set your account in a rejected state until the request is validated by your new supervisor.<br>
If your new supervisor rejects your supervision request, you need to find another supervisor.<br>
If no supervisor is found after a specific date, your account will be blocked and you will need to proceed with an unblock account request<br>
<div><span class="label">New supervisor username: </span><input id="new_godfather_username" type="text" /></div>
<div><span class="documentation">A request for supervision will be sent to the new supervisor</span></div>
</div>
</div>
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
<div id="{{ dialog_id }}" class="renew_account" style="display:none;" title="Remove supervisee">
<div class="settings">
<div><span id="infos"></span></div>
This action will remove the supervisee from your supervision list.
</div>
</div>
{% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch
*
* This file is part of the beat.web module of the BEAT platform.
*
* Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch
*
* Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %}
<div id="{{ dialog_id }}" class="renew_account alert-warning" style="display:none;" title="Validate supervisee">
<div class="settings">
<div><span id="infos"></span></div>
This action will add the supervisee to your supervision list. You therefore acknowledge that this user is under your responsability.
</div>
</div>
......@@ -226,8 +226,34 @@
<li class="list-group-item"><b>Supervision Track last validation date:</b> {{ supervisiontrack.last_validation_date }}</li>
<li class="list-group-item"><b>Supervision Track expiration date:</b> {{ supervisiontrack.expiration_date }}</li>
</ul>
<div class="form-group" style="text-align: center;">
<input type="hidden" name="token" value="true">
<button type="button" class="btn btn-warning" onclick="beat.accounts.dialogs.modal_change_supervisor('change_supervisor', '{{ supervisiontrack.godfather.username }}', '{% url 'api_accounts:add_supervisor' supervisiontrack.godfather.username %}', '{% url 'accounts:settings' %}');"><i class="fa fa-refresh fa-fw fa-lg"></i> Wish to update supervision?</button>
</div>
{% elif user.profile.status == 'R' %}
<li class="list-group-item list-group-item-warning" style="text-align:center;">Rejected: You need to find a new supervisor</li>
<li class="list-group-item list-group-item-danger" style="text-align:center;">Status is rejected: You need to find a new supervisor</li>
<br>
{% if user.profile.supervision_key == None %}
<h4>General Information</h4>
<ul class="list-group">
<li class="list-group-item"><b>You need to find a new supervisor to continue using your account</b></li>
<li class="list-group-item"><b>Deadline account blockage date (if no supervisor):</b> {{ user.profile.rejection_date }}</li>
<li class="list-group-item"><i>If your account gets blocked you can still follow the unblock procedure to re-activate it.</i></li>
</ul>
<div class="form-group" style="text-align: center;">
<input type="hidden" name="token" value="true">
<button type="button" class="btn btn-danger" onclick="beat.accounts.dialogs.modal_add_supervisor('change_supervisor', '{% url 'api_accounts:add_supervisor' 'nogodfather' %}', '{% url 'accounts:settings' %}');"><i class="fa fa-plus fa-fw fa-lg"></i> Add a supervisor</button>
</div>
{% else %}
<h4>General Information about a pending request</h4>
<ul class="list-group">
<li class="list-group-item"><b>Pending request made to supervisor:</b> {{ supervisiontrack.godfather.username }}</li>
<li class="list-group-item"><b>Deadline account blockage date (if no supervisor):</b> {{ user.profile.rejection_date }}</li>
<li class="list-group-item"><i>You need to be patient until this supervisor accepts your request. An email was sent about your request, but in the meantime you can remind him to accept your supervision.<br>
If this supervisor rejects your supervision request, you will be informed and you will get the opportunity to make a new one.<br>
If your account gets blocked you can still follow the unblock procedure to re-activate it.</i></li>
</ul>
{% endif %}
<br>
{% elif user.profile.status == 'Y' %}
<li class="list-group-item list-group-item-warning" style="text-align:center;">Revalidation required: You need to confirm that you wish to revalidate your account (year basis check)</li>
......@@ -254,8 +280,101 @@
</div>
{% else %}
<div class="row">
<div class="col-sm-6 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-users"></i> Supervision management
</div>
<div class="panel-body">
<form id="token" method="post" action="" class="form">
{% csrf_token %}
<div class="form-group" style="text-align: justify;">
{% if supervisiontracks_pending|length > 0 %}
<li class="list-group-item list-group-item-danger" style="text-align:center;">Pending requests: You have a few days to accept or reject these supervision requests</li>
<br>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Username</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for supervisiontrack_pending in supervisiontracks_pending%}
<tr class="danger">
<td>{{supervisiontrack_pending.supervisee.first_name}}</td>
<td>{{supervisiontrack_pending.supervisee.last_name}}</td>
<td>{{supervisiontrack_pending.supervisee.username}}</td>
<td>{{supervisiontrack_pending.supervisee.email}}</td>
<td>
<button type="button" class="btn btn-success btn-supervisee" onclick="beat.accounts.dialogs.modal_validate_supervisee('validate_supervisee', '{% url 'api_accounts:validate_supervisee' supervisiontrack_pending.supervisee.username %}', '{% url 'accounts:settings' %}');"> Accept</button>
<button type="button" class="btn btn-danger btn-supervisee" onclick="beat.accounts.dialogs.modal_remove_supervisee('remove_supervisee', '{% url 'api_accounts:remove_supervisee' supervisiontrack_pending.supervisee.username %}', '{% url 'accounts:settings' %}');"> Reject</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<hr />
{% endif %}
<li class="list-group-item" style="text-align:center;"><b>Supervision list</b></li>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Username</th>
<th>Email</th>
<th>Start Date</th>
<th>Expiration Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for supervisiontrack_valid in supervisiontracks_valid%}
{% if supervisiontrack_valid.supervisee.profile