Permalink
Browse files

Finishing implementation of "view as user" feature for admin

Altered workflow run status view to show runs for user id and backend controller to take uid parameter. Processing events for toggling the "viewing as user" alerts and routing of views.
  • Loading branch information...
lowery committed Dec 4, 2017
1 parent de4a2f5 commit 024efeff362398a70fca6e62d71ea7fbe4e788b6
@@ -486,10 +486,15 @@ public Result removeRuns() {
* @return
*/
@SubjectPresent
public Result status() {
public Result status(Long uid) {
System.out.println(uid);

List<RunResult> results = new ArrayList<>();
List<WorkflowRun> userRuns = workflowDao.findUserWorkflowRuns(session("uid"));
List<WorkflowRun> sharedRuns = userAccessDao.findSharedRunsByUser(Long.parseLong(session("uid")));
//List<WorkflowRun> userRuns = workflowDao.findUserWorkflowRuns(session("uid"));
//List<WorkflowRun> sharedRuns = userAccessDao.findSharedRunsByUser(Long.parseLong(session("uid")));

List<WorkflowRun> userRuns = workflowDao.findUserWorkflowRuns(uid);
List<WorkflowRun> sharedRuns = userAccessDao.findSharedRunsByUser(uid);

List<WorkflowRun> runs = new ArrayList<>();
runs.addAll(userRuns);
@@ -71,7 +71,7 @@ public WorkflowRun findWorkflowRunById(long id) {
return run;
}

public List<WorkflowRun> findUserWorkflowRuns(String uid) {
public List<WorkflowRun> findUserWorkflowRuns(Long uid) {
return WorkflowRun.find.where().eq("owner.id", uid).findList();
}

@@ -70,7 +70,7 @@ <h4 class="modal-title" id="myModalLabel">Select User</h4>
<p>Start entering a username below and select to temporarily view runs as that user.</p>
<div class="ui-widget">
<label for="user-select">Username</label>
<input id="user-select">
<input id="user-select" /><input type="hidden" id="user-select-id" />
</div>
</form>
</div>
@@ -67,8 +67,8 @@ POST /files/delete/:id controllers.Workflows.deleteUplo

# Workflow run routes for managing user runs and artifacts (result, report, logs)
# ~~~~
GET /results controllers.Workflows.status()
PUT /results/:id controllers.Workflows.shareRun(id: Long)
GET /results/:uid controllers.Workflows.status(uid: Long)
PUT /results/:uid controllers.Workflows.shareRun(uid: Long)

GET /run/result/*id controllers.Workflows.resultArtifacts(id : Long)
GET /run/archive/*id controllers.Workflows.resultArchive(id : Long)
@@ -76,20 +76,34 @@ require([
app.currentGroups = new GroupCollection();
app.currentUsers = new Users();

app.router.on("route:status", function () {
var viewAsSelf = function () {
$('#view-as-text').html('');
$('#page-alert').html('');
$('#view-as-self').hide();
$('#view-as-user').show();
};

var viewAsUser = function (uid, username) {
$('#view-as-text').html('<span class="label label-warning" style="font-size: .9em">Viewing as <i>' + username + '</i></span>');
$('#page-alert').html('<div class="alert alert-warning alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Viewing workflows page as ' + username + '.</strong> Navigating away from the workflows page will restore view state to the currently logged in user.</div>');
$('#view-as-user').hide();
$('#view-as-self').show();
};

app.router.on("route:status", function (uid) {
$(".nav-pills li").removeClass("active");
$('.status-pill').addClass('active');

$('.breadcrumb .active').remove();
$('.breadcrumb').append('<li class="active"><a href="#status">Status</a></li>');

//if (app.view_as) {
// runs.uid = app.view_as;
//} else {
//runs.uid = window.uid;
//}
// Default is to view workflow runs as currently logged in user

if (!uid) {
uid = app.session.get('uid');
}

var statusView = new RunStatusView({ uid: app.session.get('uid') });
var statusView = new RunStatusView({ uid: uid, onClose: viewAsSelf });
this.navigateToView(statusView);
});

@@ -179,11 +193,21 @@ require([
model.fetch({
success: function (data) {
var users = data.toJSON().map(function (user) {
return user.username;
return {
'id': user.id,
'label': user.username,
'value': user.username
};
});

$("#user-select").autocomplete({
source: users
source: users,
select: function( event, ui ) {
$(this).val(ui.item.label);

$("#user-select-id").val(ui.item.id);
return false;
}
});
}
});
@@ -196,8 +220,12 @@ require([
});

$('#user-select-btn').click(function (event) {
console.log($('#user-select').val());
var username = $('#user-select').val();
var uid = $('#user-select-id').val();

app.router.navigate("/status/" + uid, {trigger: true});

viewAsUser(uid, username);
/*var userlist = new Users();
userlist.fetch({
success: function (data) {
@@ -230,22 +258,9 @@ require([
$('#user-select-modal').modal('toggle');
});

$('#view-as-self').click(function (event) {
$('#view-as-text').html('');
$('#page-alert').html('<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>View state reset to logged in user.</strong> Viewing workflows page as current user.</div>');
$(this).toggle();
$('#view-as-user').toggle();

delete app.view_as;

// TODO: reset view differently, this is a hack for now
if (app.router.currentView instanceof WorkflowRunsView) {
var runs = new WorkflowRuns();
//runs.uid = window.uid;

var statusView = new WorkflowRunsView({collection: runs });
app.router.navigateToView(statusView);
}
$('#view-as-self').click(function (event) {
app.router.navigate('/status', {trigger: true});
});

});
@@ -7,7 +7,7 @@ define([
routes: {
"run": 'workflow',
"workflow/:name": "run",
"status": 'status',
"status(/:uid)": 'status',
"users": 'users',
"runs/:uid": "runs",
"deploy": 'deploy',
@@ -6,14 +6,15 @@ define([
'views/result',
'views/run',
'views/sharerun',
'app',
'text!templates/runs.html'
], function ($, _, Backbone, ResultModel, ResultView, RunView, ShareView, app, runsTpl) {
], function ($, _, Backbone, ResultModel, ResultView, RunView, ShareView, runsTpl) {

var RunsView = Backbone.View.extend({
template: _.template(runsTpl),

initialize: function () {
initialize: function (options) {
this.options = options;

this.views = [];
this.selected = [];

@@ -34,7 +35,8 @@ define([
this.$el.html(this.template({ }));

this.collection.each(function (run) {
if (run.get('owner').id == app.session.get('uid')) {
//if (run.get('owner').id == app.session.get('uid')) {
if (run.get('owner').id == this.options.uid) {
if (this.selected.includes(run)) {
run.set('selected', true);
}
@@ -31,11 +31,11 @@ define([
this.$el.html(this.template({}));

this.runs = new Runs({ 'uid': this.options.uid });
this.runsView = new RunsView({ collection: this.runs, el: this.$('#user-runs') });
this.runsView = new RunsView({ collection: this.runs, el: this.$('#user-runs'), uid: this.options.uid });
this.listenTo(this.runsView, 'selectionChange', this.renderControls);
this.listenTo(this.runsView, 'addedUserRun', this.addedUserRun);

this.sharedView = new SharedRunsView({ collection: this.runs, el: this.$('#shared-runs') });
this.sharedView = new SharedRunsView({ collection: this.runs, el: this.$('#shared-runs'), uid: this.options.uid });
this.listenTo(this.sharedView, 'addedSharedRun', this.addedSharedRun);

return this;
@@ -71,6 +71,16 @@ define([

addedSharedRun: function (e) {
this.$('.shared-runs-count').html(e.count);
},

onBeforeClose: function () {
this.runsView.onBeforeClose();
this.sharedView.onBeforeClose();

// Callback for main
if (this.options.onClose) {
this.options.onClose();
}
}
});

@@ -4,14 +4,15 @@ define([
'backbone',
'views/sharedrun',
'views/result',
'app',
'text!templates/sharedruns.html'
], function ($, _, Backbone, SharedRunView, ResultView, app, sharedTpl) {
], function ($, _, Backbone, SharedRunView, ResultView, sharedTpl) {

var SharedRunsView = Backbone.View.extend({
template: _.template(sharedTpl),

initialize: function () {
initialize: function (options) {
this.options = options;

this.views = [];
this.count = 0;

@@ -32,7 +33,7 @@ define([
this.$el.html(this.template({ }));

this.collection.each(function (run) {
if (!(run.get('owner').id == app.session.get('uid'))) {
if (!(run.get('owner').id == this.options.uid)) {
this.addRun(run);
}
}, this);

0 comments on commit 024efef

Please sign in to comment.