feat(openid-connect): Switch to generic OIDC Client library instead of using Keycloak.js (#273)
This commit is contained in:
1 parent
2f05ed5961
commit
18bcf83805
70 files changed
+572
-655
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Random } from 'meteor/random';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
// Local imports
|
||||
import { removeFromArray } from '../lib/removeFromArray';
|
||||
@@ -39,9 +40,9 @@ HP.Protocol = class Protocol {
|
||||
|
||||
// If we are logged in while creating this Protocol,
|
||||
// store this information as well
|
||||
if (Meteor.users && Meteor.userId) {
|
||||
this.createdBy = Meteor.userId;
|
||||
this.modifiedBy = Meteor.userId;
|
||||
if (OHIF.user && OHIF.user.userLoggedIn && OHIF.user.userLoggedIn()) {
|
||||
this.createdBy = OHIF.user.getUserId();
|
||||
this.modifiedBy = OHIF.user.getUserId();
|
||||
}
|
||||
|
||||
// Create two empty Sets specifying which roles
|
||||
@@ -107,8 +108,8 @@ HP.Protocol = class Protocol {
|
||||
protocolWasModified() {
|
||||
// If we are logged in while modifying this Protocol,
|
||||
// store this information as well
|
||||
if (Meteor.users && Meteor.userId) {
|
||||
this.modifiedBy = Meteor.userId;
|
||||
if (OHIF.user && OHIF.user.userLoggedIn && OHIF.user.userLoggedIn()) {
|
||||
this.modifiedBy = OHIF.user.getUserId();
|
||||
}
|
||||
|
||||
// Protocol has been modified, so mark priors information
|
||||
@@ -240,4 +241,4 @@ HP.Protocol = class Protocol {
|
||||
this.protocolWasModified();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -157,4 +157,155 @@ var defaultStrategy = (function () {
|
||||
|
||||
})();
|
||||
|
||||
HP.ProtocolStore.setStrategy(defaultStrategy);
|
||||
var clientOnlyStrategy = (function () {
|
||||
const HangingProtocols = new Mongo.Collection(null);
|
||||
|
||||
let defaultsAdded = false;
|
||||
|
||||
function addDefaultProtocols() {
|
||||
console.log('Inserting default protocols');
|
||||
|
||||
addProtocol(HP.defaultProtocol);
|
||||
|
||||
defaultsAdded = true;
|
||||
}
|
||||
|
||||
function getDatabaseIdByProtocolId(protocolId) {
|
||||
const filteredProtocol = HangingProtocols.findOne({
|
||||
id: protocolId
|
||||
}, {
|
||||
fields: {
|
||||
_id: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!filteredProtocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
return filteredProtocol._id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a function to be called when the hangingprotocols collection is subscribed
|
||||
* The callback is called only one time when the subscription is ready
|
||||
*
|
||||
* @param callback The function to be called as a callback
|
||||
*/
|
||||
function onReady(callback) {
|
||||
if (!defaultsAdded) {
|
||||
addDefaultProtocols();
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hanging protocol by protocolId if defined, otherwise all stored hanging protocols
|
||||
*
|
||||
* @param protocolId The protocol ID used to find the hanging protocol
|
||||
* @returns {object|array} The hanging protocol by protocolId or array of the stored hanging protocols
|
||||
*/
|
||||
function getProtocol(protocolId) {
|
||||
// Return the hanging protocol by protocolId if defined
|
||||
if (protocolId) {
|
||||
return HangingProtocols.findOne({
|
||||
id: protocolId
|
||||
});
|
||||
}
|
||||
|
||||
// Otherwise, return all protocols
|
||||
return HangingProtocols.find().fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the hanging protocol
|
||||
*
|
||||
* @param protocol The hanging protocol to be stored
|
||||
*/
|
||||
function addProtocol(protocol) {
|
||||
// Collections can only be updated by database ID (_id) on client, so
|
||||
// get the database ID (_id) by the hanging protocol ID firstly
|
||||
const databaseId = getDatabaseIdByProtocolId(protocol.id);
|
||||
|
||||
// Remove any MongoDB ID the protocol may have had
|
||||
delete protocol._id;
|
||||
|
||||
// Update the protocol with the same id if exists instead of inserting this protocol
|
||||
if (databaseId) {
|
||||
// Update the hanging protocol by the database ID
|
||||
HangingProtocols.update(databaseId, {
|
||||
$set: protocol
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert the protocol
|
||||
HangingProtocols.insert(protocol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the hanging protocol by protocolId
|
||||
*
|
||||
* @param protocolId The protocol ID used to find the hanging protocol to update
|
||||
* @param protocol The updated hanging protocol
|
||||
*/
|
||||
function updateProtocol(protocolId, protocol) {
|
||||
// Collections can only be updated by database ID (_id) on client, so
|
||||
// get the database ID (_id) by the hanging protocol ID firstly
|
||||
const databaseId = getDatabaseIdByProtocolId(protocolId);
|
||||
|
||||
// Skip if it does not exist in database
|
||||
if (!databaseId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any MongoDB ID the protocol may have had
|
||||
delete protocol._id;
|
||||
|
||||
// Update the hanging protocol by the database ID
|
||||
HangingProtocols.update(databaseId, {
|
||||
$set: protocol
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the hanging protocol
|
||||
*
|
||||
* @param protocolId The protocol ID used to remove the hanging protocol
|
||||
*/
|
||||
function removeProtocol(protocolId) {
|
||||
// Collections can only be removed by database ID (_id) on client, so
|
||||
// get the database ID (_id) by the hanging protocol ID firstly
|
||||
const databaseId = getDatabaseIdByProtocolId(protocolId);
|
||||
|
||||
// Skip if it does not exist in database
|
||||
if (!databaseId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the hanging protocol by the database ID
|
||||
HangingProtocols.remove(databaseId);
|
||||
}
|
||||
|
||||
// Module Exports
|
||||
return {
|
||||
onReady: onReady,
|
||||
getProtocol: getProtocol,
|
||||
addProtocol: addProtocol,
|
||||
updateProtocol: updateProtocol,
|
||||
removeProtocol: removeProtocol
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
// If we are running a disconnect client similar to the StandaloneViewer
|
||||
// (see https://docs.ohif.org/standalone-viewer/usage.html) we don't want
|
||||
// our HangingProtocol strategy to try to use Meteor methods or Pub / Sub
|
||||
if (Meteor.status().connected === true) {
|
||||
HP.ProtocolStore.setStrategy(defaultStrategy);
|
||||
} else {
|
||||
HP.ProtocolStore.setStrategy(clientOnlyStrategy);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ Package.onUse(function(api) {
|
||||
api.use('validatejs');
|
||||
|
||||
// Our custom packages
|
||||
api.use('ohif:core');
|
||||
api.use('ohif:viewerbase');
|
||||
|
||||
api.addAssets('assets/dots.svg', 'client');
|
||||
|
||||
Reference in new issue
Block a user