Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/src/Authentication/Type/OIDC.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ function authenticateByCode($code)
'samesite' => 'Strict'
);

setcookie($cookie_key, $token, $cookieOpts);
return $this->getUser($token);
$user = $this->getUser($token);

if ($user) {
setcookie($cookie_key, $token, $cookieOpts);
}

return $user;
}

function logout()
Expand Down
6 changes: 4 additions & 2 deletions api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function check()
{
$this->returnResponse(200, $this->generateJwtToken($userId));
}
} else if ($userId === null) {
$this->returnError(403, 'User not recognised');
}
$this->returnError(400, 'No previous session');
}
Expand Down Expand Up @@ -358,7 +360,7 @@ function authorise()

if ($cas_sso) {
header('Location: ' . $this->authenticateByType()->authorise());
$this->returnResponse(302, array('status' => "Redirecting to CAS"));
$this->returnResponse(302, array('status' => "Redirecting to provider"));
} else {
$this->returnError(501, "SSO not configured");
}
Expand All @@ -379,7 +381,7 @@ function authenticateByCode()
}
$this->returnResponse(200, $this->generateJwtToken($fedid));
} else {
$this->returnError(401, 'Invalid Credentials');
$this->returnError(403, 'User not recognised');
}
}

Expand Down
60 changes: 38 additions & 22 deletions api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,24 +1212,6 @@ function _mca($id)
$this->db->close();

$data = array(array(), array());
if (file_exists($info['DAT'])) {
$dat = explode("\n", file_get_contents($info['DAT']));

foreach ($dat as $i => $d) {
if ($i > 2 && $d) {
list($e, $v) = preg_split('/\s+/', trim($d));
if ($i % 2 == 1) {
if (floatval($e) <= $info['ENERGY']) {
if (floatval($e) > ($info['ENERGY'] - 1100))
array_push($data[1], array(floatval($e), floatval($v)));
else
array_push($data[0], array(floatval($e), floatval($v)));
}
}
}
}
}


# pymca
$results = str_replace('.mca', '.results.dat', preg_replace('/(data\/\d\d\d\d\/\w\w\d+-\d+)/', '\1/processed/pymca', $info['DIR']));
Expand All @@ -1238,22 +1220,56 @@ function _mca($id)
$elements = array();
$el_no_match = array();
$max_counts = 0;
$line_number = 0;
$max_elements = 5;
$compton_cutoff = $info['ENERGY'] - 1100;

if (file_exists($results)) {
$dat = explode("\n", file_get_contents($results));
foreach ($dat as $i => $d) {
if ($i < 5) {
foreach ($dat as $d) {
if (empty($d) || strpos($d, '#') === 0) {
if (strpos($d, 'COMPTON_CUTOFF_EV') !== false) {
$parts = explode('COMPTON_CUTOFF_EV', $d);
$compton_cutoff = floatval(trim($parts[1]));
}
continue;
}
if ($line_number < $max_elements) {
$l = explode(' ', $d);
if ($i == 0)
if ($line_number == 0) {
$max_counts = floatval($l[1]);
}
if (array_key_exists($l[0], $el_to_en)) {
$els = $el_to_en[$l[0]];
$elements[$l[0]] = array(array_map('floatval', $els), floatval($l[1]), floatval($l[2]));
} else
} else {
array_push($el_no_match, $l[0]);
}
$line_number++;
} else {
break;
}
}
}

if (file_exists($info['DAT'])) {
$dat = explode("\n", file_get_contents($info['DAT']));

foreach ($dat as $i => $d) {
if ($i > 2 && $d) {
list($e, $v) = preg_split('/\s+/', trim($d));
if ($i % 2 == 1) {
if (floatval($e) <= $info['ENERGY']) {
if (floatval($e) > $compton_cutoff)
array_push($data[1], array(floatval($e), floatval($v)));
else
array_push($data[0], array(floatval($e), floatval($v)));
}
}
}
}
}

array_push($data, $elements);
array_push($data, $el_no_match);
array_push($data, $max_counts);
Expand Down
10 changes: 8 additions & 2 deletions api/src/Page/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,15 @@ function _pipelines() {
$status = $this->has_arg('pipelinestatus') ? $this->arg('pipelinestatus') : null;
$category = $this->has_arg('category') ? $this->arg('category') : null;

// allow more than one status
if ($status) {
$where .= ' AND pp.pipelinestatus=:'.(sizeof($args)+1);
array_push($args, $this->arg('pipelinestatus'));
$status_queries = array();
$status_array = is_array($status) ? $status : array($status);
foreach ($status_array as $s) {
array_push($args, $s);
array_push($status_queries, 'pp.pipelinestatus=:' . count($args));
}
$where .= ' AND (' . implode(' OR ', $status_queries) . ')';
}
if ($category) {
$where .= ' AND ppc.name=:'.(sizeof($args)+1);
Expand Down
4 changes: 2 additions & 2 deletions api/src/Page/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Processing extends Page {
'n' => '\d+',
'sampleGroupId' => '\d+',
'resultCount' => '\d+',
'pipeline' => '[\w\s\+]+',
'pipeline' => '\d+',
'spacegroup' => '(\w|\s|\-|\/)+',
'resolution' => '[\d\.]+',
'completeness' => '[\d\.]+',
Expand Down Expand Up @@ -403,7 +403,7 @@ function _results_for_visit() {

if ($this->has_arg('pipeline')) {
$st = sizeof($args);
$where .= " AND app.processingprograms = :" . ($st + 1);
$where .= " AND app.processingpipelineid = :" . ($st + 1);
array_push($args, $this->arg('pipeline'));
}

Expand Down
12 changes: 6 additions & 6 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ function _get_proposals($id = null)
array_push($args, $id);
}

if ($this->staff) {
if ($this->user->hasPermission('all_dewars')) {
// allow to see shipments on all proposals
} else if ($this->staff) {
if (!$this->user->hasPermission('super_admin')) {
$bls = array();
foreach ($this->user->perms as $p) {
Expand All @@ -172,8 +174,6 @@ function _get_proposals($id = null)
$where .= " AND (shp.personid=:" . (sizeof($args) + 1) . " OR s.beamlinename in ('" . implode("','", $bls) . "'))";
array_push($args, $this->user->personId);
}
} else if ($this->user->hasPermission('all_dewars')) {
// allow to see shipments on all proposals
} else {
$where = " INNER JOIN session_has_person shp ON shp.sessionid = s.sessionid " . $where;
$where .= " AND shp.personid=:" . (sizeof($args) + 1);
Expand Down Expand Up @@ -919,7 +919,9 @@ function _lookup()
$args = array();


if ($this->staff) {
if ($field == 'SHIPPINGID' && $this->user->hasPermission('all_dewars')) {
// allow to see shipments
} else if ($this->staff) {
if (!$this->user->hasPermission('super_admin')) {
$bls = array();
foreach ($this->user->perms as $p) {
Expand All @@ -933,8 +935,6 @@ function _lookup()

$where .= " AND ses.beamlinename in ('" . implode("','", $bls) . "')";
}
} else if ($field == 'SHIPPINGID' && $this->user->hasPermission('all_dewars')) {
// allow to see shipments
} else {
$where = " INNER JOIN session_has_person shp ON shp.sessionid = ses.sessionid " . $where;
$where .= " AND shp.personid=:" . (sizeof($args) + 1);
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Controllers/AuthenticationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testCodeAuthenticationInitiallyFailsWhenAuthenticationTypeReturn
});

$this->assertContains('Content-Type: application/json', Output::$headers);
$this->assertContains('X-PHP-Response-Code: 401', Output::$headers);
$this->assertContains('X-PHP-Response-Code: 403', Output::$headers);
}

public function testCodeAuthenticationWhenGetValidFedIdReturnsSuccess(): void
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/app/store/modules/store.auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const auth = {
},
error: function(req, status, error) {
commit('authError')
reject(error)
reject(req)
},
complete: function() {
commit('loading', false, { root: true })
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/app/views/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default {
.dispatch("auth/getToken", token)
.then(() => this.$router.push(actualRedirectUrl))
.catch((e) => {
if (e === "Forbidden") {
if (e.status === 403) {
this.authError = "not-recognised";
}
});
Expand Down
2 changes: 2 additions & 0 deletions client/src/js/modules/dc/views/dcbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ define(['marionette',
console.log('updateDCC', this.ui.dcglink, this.model)
if (this.model.get('DCC') > 1) {
this.$el.find('li.group').show()
this.$el.find('.gridsize2').show()
this.$el.find('.dcglink').show()
this.$el.find('.dclink').hide()
this.$el.find('.reprocess').hide()
Expand All @@ -95,6 +96,7 @@ define(['marionette',
}
} else {
this.$el.find('li.group').hide()
this.$el.find('.gridsize2').hide()
this.$el.find('.dcglink').hide()
this.$el.find('.dclink').show()
this.$el.find('.reprocess').show()
Expand Down
6 changes: 3 additions & 3 deletions client/src/js/modules/dc/views/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ define(['marionette',
xrcholder: '.holder h1.xrc',
apholder: '.holder h1.ap',
gridsize: '.gridsize',
gridsize2: '.gridsize2',
},

toggleZoom: function(e) {
Expand Down Expand Up @@ -126,9 +127,8 @@ define(['marionette',
if (this.ui.bx.text) this.ui.by.text((gi.get('DY_MM')*1000).toFixed(0))

if (gi.get('STEPS_Y') > 10 && this.ui.zoom.show) this.ui.zoom.show()
var gridsize = gi.get('STEPS_X') + ' x ' + gi.get('STEPS_Y')
if (gi.get('STEPS_Z')) { gridsize += ' x ' + gi.get('STEPS_Z') }
this.ui.gridsize.html(gridsize)
this.ui.gridsize.html(gi.get('STEPS_X') + ' x ' + gi.get('STEPS_Y'))
if (gi.get('STEPS_Z')) { this.ui.gridsize2.html(' x ' + gi.get('STEPS_Z')) }
},

checkXRCandAP: function() {
Expand Down
23 changes: 13 additions & 10 deletions client/src/js/modules/dc/views/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ define(['backbone',
'utils/table',
'utils/kvcollection',
'collections/spacegroups',
'collections/processingpipelines',
'templates/dc/summary.html'],
function(Backbone, Marionette, Backgrid, TableView,
utils,
table,
KVCollection,
Spacegroups,
ProcessingPipelines,
template) {

var Pipelines = Backbone.Collection.extend(_.extend({
Expand Down Expand Up @@ -186,19 +188,20 @@ define(['backbone',
this.updateData()
},

updatePipelines: function() {
this.ui.pipeline.html('<option value="">All pipelines</option>'+this.processing_pipelines.opts())
},

onRender: function() {
this.showSpaceGroups()

this.pipelines = new Pipelines([
{ NAME: 'Any', VALUE: '' },
{ NAME: 'Xia2 DIALS', VALUE: 'xia2 dials' },
{ NAME: 'Xia2 3dii', VALUE: 'xia2 3dii' },
{ NAME: 'Fast DP', VALUE: 'fast_dp' },
{ NAME: 'autoPROC', VALUE: 'autoPROC' },
{ NAME: 'autoPROC+STARANISO', VALUE: 'autoPROC+STARANISO' },
])

this.ui.pipeline.html(this.pipelines.opts())
this.processing_pipelines = new ProcessingPipelines()
this.processing_pipelines.fetch({
data: {
category: 'processing',
pipelinestatus: ['automatic', 'optional'],
}
}).done(this.updatePipelines.bind(this));

var columns = [
{ label: '', cell: table.TemplateCell, editable: false, template: '<a href="/dc/visit/'+this.visit+'/id/<%-ID%>" class="button button-notext"><i class="fa fa-search"></i> <span>View Data Collection</span></a>' },
Expand Down
8 changes: 7 additions & 1 deletion client/src/js/modules/shipment/views/shipments.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ define(['marionette',

return Marionette.LayoutView.extend({
className: 'content',
template: '<div><h1>Shipments</h1><p class="help">This page shows a list of shipments associated with the currently selected proposal</p><p class="help">In order to register your samples you need to create a shipment. Shipments contain dewars, dewars contain containers, and containers individual samples. These can be created sequentially by viewing a particular shipment</p><div class="ra"><a class="button add" href="/shipments/add" data-testid="add-shipment-button"><i class="fa fa-plus"></i> Add Shipment</a></div><div class="wrapper"></div></div>',
template: '<div><h1>Shipments</h1><div id="ebic-banner" class="tw-hidden tw-my-4 tw-p-4 tw-bg-content-active tw-rounded tw-flex tw-justify-between"> <p class="tw-text-md"> eBIC is switching to SCAUP for shipments. <a id="ebic-link" href="">Click here to select a session and create a new shipment.</a></p></div><p class="help">This page shows a list of shipments associated with the currently selected proposal</p><p class="help">In order to register your samples you need to create a shipment. Shipments contain dewars, dewars contain containers, and containers individual samples. These can be created sequentially by viewing a particular shipment</p><div class="ra"><a class="button add" href="/shipments/add" data-testid="add-shipment-button"><i class="fa fa-plus"></i> Add Shipment</a></div><div class="wrapper"></div></div>',
regions: { 'wrap': '.wrapper' },
ui: {
add: 'a.add',
ebicBanner: 'div#ebic-banner',
ebicLink: 'a#ebic-link'
},

initialize: function(options) {
Expand Down Expand Up @@ -71,6 +73,10 @@ define(['marionette',
onRender: function() {
if (app.proposal && app.proposal.get('ACTIVE') != 1) this.ui.add.hide()

if (app.proposal.get("TYPES").includes("em") && "em" in app.options.get("redirects")) {
this.ui.ebicBanner.show();
this.ui.ebicLink.prop("href", `${app.options.get("redirects").em }/proposals/${app.proposal.get("PROPOSAL")}`);
}
this.wrap.show(this.table)
}
})
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/templates/dc/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1 class="title"></h1>
<li>Transmission: <%-TRANSMISSION%>%</li>
<li>Beamsize: <%-BSX%>x<%-BSY%>&mu;m</li>
<li>Boxsize: <span class="boxx"></span>x<span class="boxy"></span>&mu;m</li>
<li>Grid scan size: <span class="gridsize"></span></li>
<li>Grid scan size: <span class="gridsize"></span><span class="gridsize2"></span></li>
<li class="comment">Comment: <span class="COMMENTS"><%-COMMENTS%></span></li>
<% if (!STATE) { %><li>Status: <span class="b">Stopped</span></li><% } %>

Expand Down
Loading