mirror of
https://github.com/nasa/openmct.git
synced 2025-05-11 04:52:57 +00:00
Merge remote-tracking branch 'upstream/master' into mobile_ins
This commit is contained in:
commit
c85cec0445
@ -18,6 +18,7 @@
|
|||||||
"platform/features/scrolling",
|
"platform/features/scrolling",
|
||||||
"platform/features/events",
|
"platform/features/events",
|
||||||
"platform/forms",
|
"platform/forms",
|
||||||
|
"platform/identity",
|
||||||
"platform/persistence/queue",
|
"platform/persistence/queue",
|
||||||
"platform/policy",
|
"platform/policy",
|
||||||
"platform/entanglement",
|
"platform/entanglement",
|
||||||
|
12
example/identity/bundle.json
Normal file
12
example/identity/bundle.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extensions": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"implementation": "ExampleIdentityService.js",
|
||||||
|
"provides": "identityService",
|
||||||
|
"type": "provider",
|
||||||
|
"depends": [ "dialogService" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
75
example/identity/src/ExampleIdentityService.js
Normal file
75
example/identity/src/ExampleIdentityService.js
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var DEFAULT_IDENTITY = { key: "user", name: "Example User" },
|
||||||
|
DIALOG_STRUCTURE = {
|
||||||
|
name: "Identify Yourself",
|
||||||
|
sections: [{ rows: [
|
||||||
|
{
|
||||||
|
name: "User ID",
|
||||||
|
control: "textfield",
|
||||||
|
key: "key",
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Human name",
|
||||||
|
control: "textfield",
|
||||||
|
key: "name",
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
]}]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example implementation of an identity service. This prompts the
|
||||||
|
* user to enter a name and user ID; in a more realistic
|
||||||
|
* implementation, this would be read from a server, possibly
|
||||||
|
* prompting for a user name and password (or similar) as
|
||||||
|
* appropriate.
|
||||||
|
*
|
||||||
|
* @implements {IdentityService}
|
||||||
|
* @memberof platform/identity
|
||||||
|
*/
|
||||||
|
function ExampleIdentityProvider(dialogService) {
|
||||||
|
// Handle rejected dialog messages by treating the
|
||||||
|
// current user as undefined.
|
||||||
|
function echo(v) { return v; }
|
||||||
|
function giveUndefined() { return undefined; }
|
||||||
|
|
||||||
|
this.userPromise =
|
||||||
|
dialogService.getUserInput(DIALOG_STRUCTURE, DEFAULT_IDENTITY)
|
||||||
|
.then(echo, giveUndefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleIdentityProvider.prototype.getUser = function () {
|
||||||
|
return this.userPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
return ExampleIdentityProvider;
|
||||||
|
}
|
||||||
|
);
|
@ -93,11 +93,6 @@
|
|||||||
{
|
{
|
||||||
"key": "navigationService",
|
"key": "navigationService",
|
||||||
"implementation": "navigation/NavigationService.js"
|
"implementation": "navigation/NavigationService.js"
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "creationService",
|
|
||||||
"implementation": "creation/CreationService.js",
|
|
||||||
"depends": [ "persistenceService", "$q", "$log" ]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"actions": [
|
"actions": [
|
||||||
@ -115,7 +110,7 @@
|
|||||||
"depends": [ "urlService", "$window" ],
|
"depends": [ "urlService", "$window" ],
|
||||||
"group": "windowing",
|
"group": "windowing",
|
||||||
"glyph": "y",
|
"glyph": "y",
|
||||||
"priority": "preferred"
|
"priority": "preferred"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "fullscreen",
|
"key": "fullscreen",
|
||||||
@ -123,7 +118,7 @@
|
|||||||
"category": "view-control",
|
"category": "view-control",
|
||||||
"group": "windowing",
|
"group": "windowing",
|
||||||
"glyph": "z",
|
"glyph": "z",
|
||||||
"priority": "default"
|
"priority": "default"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"views": [
|
"views": [
|
||||||
@ -146,6 +141,13 @@
|
|||||||
"type": "provider",
|
"type": "provider",
|
||||||
"implementation": "creation/CreateActionProvider.js",
|
"implementation": "creation/CreateActionProvider.js",
|
||||||
"depends": [ "typeService", "dialogService", "creationService", "policyService" ]
|
"depends": [ "typeService", "dialogService", "creationService", "policyService" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "CreationService",
|
||||||
|
"provides": "creationService",
|
||||||
|
"type": "provider",
|
||||||
|
"implementation": "creation/CreationService.js",
|
||||||
|
"depends": [ "persistenceService", "$q", "$log" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"runs": [
|
"runs": [
|
||||||
|
@ -59,10 +59,10 @@ define(
|
|||||||
var locatingType = locatingObject &&
|
var locatingType = locatingObject &&
|
||||||
locatingObject.getCapability('type');
|
locatingObject.getCapability('type');
|
||||||
return locatingType && policyService.allow(
|
return locatingType && policyService.allow(
|
||||||
"composition",
|
"composition",
|
||||||
locatingType,
|
locatingType,
|
||||||
type
|
type
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sections.push({
|
sections.push({
|
||||||
@ -77,6 +77,9 @@ define(
|
|||||||
row.key = index;
|
row.key = index;
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
|
}).filter(function (row) {
|
||||||
|
// Only show rows which have defined controls
|
||||||
|
return row && row.control;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ define(
|
|||||||
* space an object is created within (as it is possible to
|
* space an object is created within (as it is possible to
|
||||||
* have multiple persistence spaces attached.)
|
* have multiple persistence spaces attached.)
|
||||||
*
|
*
|
||||||
|
* Note that the model passed in for object creation may be
|
||||||
|
* modified to attach additional initial properties associated
|
||||||
|
* with domain object creation.
|
||||||
|
*
|
||||||
* @param {object} model the model for the newly-created
|
* @param {object} model the model for the newly-created
|
||||||
* domain object
|
* domain object
|
||||||
* @param {DomainObject} parent the domain object which
|
* @param {DomainObject} parent the domain object which
|
||||||
@ -67,12 +71,6 @@ define(
|
|||||||
var persistence = parent.getCapability("persistence"),
|
var persistence = parent.getCapability("persistence"),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
// Store the location of an object relative to it's parent.
|
|
||||||
function addLocationToModel(modelId, model, parent) {
|
|
||||||
model.location = parent.getId();
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Persist the new domain object's model; it will be fully
|
// Persist the new domain object's model; it will be fully
|
||||||
// constituted as a domain object when loaded back, as all
|
// constituted as a domain object when loaded back, as all
|
||||||
// domain object models are.
|
// domain object models are.
|
||||||
@ -135,7 +133,6 @@ define(
|
|||||||
// 2. Create a model with that ID in the persistence space
|
// 2. Create a model with that ID in the persistence space
|
||||||
// 3. Add that ID to
|
// 3. Add that ID to
|
||||||
return self.$q.when(uuid()).then(function (id) {
|
return self.$q.when(uuid()).then(function (id) {
|
||||||
model = addLocationToModel(id, model, parent);
|
|
||||||
return doPersist(persistence.getSpace(), id, model);
|
return doPersist(persistence.getSpace(), id, model);
|
||||||
}).then(function (id) {
|
}).then(function (id) {
|
||||||
return addToComposition(id, parent, persistence);
|
return addToComposition(id, parent, persistence);
|
||||||
|
@ -42,7 +42,9 @@ define(
|
|||||||
"property" + name,
|
"property" + name,
|
||||||
[ "getDefinition", "getValue", "setValue" ]
|
[ "getDefinition", "getValue", "setValue" ]
|
||||||
);
|
);
|
||||||
mockProperty.getDefinition.andReturn({});
|
mockProperty.getDefinition.andReturn({
|
||||||
|
control: "textfield"
|
||||||
|
});
|
||||||
mockProperty.getValue.andReturn(name);
|
mockProperty.getValue.andReturn(name);
|
||||||
return mockProperty;
|
return mockProperty;
|
||||||
}
|
}
|
||||||
|
@ -201,16 +201,6 @@ define(
|
|||||||
expect(mockLog.error).toHaveBeenCalled();
|
expect(mockLog.error).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("stores location on new domainObjects", function () {
|
|
||||||
var model = { name: "my model" },
|
|
||||||
objectPromise = creationService.createObject(
|
|
||||||
model,
|
|
||||||
mockParentObject
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(model.location).toBe('parentId');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -50,8 +50,8 @@ define(
|
|||||||
|
|
||||||
function formatTimestamp(timestamp) {
|
function formatTimestamp(timestamp) {
|
||||||
return typeof timestamp === 'number' ?
|
return typeof timestamp === 'number' ?
|
||||||
(moment.utc(timestamp).format(TIME_FORMAT) + " UTC") :
|
(moment.utc(timestamp).format(TIME_FORMAT) + " UTC") :
|
||||||
undefined;
|
undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProperties() {
|
function getProperties() {
|
||||||
|
@ -72,7 +72,12 @@ define(
|
|||||||
*/
|
*/
|
||||||
PersistenceCapability.prototype.persist = function () {
|
PersistenceCapability.prototype.persist = function () {
|
||||||
var domainObject = this.domainObject,
|
var domainObject = this.domainObject,
|
||||||
modified = domainObject.getModel().modified;
|
model = domainObject.getModel(),
|
||||||
|
modified = model.modified,
|
||||||
|
persistenceService = this.persistenceService,
|
||||||
|
persistenceFn = model.persisted !== undefined ?
|
||||||
|
this.persistenceService.updateObject :
|
||||||
|
this.persistenceService.createObject;
|
||||||
|
|
||||||
// Update persistence timestamp...
|
// Update persistence timestamp...
|
||||||
domainObject.useCapability("mutation", function (model) {
|
domainObject.useCapability("mutation", function (model) {
|
||||||
@ -80,11 +85,11 @@ define(
|
|||||||
}, modified);
|
}, modified);
|
||||||
|
|
||||||
// ...and persist
|
// ...and persist
|
||||||
return this.persistenceService.updateObject(
|
return persistenceFn.apply(persistenceService, [
|
||||||
this.getSpace(),
|
this.getSpace(),
|
||||||
domainObject.getId(),
|
domainObject.getId(),
|
||||||
domainObject.getModel()
|
domainObject.getModel()
|
||||||
);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +48,7 @@ define(
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockPersistenceService = jasmine.createSpyObj(
|
mockPersistenceService = jasmine.createSpyObj(
|
||||||
"persistenceService",
|
"persistenceService",
|
||||||
[ "updateObject", "readObject" ]
|
[ "updateObject", "readObject", "createObject", "deleteObject" ]
|
||||||
);
|
);
|
||||||
mockDomainObject = {
|
mockDomainObject = {
|
||||||
getId: function () { return id; },
|
getId: function () { return id; },
|
||||||
@ -68,10 +68,24 @@ define(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("makes a call to the persistence service when invoked", function () {
|
it("creates unpersisted objects with the persistence service", function () {
|
||||||
|
// Verify precondition; no call made during constructor
|
||||||
|
expect(mockPersistenceService.createObject).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
persistence.persist();
|
||||||
|
|
||||||
|
expect(mockPersistenceService.createObject).toHaveBeenCalledWith(
|
||||||
|
SPACE,
|
||||||
|
id,
|
||||||
|
model
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates previously persisted objects with the persistence service", function () {
|
||||||
// Verify precondition; no call made during constructor
|
// Verify precondition; no call made during constructor
|
||||||
expect(mockPersistenceService.updateObject).not.toHaveBeenCalled();
|
expect(mockPersistenceService.updateObject).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
model.persisted = 12321;
|
||||||
persistence.persist();
|
persistence.persist();
|
||||||
|
|
||||||
expect(mockPersistenceService.updateObject).toHaveBeenCalledWith(
|
expect(mockPersistenceService.updateObject).toHaveBeenCalledWith(
|
||||||
|
@ -33,6 +33,11 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"components": [
|
"components": [
|
||||||
|
{
|
||||||
|
"type": "decorator",
|
||||||
|
"provides": "creationService",
|
||||||
|
"implementation": "services/LocatingCreationDecorator.js"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"controllers": [
|
"controllers": [
|
||||||
],
|
],
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*global define */
|
||||||
|
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a `location` property to newly-created domain objects.
|
||||||
|
* @constructor
|
||||||
|
* @augments {platform/commonUI/browse.CreationService}
|
||||||
|
* @memberof platform/entanglement
|
||||||
|
*/
|
||||||
|
function LocatingCreationDecorator(creationService) {
|
||||||
|
this.creationService = creationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocatingCreationDecorator.prototype.createObject = function (model, parent) {
|
||||||
|
if (parent && parent.getId) {
|
||||||
|
model.location = parent.getId();
|
||||||
|
}
|
||||||
|
return this.creationService.createObject(model, parent);
|
||||||
|
};
|
||||||
|
|
||||||
|
return LocatingCreationDecorator;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,79 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*global define,describe,beforeEach,it,jasmine,expect */
|
||||||
|
|
||||||
|
define(
|
||||||
|
[
|
||||||
|
'../../src/services/LocatingCreationDecorator'
|
||||||
|
],
|
||||||
|
function (LocatingCreationDecorator) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("LocatingCreationDecorator", function () {
|
||||||
|
var mockCreationService,
|
||||||
|
mockPromise,
|
||||||
|
mockParent,
|
||||||
|
decorator;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockCreationService = jasmine.createSpyObj(
|
||||||
|
'creationService',
|
||||||
|
['createObject']
|
||||||
|
);
|
||||||
|
mockPromise = jasmine.createSpyObj(
|
||||||
|
'promise',
|
||||||
|
['then']
|
||||||
|
);
|
||||||
|
mockParent = jasmine.createSpyObj(
|
||||||
|
'domainObject',
|
||||||
|
['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability']
|
||||||
|
);
|
||||||
|
mockCreationService.createObject.andReturn(mockPromise);
|
||||||
|
mockParent.getId.andReturn('test-id');
|
||||||
|
decorator = new LocatingCreationDecorator(mockCreationService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("delegates to its decorated service", function () {
|
||||||
|
expect(decorator.createObject(
|
||||||
|
{ someKey: "some value" },
|
||||||
|
mockParent
|
||||||
|
)).toEqual(mockPromise); // promise returned by decoratee
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a location property", function () {
|
||||||
|
decorator.createObject(
|
||||||
|
{ someKey: "some value" },
|
||||||
|
mockParent
|
||||||
|
);
|
||||||
|
expect(mockCreationService.createObject).toHaveBeenCalledWith(
|
||||||
|
{
|
||||||
|
someKey: "some value",
|
||||||
|
location: "test-id" // Parent's identifier
|
||||||
|
},
|
||||||
|
mockParent
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
@ -4,5 +4,6 @@
|
|||||||
"services/LinkService",
|
"services/LinkService",
|
||||||
"services/MoveService",
|
"services/MoveService",
|
||||||
"services/LocationService",
|
"services/LocationService",
|
||||||
|
"services/LocatingCreationDecorator",
|
||||||
"capabilities/LocationCapability"
|
"capabilities/LocationCapability"
|
||||||
]
|
]
|
||||||
|
41
platform/identity/bundle.json
Normal file
41
platform/identity/bundle.json
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"extensions": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"implementation": "IdentityAggregator.js",
|
||||||
|
"type": "aggregator",
|
||||||
|
"provides": "identityService",
|
||||||
|
"depends": [ "$q" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"implementation": "IdentityProvider.js",
|
||||||
|
"type": "provider",
|
||||||
|
"provides": "identityService",
|
||||||
|
"depends": [ "$q" ],
|
||||||
|
"priority": "fallback"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "decorator",
|
||||||
|
"provides": "creationService",
|
||||||
|
"implementation": "IdentityCreationDecorator.js",
|
||||||
|
"depends": [ "identityService" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indicators": [
|
||||||
|
{
|
||||||
|
"implementation": "IdentityIndicator.js",
|
||||||
|
"depends": [ "identityService" ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"key": "creator",
|
||||||
|
"name": "Creator"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
93
platform/identity/src/IdentityAggregator.js
Normal file
93
platform/identity/src/IdentityAggregator.js
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines interfaces and common infrastructure for establishing
|
||||||
|
* a user's identity.
|
||||||
|
* @namespace platform/identity
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides information about the currently logged-in
|
||||||
|
* user, if available.
|
||||||
|
*
|
||||||
|
* @interface IdentityService
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the current user. This returns a promise
|
||||||
|
* which will resolve to metadata about the user, or undefined if
|
||||||
|
* no information about the user is available.
|
||||||
|
*
|
||||||
|
* @method IdentityService#getUser
|
||||||
|
* @returns {Promise.<IdentityMetadata>} a promise for metadata about
|
||||||
|
* the current user
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata about a user.
|
||||||
|
*
|
||||||
|
* @typedef IdentityMetadata
|
||||||
|
* @property {string} name the user's human-readable name
|
||||||
|
* @property {string} key the user's machine-readable name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aggregator for multiple identity services. Exposes the first
|
||||||
|
* defined identity provided by any provider, according to
|
||||||
|
* priority order.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @implements {IdentityService}
|
||||||
|
* @memberof platform/identity
|
||||||
|
*/
|
||||||
|
function IdentityAggregator($q, providers) {
|
||||||
|
this.providers = providers;
|
||||||
|
this.$q = $q;
|
||||||
|
}
|
||||||
|
|
||||||
|
function delegateGetUser(provider) {
|
||||||
|
return provider.getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
function identity(value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function giveFirst(results) {
|
||||||
|
return results.filter(identity)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityAggregator.prototype.getUser = function () {
|
||||||
|
var $q = this.$q,
|
||||||
|
promises = this.providers.map(delegateGetUser);
|
||||||
|
|
||||||
|
return $q.all(promises).then(giveFirst);
|
||||||
|
};
|
||||||
|
|
||||||
|
return IdentityAggregator;
|
||||||
|
}
|
||||||
|
);
|
55
platform/identity/src/IdentityCreationDecorator.js
Normal file
55
platform/identity/src/IdentityCreationDecorator.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*global define */
|
||||||
|
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a `creator` property to newly-created domain objects.
|
||||||
|
* @constructor
|
||||||
|
* @augments {platform/commonUI/browse.CreationService}
|
||||||
|
* @memberof platform/entanglement
|
||||||
|
*/
|
||||||
|
function IdentityCreationDecorator(identityService, creationService) {
|
||||||
|
this.identityService = identityService;
|
||||||
|
this.creationService = creationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityCreationDecorator.prototype.createObject = function (model, parent) {
|
||||||
|
var creationService = this.creationService,
|
||||||
|
identityService = this.identityService;
|
||||||
|
|
||||||
|
return identityService.getUser().then(function (user) {
|
||||||
|
if (user && user.key) {
|
||||||
|
model.creator = user.key;
|
||||||
|
}
|
||||||
|
return creationService.createObject(model, parent);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return IdentityCreationDecorator;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
63
platform/identity/src/IdentityIndicator.js
Normal file
63
platform/identity/src/IdentityIndicator.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicator showing the currently logged-in user.
|
||||||
|
* @constructor
|
||||||
|
* @memberof platform/identity
|
||||||
|
* @implements {Indicator}
|
||||||
|
* @param {IdentityService} identityService the identity service
|
||||||
|
*/
|
||||||
|
function IdentityIndicator(identityService) {
|
||||||
|
// Track the current connection state
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
identityService.getUser().then(function (user) {
|
||||||
|
if (user && user.key) {
|
||||||
|
self.text = user.name || user.key;
|
||||||
|
self.description = "Logged in as " + user.key;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityIndicator.prototype.getGlyph = function () {
|
||||||
|
return this.text && "P";
|
||||||
|
};
|
||||||
|
IdentityIndicator.prototype.getGlyphClass = function () {
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
IdentityIndicator.prototype.getText = function () {
|
||||||
|
return this.text;
|
||||||
|
};
|
||||||
|
IdentityIndicator.prototype.getDescription = function () {
|
||||||
|
return this.description;
|
||||||
|
};
|
||||||
|
|
||||||
|
return IdentityIndicator;
|
||||||
|
}
|
||||||
|
);
|
55
platform/identity/src/IdentityProvider.js
Normal file
55
platform/identity/src/IdentityProvider.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines interfaces and common infrastructure for establishing
|
||||||
|
* a user's identity.
|
||||||
|
* @namespace platform/identity
|
||||||
|
*/
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var UNKNOWN_USER = {
|
||||||
|
key: "unknown",
|
||||||
|
name: "Unknown User"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default implementation of an identity service. Provides an
|
||||||
|
* unkown user.
|
||||||
|
* @constructor
|
||||||
|
* @implements {IdentityService}
|
||||||
|
* @memberof platform/identity
|
||||||
|
*/
|
||||||
|
function IdentityProvider($q) {
|
||||||
|
this.userPromise = $q.when(UNKNOWN_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityProvider.prototype.getUser = function () {
|
||||||
|
return this.userPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
return IdentityProvider;
|
||||||
|
}
|
||||||
|
);
|
143
platform/identity/test/IdentityAggregatorSpec.js
Normal file
143
platform/identity/test/IdentityAggregatorSpec.js
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,runs,jasmine*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
["../src/IdentityAggregator"],
|
||||||
|
function (IdentityAggregator) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("The identity aggregator", function () {
|
||||||
|
var mockProviders,
|
||||||
|
mockQ,
|
||||||
|
resolves,
|
||||||
|
mockPromise,
|
||||||
|
mockCallback,
|
||||||
|
testUsers,
|
||||||
|
aggregator;
|
||||||
|
|
||||||
|
function callbackCalled() {
|
||||||
|
return mockCallback.calls.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveProviderPromises() {
|
||||||
|
['a', 'b', 'c'].forEach(function (id, i) {
|
||||||
|
resolves[id](testUsers[i]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
testUsers = [
|
||||||
|
{ key: "user0", name: "User Zero" },
|
||||||
|
{ key: "user1", name: "User One" },
|
||||||
|
{ key: "user2", name: "User Two" }
|
||||||
|
];
|
||||||
|
|
||||||
|
resolves = {};
|
||||||
|
|
||||||
|
mockProviders = ['a', 'b', 'c'].map(function (id) {
|
||||||
|
var mockProvider = jasmine.createSpyObj(
|
||||||
|
'provider-' + id,
|
||||||
|
[ 'getUser' ]
|
||||||
|
);
|
||||||
|
|
||||||
|
mockProvider.getUser.andReturn(new Promise(function (r) {
|
||||||
|
resolves[id] = r;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return mockProvider;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockQ = jasmine.createSpyObj('$q', ['all']);
|
||||||
|
mockQ.all.andCallFake(function (promises) {
|
||||||
|
return Promise.all(promises);
|
||||||
|
});
|
||||||
|
|
||||||
|
mockCallback = jasmine.createSpy('callback');
|
||||||
|
|
||||||
|
aggregator = new IdentityAggregator(
|
||||||
|
mockQ,
|
||||||
|
mockProviders
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("delegates to the aggregated providers", function () {
|
||||||
|
// Verify precondition
|
||||||
|
mockProviders.forEach(function (p) {
|
||||||
|
expect(p.getUser).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
aggregator.getUser();
|
||||||
|
|
||||||
|
mockProviders.forEach(function (p) {
|
||||||
|
expect(p.getUser).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns the first result when it is defined", function () {
|
||||||
|
aggregator.getUser().then(mockCallback);
|
||||||
|
|
||||||
|
resolveProviderPromises();
|
||||||
|
|
||||||
|
waitsFor(callbackCalled);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith(testUsers[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns a later result when earlier results are undefined", function () {
|
||||||
|
testUsers[0] = undefined;
|
||||||
|
|
||||||
|
aggregator.getUser().then(mockCallback);
|
||||||
|
|
||||||
|
resolveProviderPromises();
|
||||||
|
|
||||||
|
waitsFor(callbackCalled);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith(testUsers[1]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined when no providers expose users", function () {
|
||||||
|
testUsers = [ undefined, undefined, undefined ];
|
||||||
|
|
||||||
|
aggregator.getUser().then(mockCallback);
|
||||||
|
|
||||||
|
resolveProviderPromises();
|
||||||
|
|
||||||
|
waitsFor(callbackCalled);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined when there are no providers", function () {
|
||||||
|
new IdentityAggregator(mockQ, []).getUser().then(mockCallback);
|
||||||
|
waitsFor(callbackCalled);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
107
platform/identity/test/IdentityCreationDecoratorSpec.js
Normal file
107
platform/identity/test/IdentityCreationDecoratorSpec.js
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*global define,describe,beforeEach,it,jasmine,expect,Promise,waitsFor,runs */
|
||||||
|
|
||||||
|
define(
|
||||||
|
[
|
||||||
|
'../src/IdentityCreationDecorator'
|
||||||
|
],
|
||||||
|
function (IdentityCreationDecorator) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("IdentityCreationDecorator", function () {
|
||||||
|
var mockIdentityService,
|
||||||
|
mockCreationService,
|
||||||
|
mockParent,
|
||||||
|
mockCreatedObject,
|
||||||
|
mockCallback,
|
||||||
|
decorator;
|
||||||
|
|
||||||
|
function calledBack() {
|
||||||
|
return mockCallback.calls.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockCallback = jasmine.createSpy('callback');
|
||||||
|
mockIdentityService = jasmine.createSpyObj(
|
||||||
|
'identityService',
|
||||||
|
['getUser']
|
||||||
|
);
|
||||||
|
mockCreationService = jasmine.createSpyObj(
|
||||||
|
'creationService',
|
||||||
|
['createObject']
|
||||||
|
);
|
||||||
|
mockParent = jasmine.createSpyObj(
|
||||||
|
'parentObject',
|
||||||
|
['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability']
|
||||||
|
);
|
||||||
|
mockCreatedObject = jasmine.createSpyObj(
|
||||||
|
'domainObject',
|
||||||
|
['getCapability', 'getId', 'getModel', 'hasCapability', 'useCapability']
|
||||||
|
);
|
||||||
|
mockCreationService.createObject
|
||||||
|
.andReturn(Promise.resolve(mockCreatedObject));
|
||||||
|
mockIdentityService.getUser
|
||||||
|
.andReturn(Promise.resolve({ key: "test-user-id" }));
|
||||||
|
mockParent.getId.andReturn('test-id');
|
||||||
|
decorator = new IdentityCreationDecorator(
|
||||||
|
mockIdentityService,
|
||||||
|
mockCreationService
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("delegates to its decorated service when identity is available", function () {
|
||||||
|
var testModel = { someKey: "some value" };
|
||||||
|
|
||||||
|
decorator.createObject(testModel, mockParent)
|
||||||
|
.then(mockCallback);
|
||||||
|
|
||||||
|
waitsFor(calledBack);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback)
|
||||||
|
.toHaveBeenCalledWith(mockCreatedObject);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a creator property", function () {
|
||||||
|
var testModel = { someKey: "some value" };
|
||||||
|
|
||||||
|
decorator.createObject(testModel, mockParent)
|
||||||
|
.then(mockCallback);
|
||||||
|
|
||||||
|
waitsFor(calledBack);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback)
|
||||||
|
.toHaveBeenCalledWith(mockCreatedObject);
|
||||||
|
// Make sure arguments were delegated appropriately
|
||||||
|
expect(mockCreationService.createObject)
|
||||||
|
.toHaveBeenCalledWith(
|
||||||
|
{ someKey: "some value", creator: "test-user-id" },
|
||||||
|
mockParent
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
76
platform/identity/test/IdentityIndicatorSpec.js
Normal file
76
platform/identity/test/IdentityIndicatorSpec.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
["../src/IdentityIndicator"],
|
||||||
|
function (IdentityIndicator) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("The identity indicator", function () {
|
||||||
|
var mockPromise,
|
||||||
|
mockIdentityService,
|
||||||
|
indicator;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||||
|
mockIdentityService = jasmine.createSpyObj(
|
||||||
|
'identityService',
|
||||||
|
['getUser']
|
||||||
|
);
|
||||||
|
|
||||||
|
mockIdentityService.getUser.andReturn(mockPromise);
|
||||||
|
|
||||||
|
indicator = new IdentityIndicator(mockIdentityService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows information about the current user", function () {
|
||||||
|
mockPromise.then.mostRecentCall.args[0]({
|
||||||
|
key: "testuserid",
|
||||||
|
name: "A User"
|
||||||
|
});
|
||||||
|
// Should have a single character glyph
|
||||||
|
expect(indicator.getGlyph().length).toEqual(1);
|
||||||
|
expect(indicator.getGlyphClass()).toBeUndefined();
|
||||||
|
expect(indicator.getText()).toEqual("A User");
|
||||||
|
expect(indicator.getDescription().indexOf("testuserid"))
|
||||||
|
.not.toEqual(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows nothing while no user information is available", function () {
|
||||||
|
expect(indicator.getGlyph()).toBeUndefined();
|
||||||
|
expect(indicator.getGlyphClass()).toBeUndefined();
|
||||||
|
expect(indicator.getText()).toBeUndefined();
|
||||||
|
expect(indicator.getDescription()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows nothing when there is no identity information", function () {
|
||||||
|
mockPromise.then.mostRecentCall.args[0](undefined);
|
||||||
|
expect(indicator.getGlyph()).toBeUndefined();
|
||||||
|
expect(indicator.getGlyphClass()).toBeUndefined();
|
||||||
|
expect(indicator.getText()).toBeUndefined();
|
||||||
|
expect(indicator.getDescription()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
63
platform/identity/test/IdentityProviderSpec.js
Normal file
63
platform/identity/test/IdentityProviderSpec.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*global define,describe,beforeEach,it,jasmine,expect,Promise,waitsFor,runs */
|
||||||
|
|
||||||
|
define(
|
||||||
|
[
|
||||||
|
'../src/IdentityProvider'
|
||||||
|
],
|
||||||
|
function (IdentityProvider) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("IdentityProvider", function () {
|
||||||
|
var mockQ, mockCallback, provider;
|
||||||
|
|
||||||
|
function calledBack() {
|
||||||
|
return mockCallback.calls.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockCallback = jasmine.createSpy('callback');
|
||||||
|
mockQ = jasmine.createSpyObj('$q', ['when']);
|
||||||
|
mockQ.when.andCallFake(function (v) {
|
||||||
|
return Promise.resolve(v);
|
||||||
|
});
|
||||||
|
|
||||||
|
provider = new IdentityProvider(mockQ);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides an unknown user", function () {
|
||||||
|
provider.getUser().then(mockCallback);
|
||||||
|
|
||||||
|
waitsFor(calledBack);
|
||||||
|
runs(function () {
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith({
|
||||||
|
key: jasmine.any(String),
|
||||||
|
name: jasmine.any(String)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
6
platform/identity/test/suite.json
Normal file
6
platform/identity/test/suite.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
"IdentityAggregator",
|
||||||
|
"IdentityCreationDecorator",
|
||||||
|
"IdentityIndicator",
|
||||||
|
"IdentityProvider"
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user