Skip to content
Snippets Groups Projects
Commit 33d12dd1 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'issue_425' into 'master'

Issue 425

Improves on the solution for issue #425

See merge request !209
parents cb8d6e1c 9bcfc867
No related branches found
No related tags found
1 merge request!209Issue 425
Pipeline #
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
{% comment %} {% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch * Contact: beat.support@idiap.ch
* *
* This file is part of the beat.web module of the BEAT platform. * This file is part of the beat.web module of the BEAT platform.
* *
* Commercial License Usage * Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in * Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you * accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch * and Idiap. For further information contact tto@idiap.ch
* *
* Alternatively, this file may be used under the terms of the GNU Affero * 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 * Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file. * 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 * The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. * or FITNESS FOR A PARTICULAR PURPOSE.
* *
* You should have received a copy of the GNU Affero Public License along * 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/. * with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %} {% endcomment %}
...@@ -129,13 +129,6 @@ function process_diff(lines, editor, diff_line_numbers_classname) ...@@ -129,13 +129,6 @@ function process_diff(lines, editor, diff_line_numbers_classname)
</div> </div>
</div> </div>
<div id="errors" class="row" style="display:none">
<div class="col-sm-offset-1 col-sm-10">
<h2></h2>
<p></p>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
...@@ -143,79 +136,58 @@ jQuery(document).ready(function() { ...@@ -143,79 +136,58 @@ jQuery(document).ready(function() {
$('h4').hide(); $('h4').hide();
$('#progress').show(); $('#progress').show();
$.get('{% url 'api_algorithms:diff' algorithm1_author algorithm1_name algorithm1_version algorithm2_author algorithm2_name algorithm2_version %}') var d = $.get('{% url 'api_algorithms:diff' algorithm1_author algorithm1_name algorithm1_version algorithm2_author algorithm2_name algorithm2_version %}');
.done(function(data) {
d.done(function(data) {
$('#progress').hide();
$('h4').show(); $('#progress').hide();
$('h4').show();
var source_code_lines = data.source_code_diff.split('\n')
var source_code_lines = data.source_code_diff.split('\n');
var code = '';
for (var i = 0; i < source_code_lines.length; ++i) var code = '';
code += source_code_lines[i].substr(2) + '\n'; for (var i = 0; i < source_code_lines.length; ++i) {
code += source_code_lines[i].substr(2) + '\n';
var declaration_lines = data.diff.split('\n')
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i)
declaration += declaration_lines[i].substr(2) + '\n';
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
})
.fail(function(jqXHR, textStatus, errorThrown) {
$('#title').hide();
var errors_box = $('.container #errors');
if (jqXHR.status == 404)
{
errors_box.find('h2').text('Algorithm not found');
errors_box.find('p').html("We are sorry, but the algorithm called <strong>" +
jqXHR.responseText + "</strong> could not be found.");
}
else if (jqXHR.status == 401)
{
errors_box.find('h2').text('Unauthorized access');
errors_box.find('p').html("We are sorry, but your aren't authorized to access the algorithm called <strong>" +
jqXHR.responseText + "</strong>.");
}
else if (jqXHR.responseText.length > 0)
{
errors_box.find('h2').text(textStatus);
errors_box.find('p').html(jqXHR.responseText);
} }
else
{ var declaration_lines = data.diff.split('\n');
errors_box.find('h2').text(textStatus); var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i) {
declaration += declaration_lines[i].substr(2) + '\n';
} }
errors_box.show(); var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
});
d.fail(function (data, status_text) {
$('#progress').hide();
process_error(data, status_text, document.referrer);
}); });
}); });
......
...@@ -58,7 +58,6 @@ class ShareCodeView(ShareView): ...@@ -58,7 +58,6 @@ class ShareCodeView(ShareView):
class DiffView(generics.RetrieveAPIView): class DiffView(generics.RetrieveAPIView):
model = Code model = Code
permission_classes = [permissions.IsAuthenticated]
serializer_class = DiffSerializer serializer_class = DiffSerializer
def get(self, request, author1, name1, version1, author2, name2, version2): def get(self, request, author1, name1, version1, author2, name2, version2):
...@@ -79,13 +78,15 @@ class DiffView(generics.RetrieveAPIView): ...@@ -79,13 +78,15 @@ class DiffView(generics.RetrieveAPIView):
# Check that the user can access them # Check that the user can access them
accessibility = object1.accessibility_for(request.user) has_access, open_source, _ = object1.accessibility_for(request.user)
if not accessibility[1]: if not ((request.user == object1.author) or \
return ForbiddenResponse(object1.fullname()) (has_access and open_source)):
return ForbiddenResponse("You cannot access the source-code of \"%s\"" % object1.fullname())
accessibility = object2.accessibility_for(request.user)
if not accessibility[1]: has_access, open_source, _ = object2.accessibility_for(request.user)
return ForbiddenResponse(object2.fullname()) if not ((request.user == object2.author) or \
(has_access and open_source)):
return ForbiddenResponse("You cannot access the source-code of \"%s\"" % object2.fullname())
# Compute the diff # Compute the diff
serializer = self.get_serializer({'object1': object1, serializer = self.get_serializer({'object1': object1,
......
...@@ -178,7 +178,6 @@ class ListCreateContributionView(IsAuthorOrReadOnlyMixin, ListCreateBaseView): ...@@ -178,7 +178,6 @@ class ListCreateContributionView(IsAuthorOrReadOnlyMixin, ListCreateBaseView):
class DiffView(generics.RetrieveAPIView): class DiffView(generics.RetrieveAPIView):
model = Versionable model = Versionable
permission_classes = [permissions.IsAuthenticated]
serializer_class = DiffSerializer serializer_class = DiffSerializer
def get(self, request, author1, name1, version1, author2, name2, version2): def get(self, request, author1, name1, version1, author2, name2, version2):
......
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
{% comment %} {% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch * Contact: beat.support@idiap.ch
* *
* This file is part of the beat.web module of the BEAT platform. * This file is part of the beat.web module of the BEAT platform.
* *
* Commercial License Usage * Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in * Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you * accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch * and Idiap. For further information contact tto@idiap.ch
* *
* Alternatively, this file may be used under the terms of the GNU Affero * 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 * Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file. * 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 * The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. * or FITNESS FOR A PARTICULAR PURPOSE.
* *
* You should have received a copy of the GNU Affero Public License along * 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/. * with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %} {% endcomment %}
...@@ -129,93 +129,61 @@ function process_diff(lines, editor, diff_line_numbers_classname) ...@@ -129,93 +129,61 @@ function process_diff(lines, editor, diff_line_numbers_classname)
</div> </div>
</div> </div>
<div id="errors" class="row" style="display:none">
<div class="col-sm-offset-1 col-sm-10">
<h2></h2>
<p></p>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
$('#progress').show(); $('#progress').show();
$('h4').hide(); $('h4').hide();
$.get('{% url 'api_libraries:diff' library1_author library1_name library1_version library2_author library2_name library2_version %}') var d = $.get('{% url 'api_libraries:diff' library1_author library1_name library1_version library2_author library2_name library2_version %}');
.done(function(data) {
$('#progress').hide(); d.done(function(data) {
$('h4').show();
var source_code_lines = data.source_code_diff.split('\n')
var code = '';
for (var i = 0; i < source_code_lines.length; ++i)
code += source_code_lines[i].substr(2) + '\n';
var declaration_lines = data.diff.split('\n')
var declaration = '';
for (var i = 0; i < declaration_lines.length; ++i)
declaration += declaration_lines[i].substr(2) + '\n';
var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
})
.fail(function(jqXHR, textStatus, errorThrown) {
$('#progress').hide(); $('#progress').hide();
$('#title').hide(); $('h4').show();
var errors_box = $('.container #errors'); var source_code_lines = data.source_code_diff.split('\n');
if (jqXHR.status == 404) var code = '';
{ for (var i = 0; i < source_code_lines.length; ++i) {
errors_box.find('h2').text('Library not found'); code += source_code_lines[i].substr(2) + '\n';
errors_box.find('p').html("We are sorry, but the library called <strong>" +
jqXHR.responseText + "</strong> could not be found.");
}
else if (jqXHR.status == 401)
{
errors_box.find('h2').text('Unauthorized access');
errors_box.find('p').html("We are sorry, but your aren't authorized to access the library called <strong>" +
jqXHR.responseText + "</strong>.");
} }
else if (jqXHR.responseText.length > 0)
{ var declaration_lines = data.diff.split('\n');
errors_box.find('h2').text(textStatus);
errors_box.find('p').html(jqXHR.responseText); var declaration = '';
} for (var i = 0; i < declaration_lines.length; ++i) {
else declaration += declaration_lines[i].substr(2) + '\n';
{
errors_box.find('h2').text(textStatus);
} }
errors_box.show(); var diff_line_numbers_classname = (Math.log10(Math.max(source_code_lines.length, declaration_lines.length)) > 3 ?
'diff_line_numbers_large' :
'diff_line_numbers');
var code_editor = CodeMirror($('#code_editor_container')[0],
{
value: code,
mode: 'python',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
var declaration_editor = CodeMirror($('#declaration_container')[0],
{
value: declaration,
mode: 'javascript',
readOnly: true,
lineNumbers: false,
gutters: [diff_line_numbers_classname, 'diff_addition_deletion'],
}
);
process_diff(source_code_lines, code_editor, diff_line_numbers_classname);
process_diff(declaration_lines, declaration_editor, diff_line_numbers_classname);
}); });
d.fail(process_error);
}); });
</script> </script>
......
/* /*
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch * Contact: beat.support@idiap.ch
* *
* This file is part of the beat.web module of the BEAT platform. * This file is part of the beat.web module of the BEAT platform.
* *
* Commercial License Usage * Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in * Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you * accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch * and Idiap. For further information contact tto@idiap.ch
* *
* Alternatively, this file may be used under the terms of the GNU Affero * 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 * Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file. * 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 * The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. * or FITNESS FOR A PARTICULAR PURPOSE.
* *
* You should have received a copy of the GNU Affero Public License along * 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/. * with the BEAT platform. If not, see http://www.gnu.org/licenses/.
*/ */
...@@ -131,8 +131,8 @@ function process_error(data, status_text, redirect) { ...@@ -131,8 +131,8 @@ function process_error(data, status_text, redirect) {
type: BootstrapDialog.TYPE_DANGER, type: BootstrapDialog.TYPE_DANGER,
title: 'Error during submission' + ' - ' + data.statusText + ' (' + data.status + ')', title: 'Error during submission' + ' - ' + data.statusText + ' (' + data.status + ')',
message: div, message: div,
onhidden: function() { callback: function(result) {
if (redirect !== undefined) window.location = redirect; if (redirect !== undefined) window.location.href = redirect;
} }
}); });
} }
...@@ -142,8 +142,8 @@ function process_error(data, status_text, redirect) { ...@@ -142,8 +142,8 @@ function process_error(data, status_text, redirect) {
message: 'An empty response was received by your browser, for a request you sent. This normally indicates it cannot establish a connection with the web service. In the hopes it is a temporary issue, you may re-submit your request again at a later moment. Otherwise, please contact the system administrators.', message: 'An empty response was received by your browser, for a request you sent. This normally indicates it cannot establish a connection with the web service. In the hopes it is a temporary issue, you may re-submit your request again at a later moment. Otherwise, please contact the system administrators.',
type: BootstrapDialog.TYPE_DANGER, type: BootstrapDialog.TYPE_DANGER,
title: 'Empty response', title: 'Empty response',
onhidden: function() { callback: function(result) {
if (redirect !== undefined) window.location = redirect; if (redirect !== undefined) window.location.href = redirect;
} }
}); });
} }
...@@ -152,8 +152,8 @@ function process_error(data, status_text, redirect) { ...@@ -152,8 +152,8 @@ function process_error(data, status_text, redirect) {
message: data.responseJSON, message: data.responseJSON,
type: BootstrapDialog.TYPE_DANGER, type: BootstrapDialog.TYPE_DANGER,
title: data.statusText + ' (' + data.status + ')', title: data.statusText + ' (' + data.status + ')',
onhidden: function() { callback: function(result) {
if (redirect !== undefined) window.location = redirect; if (redirect !== undefined) window.location.href = redirect;
} }
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment