Skip to content

Commit

Permalink
Merge branch 'ontoportal-lirmm-users-administation-patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
jvendetti committed Jun 8, 2021
2 parents fc7948a + 26f9c21 commit 0820bca
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 56 deletions.
Empty file.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//= require bp_search
//= require bp_mappings
//= require bp_visualize
//= require admin/users
//= require bp_admin
//= require bp_recommender
//= require bp_property_tree
Expand Down
192 changes: 187 additions & 5 deletions app/assets/javascripts/bp_admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* Created by mdorf on 3/27/15.
* Updated by Syphax.Bouazzouni on 28/04/21 , users admin part
*/


var DUMMY_ONTOLOGY = "DUMMY_ONT";
if (window.BP_CONFIG === undefined) {
window.BP_CONFIG = jQuery(document).data().bp.config;
Expand Down Expand Up @@ -33,7 +36,7 @@ function parseReportDate(dateStr) {
return dateObj.toLocaleString([], {month: '2-digit', day: '2-digit', year: 'numeric', hour: '2-digit', minute:'2-digit'});
}

var AjaxAction = function(httpMethod, operation, path, isLongOperation, params) {
let AjaxAction = function(httpMethod, operation, path, isLongOperation, params) {
params = params || {};
this.httpMethod = httpMethod;
this.operation = operation;
Expand Down Expand Up @@ -764,6 +767,7 @@ function showOntologiesToggleLinks(problemOnly) {
jQuery(".admin.index").ready(function() {
// display ontologies table on load
displayOntologies({}, DUMMY_ONTOLOGY);
displayUsers({});
UpdateCheck.act();

// make sure facebox window is empty before populating it
Expand Down Expand Up @@ -817,7 +821,10 @@ jQuery(".admin.index").ready(function() {
jQuery(this).toggleClass('selected');
}
});
jQuery('#adminUsers').on('click', '.delete-user', function(event) {
DeleteUsers.act(jQuery(this).parents('tr').first()[0].id.split('_').pop())

});
// BUTTON onclick actions ---------------------------------------

// onclick action for "Go" button for performing an action on a set of ontologies
Expand Down Expand Up @@ -846,14 +853,189 @@ jQuery(".admin.index").ready(function() {
});

// onclick action for "Refresh Report" button
jQuery("#refresh_report_action").click(function() {
RefreshReport.act();
});
jQuery("#refresh_report_action").click(function() {
RefreshReport.act();
});

// onclick action for "Update Check" button
jQuery("#update_check_action").click(function() {
UpdateCheck.act(true);
});

// end: BUTTON onclick actions -----------------------------------
});
});


/* users part */
function populateUserRows(data) {
let users = data['users'];
let allRows = [];
// let hideFields = ["format", "administeredBy", "date_created", "report_date_updated", "errErrorStatus", "errMissingStatus", "problem", "logFilePath"];
users.forEach(user =>{
let id = '<a href="'+ user['@id']+'" >' + user['@id'] + '</a>';
let email = user['email'];
let username = user['username'];
let roles = user['role'];
let firstname = user['firstName']
let lastname = user['lastName']
let created = user['created']
let actions = [
'<a href="/accounts/'+ user['username'] +'" class="mx-1">Detail</a>' ,
'<a href="javascript:;" class="delete-user mx-1">Delete</a>',
'<a href="/login_as/'+ username +'" class="mx-1">Login as</a>',

]
let row = [firstname, lastname, username, email , roles , id , created , actions.join('|')];
allRows.push(row);
})

return allRows;
}

function displayUsers(data) {
let ontTable = null;
let allRows
if (jQuery.fn.dataTable.isDataTable('#adminUsers')) {
ontTable = jQuery('#adminUsers').DataTable();

if (ontology === DUMMY_ONTOLOGY) {
// refreshing entire table
allRows = populateUserRows(data);
ontTable.clear();
ontTable.rows.add(allRows);
ontTable.draw();
} else {
// refreshing individual row
}
} else {
ontTable = jQuery("#adminUsers").DataTable({
"ajax": {
"url": "/admin/users",
"contentType": "application/json",
"dataSrc": function (json) {
return populateUserRows(json);
}
},
"rowCallback": function(row, data, index) {
var acronym = jQuery('td:nth-child(3)', row).text();

jQuery(row).attr("id", "tr_" + acronym);
if (data[data.length - 1] === true) {
jQuery(row).addClass("problem");
}
},
"initComplete": function(settings, json) {
},
"columnDefs": [
{
"targets": 0,
"searchable": true,
"title": "First Name",
},
{
"targets": 1,
"searchable": true,
"title": "Last Name",
},
{
"targets": 2,
"searchable": true,
"title": "Username",
},
{
"targets": 3,
"searchable": true,
"title": "Email",
},
{
"targets": 4,
"searchable": true,
"title": "Roles",
},
{
"targets": 5,
"searchable": true,
"orderable": false,
"title": "Id",
},
{
"targets": 6,
"searchable": true,
"orderable": true,
"title": "Created at",
},
{
"targets": 7,
"searchable": false,
"orderable": false,
"title": "Actions",
"width": "210px"
}
],
"autoWidth": false,
"lengthChange": false,
"searching": true,
"language": {
"search": "Filter: ",
"emptyTable": "No users available"
},
"info": true,
"paging": true,
"pageLength": 100,
"ordering": true,
"responsive": true,
"stripeClasses": ["", "alt"],
});
}
return ontTable;
}

function DeleteUsers(user) {
AjaxAction.call(this, "DELETE", "USERS DELETION", "accounts/"+user, false);
this.setConfirmMsg("You are about to delete the following user: '" + user + "' <b>This action CAN NOT be undone!!! Are you sure?</b>");
}

DeleteUsers.prototype = Object.create(AjaxAction.prototype);
DeleteUsers.prototype.constructor = DeleteUsers;
DeleteUsers.prototype.onSuccessAction = function(username) {
let ontTable = jQuery('#adminUsers').DataTable();
ontTable.row(jQuery("#tr_" + username)).remove().draw();
};

DeleteUsers.prototype._ajaxCall = function (username) {
let errors = [];
let success = [];
let notices = [];
jQuery.ajax({
method: 'DELETE',
url: 'accounts/'+username,
data: [],
dataType: "json",
success: (data, msg) => {
success.push('Users deleted successfully')
this.onSuccessAction(username)
_showStatusMessages(success, errors, notices, false);
},
error: function(request, textStatus, errorThrown) {
console.log('error')
errorState = true;
errors.push(request.status + ": " + errorThrown);
_showStatusMessages(success, errors, notices, false);
},
complete: function(request, textStatus) {

}
});

}

DeleteUsers.prototype.ajaxCall = function (username){
alertify.confirm(this.confirmMsg, (e) => {
if (e) {
this._ajaxCall(username);
}
});
}
DeleteUsers.act = function(user) {
new DeleteUsers(user).ajaxCall(user);
};
7 changes: 5 additions & 2 deletions app/assets/javascripts/bp_ontolobridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ function clearStatusMessages() {

function showStatusMessages(success, error) {
if (success.length > 0) {
jQuery("#ob_success_message").html(success);
jQuery("#ob_success_message").show();
let ob = jQuery("#ob_success_message")
console.log('show ob message')
console.log(ob)
ob.html(success);
ob.show();
}

if (error.length > 0) {
Expand Down
23 changes: 22 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

class AdminController < ApplicationController
layout :determine_layout
before_action :cache_setup

DEBUG_BLACKLIST = [:"$,", :$ADDITIONAL_ONTOLOGY_DETAILS, :$rdebug_state, :$PROGRAM_NAME, :$LOADED_FEATURES, :$KCODE, :$-i, :$rails_rake_task, :$$, :$gems_build_rake_task, :$daemons_stop_proc, :$VERBOSE, :$DAEMONS_ARGV, :$daemons_sigterm, :$DEBUG_BEFORE, :$stdout, :$-0, :$-l, :$-I, :$DEBUG, :$', :$gems_rake_task, :$_, :$CODERAY_DEBUG, :$-F, :$", :$0, :$=, :$FILENAME, :$?, :$!, :$rdebug_in_irb, :$-K, :$TESTING, :$fileutils_rb_have_lchmod, :$EMAIL_EXCEPTIONS, :$binding, :$-v, :$>, :$SAFE, :$/, :$fileutils_rb_have_lchown, :$-p, :$-W, :$:, :$__dbg_interface, :$stderr, :$\, :$&, :$<, :$debug, :$;, :$~, :$-a, :$DEBUG_RDOC, :$CGI_ENV, :$LOAD_PATH, :$-d, :$*, :$., :$-w, :$+, :$@, :$`, :$stdin, :$1, :$2, :$3, :$4, :$5, :$6, :$7, :$8, :$9]
ADMIN_URL = "#{LinkedData::Client.settings.rest_url}/admin/"
ONTOLOGIES_URL = "#{ADMIN_URL}ontologies_report"
USERS_URL = "#{LinkedData::Client.settings.rest_url}/users"
ONTOLOGY_URL = lambda { |acronym| "#{ADMIN_URL}ontologies/#{acronym}" }
PARSE_LOG_URL = lambda { |acronym| "#{ONTOLOGY_URL.call(acronym)}/log" }
REPORT_NEVER_GENERATED = "NEVER GENERATED"

def index
@users = LinkedData::Client::Models::User.all
if session[:user].nil? || !session[:user].admin?
redirect_to :controller => 'login', :action => 'index', :redirect => '/admin'
else
Expand Down Expand Up @@ -200,6 +201,12 @@ def delete_submission
render :json => response
end

def users
response = _users
render :json => response
end


private

def cache_setup
Expand Down Expand Up @@ -287,4 +294,18 @@ def _process_ontologies(success_keyword, error_keyword, process_proc)
render :json => response
end

def _users
response = {users: Hash.new , errors: '', success: ''}
start = Time.now
begin
response[:users] = JSON.parse(LinkedData::Client::HTTP.get(USERS_URL, {include: 'all'}, raw: true))

response[:success] = "users successfully retrieved in #{Time.now - start}s"
LOG.add :debug, "Users - retrieved #{response[:users].length} users in #{Time.now - start}s"
rescue Exception => e
response[:errors] = "Problem retrieving users - #{e.message}"
end
response
end

end
5 changes: 3 additions & 2 deletions app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def create
logged_in_user = LinkedData::Client::Models::User.authenticate(params[:user][:username], params[:user][:password])
if logged_in_user && !logged_in_user.errors
login(logged_in_user)

redirect = "/"

if session[:redirect]
redirect = CGI.unescape(session[:redirect])
end


redirect_to redirect
else
@errors << "Invalid account name/password combination"
Expand All @@ -54,7 +54,8 @@ def login_as
session[:user].apikey = session[:admin_user].apikey
end

redirect_to request.referer rescue redirect_to "/"
#redirect_to request.referer rescue redirect_to "/"
redirect_to "/"
end

# logs out a user
Expand Down
Loading

0 comments on commit 0820bca

Please sign in to comment.