Compare commits

...

41 Commits

Author SHA1 Message Date
2f4b38a061 Merge branch 'master' into user-attribution 2022-10-21 16:54:08 -07:00
d402162aed Merge branch 'user-attribution' of http://github.com/nasa/openmct into user-attribution
Merge'n
2022-10-21 16:47:35 -07:00
9e450892a7 updating incorrect use of edit and transaction in our appActions for testing 2022-10-21 16:47:05 -07:00
b06aaa7761 Merge branch 'master' into user-attribution 2022-10-21 16:00:58 -07:00
880547e9c0 updating docs for object api "startTransaction" 2022-10-21 15:32:16 -07:00
62bfa44f79 updating remove action to hold the transaction and disregard edit state when handling transactions, also updated object api to return transaction when starting and ignore edit state when determining if transaction is active 2022-10-21 15:26:27 -07:00
f59270c6b0 Merge branch 'master' into user-attribution 2022-10-21 11:47:52 -07:00
42aee096d2 Merge branch 'master' into user-attribution 2022-10-18 14:22:35 -07:00
033a45d600 fixing api test not waiting for save 2022-10-18 14:20:59 -07:00
6c5510f385 cleaned up objectAPI save, adding transactions for remove action to prevent stale object retrieval, created a private mutation method to be used in object api that does not trigger save 2022-10-18 14:02:13 -07:00
b2fabb9f00 WIP debug 2022-10-13 09:24:54 -07:00
b91176c331 WIP for testing purposes 2022-10-11 12:45:02 -07:00
4decb1ed00 Merge branch 'master' into user-attribution 2022-10-03 11:08:43 -07:00
fb0ea03378 Merge branch 'release/2.1.1' into user-attribution 2022-09-30 16:57:18 -07:00
89e5891192 Merge branch 'master' into user-attribution 2022-09-30 13:33:04 -07:00
1c00f1a731 Update version 2022-09-30 13:29:38 -07:00
bd0217498e removing async on mutate 2022-09-30 12:52:51 -07:00
d9181e5c4c updating remove action to wait for save before navigationg 2022-09-30 12:48:35 -07:00
b7ed6619d2 updating plan properties inspector test to account for new fields added in this update 2022-09-30 11:57:42 -07:00
212fa16f59 Merge branch 'user-attribution' of http://github.com/nasa/openmct into user-attribution
Merge'n master
2022-09-30 11:40:02 -07:00
1a8d35fd0c thank you ANDREW! finally found the issue in a failing test, updated object api tests to wait on async save before checking results 2022-09-30 11:39:32 -07:00
caa27dbda2 addressing PR comments and adding restricted notebook type to synchronized objects array 2022-09-30 10:45:38 -07:00
4e48ce3872 Merge branch 'master' into user-attribution 2022-09-30 10:41:08 -07:00
b8be778b5a Merge branch 'master' into user-attribution 2022-09-30 08:37:14 -07:00
69a89037ab Merge branch 'user-attribution' of http://github.com/nasa/openmct into user-attribution
Merg'n latest changes
2022-09-27 10:30:31 -07:00
04f5684fa8 WIP 2022-09-27 10:29:59 -07:00
f05eb58f13 Merge branch 'master' into user-attribution 2022-09-26 13:33:21 -07:00
3d9f175234 added a test for created timestamp 2022-09-26 13:20:35 -07:00
f5ec58acf4 adding created date to object creation 2022-09-26 13:16:00 -07:00
50c7e99bd3 pulling user info each time 2022-09-20 15:29:09 -07:00
888b7fcf90 Merge branch 'master' into user-attribution 2022-09-20 14:01:59 -07:00
f72daa7ce1 Merge branch 'master' into user-attribution 2022-09-16 09:48:42 -07:00
aea942ff73 Merge branch 'master' into user-attribution 2022-09-12 17:39:35 -07:00
7304a31fc3 Merge branch 'master' into user-attribution 2022-09-12 12:46:42 -07:00
d93da11129 cleaner test description 2022-09-12 12:45:25 -07:00
f0b2936229 added tests to object api spec for user attribution 2022-09-12 12:43:42 -07:00
fc9663804b update inspector spec to include modified by and created by fields 2022-09-12 12:20:09 -07:00
2e917aedfd removing space 2022-09-12 12:04:12 -07:00
b3820fbf46 Merge branch 'master' into user-attribution 2022-09-09 13:53:37 -07:00
0b7ea7cb1b current implementation of user attribution 2022-09-08 20:05:44 -07:00
f430505f88 initial changes adding modified and created by fields to domain objects and updating properties inspector 2022-09-08 14:19:17 -07:00
8 changed files with 197 additions and 65 deletions

View File

@ -225,15 +225,14 @@ async function getHashUrlToDomainObject(page, uuid) {
}
/**
* Utilizes the OpenMCT API to detect if the given object has an active transaction (is in Edit mode).
* Utilizes the OpenMCT API to detect if the UI is in Edit mode.
* @private
* @param {import('@playwright/test').Page} page
* @param {string | import('../src/api/objects/ObjectAPI').Identifier} identifier
* @return {Promise<boolean>} true if the object has an active transaction, false otherwise
* @return {Promise<boolean>} true if the Open MCT is in Edit Mode
*/
async function _isInEditMode(page, identifier) {
// eslint-disable-next-line no-return-await
return await page.evaluate((objectIdentifier) => window.openmct.objects.isTransactionActive(objectIdentifier), identifier);
return await page.evaluate(() => window.openmct.editor.isEditing());
}
/**

View File

@ -94,7 +94,6 @@ describe("The Annotation API", () => {
openmct.startHeadless();
});
afterEach(async () => {
openmct.objects.providers = {};
await resetApplicationState(openmct);
});
it("is defined", () => {

View File

@ -96,7 +96,7 @@ export default class ObjectAPI {
this.cache = {};
this.interceptorRegistry = new InterceptorRegistry();
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'plan', 'annotation'];
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'restricted-notebook', 'plan', 'annotation'];
this.errors = {
Conflict: ConflictError
@ -204,13 +204,13 @@ export default class ObjectAPI {
}
identifier = utils.parseKeyString(identifier);
let dirtyObject;
if (this.isTransactionActive()) {
dirtyObject = this.transaction.getDirtyObject(identifier);
}
if (dirtyObject) {
return Promise.resolve(dirtyObject);
if (this.isTransactionActive()) {
let dirtyObject = this.transaction.getDirtyObject(identifier);
if (dirtyObject) {
return Promise.resolve(dirtyObject);
}
}
const provider = this.getProvider(identifier);
@ -354,10 +354,8 @@ export default class ObjectAPI {
* @returns {Promise} a promise which will resolve when the domain object
* has been saved, or be rejected if it cannot be saved
*/
save(domainObject) {
let provider = this.getProvider(domainObject.identifier);
let savedResolve;
let savedReject;
async save(domainObject) {
const provider = this.getProvider(domainObject.identifier);
let result;
if (!this.isPersistable(domainObject.identifier)) {
@ -366,27 +364,37 @@ export default class ObjectAPI {
result = Promise.resolve(true);
} else {
const persistedTime = Date.now();
if (domainObject.persisted === undefined) {
result = new Promise((resolve, reject) => {
savedResolve = resolve;
savedReject = reject;
});
domainObject.persisted = persistedTime;
const newObjectPromise = provider.create(domainObject);
if (newObjectPromise) {
newObjectPromise.then(response => {
this.mutate(domainObject, 'persisted', persistedTime);
savedResolve(response);
}).catch((error) => {
savedReject(error);
});
} else {
result = Promise.reject(`[ObjectAPI][save] Object provider returned ${newObjectPromise} when creating new object.`);
}
const username = await this.#getCurrentUsername();
const isNewObject = domainObject.persisted === undefined;
let savedResolve;
let savedReject;
let savedObjectPromise;
result = new Promise((resolve, reject) => {
savedResolve = resolve;
savedReject = reject;
});
this.#mutate(domainObject, 'persisted', persistedTime);
this.#mutate(domainObject, 'modifiedBy', username);
if (isNewObject) {
this.#mutate(domainObject, 'created', persistedTime);
this.#mutate(domainObject, 'createdBy', username);
savedObjectPromise = provider.create(domainObject);
} else {
domainObject.persisted = persistedTime;
this.mutate(domainObject, 'persisted', persistedTime);
result = provider.update(domainObject);
savedObjectPromise = provider.update(domainObject);
}
if (savedObjectPromise) {
savedObjectPromise.then(response => {
savedResolve(response);
}).catch((error) => {
savedReject(error);
});
} else {
result = Promise.reject(`[ObjectAPI][save] Object provider returned ${savedObjectPromise} when ${isNewObject ? 'creating new' : 'updating'} object.`);
}
}
@ -399,8 +407,21 @@ export default class ObjectAPI {
});
}
async #getCurrentUsername() {
const user = await this.openmct.user.getCurrentUser();
let username;
if (user !== undefined) {
username = user.getName();
}
return username;
}
/**
* After entering into edit mode, creates a new instance of Transaction to keep track of changes in Objects
*
* @returns {Transaction} a new Transaction that was just created
*/
startTransaction() {
if (this.isTransactionActive()) {
@ -408,6 +429,8 @@ export default class ObjectAPI {
}
this.transaction = new Transaction(this);
return this.transaction;
}
/**
@ -480,14 +503,16 @@ export default class ObjectAPI {
}
/**
* Modify a domain object.
* Modify a domain object. Internal to ObjectAPI, won't call save after.
* @private
*
* @param {module:openmct.DomainObject} object the object to mutate
* @param {string} path the property to modify
* @param {*} value the new value for this property
* @method mutate
* @memberof module:openmct.ObjectAPI#
*/
mutate(domainObject, path, value) {
#mutate(domainObject, path, value) {
if (!this.supportsMutation(domainObject.identifier)) {
throw `Error: Attempted to mutate immutable object ${domainObject.name}`;
}
@ -508,6 +533,18 @@ export default class ObjectAPI {
//Destroy temporary mutable object
this.destroyMutable(mutableDomainObject);
}
}
/**
* Modify a domain object and save.
* @param {module:openmct.DomainObject} object the object to mutate
* @param {string} path the property to modify
* @param {*} value the new value for this property
* @method mutate
* @memberof module:openmct.ObjectAPI#
*/
mutate(domainObject, path, value) {
this.#mutate(domainObject, path, value);
if (this.isTransactionActive()) {
this.transaction.add(domainObject);
@ -684,7 +721,7 @@ export default class ObjectAPI {
}
isTransactionActive() {
return Boolean(this.transaction && this.openmct.editor.isEditing());
return this.transaction !== undefined && this.transaction !== null;
}
#hasAlreadyBeenPersisted(domainObject) {

View File

@ -8,13 +8,27 @@ describe("The Object API", () => {
let mockDomainObject;
const TEST_NAMESPACE = "test-namespace";
const TEST_KEY = "test-key";
const USERNAME = 'Joan Q Public';
const FIFTEEN_MINUTES = 15 * 60 * 1000;
beforeEach((done) => {
typeRegistry = jasmine.createSpyObj('typeRegistry', [
'get'
]);
const userProvider = {
isLoggedIn() {
return true;
},
getCurrentUser() {
return Promise.resolve({
getName() {
return USERNAME;
}
});
}
};
openmct = createOpenMct();
openmct.user.setProvider(userProvider);
objectAPI = openmct.objects;
openmct.editor = {};
@ -63,19 +77,34 @@ describe("The Object API", () => {
mockProvider.update.and.returnValue(Promise.resolve(true));
objectAPI.addProvider(TEST_NAMESPACE, mockProvider);
});
it("Calls 'create' on provider if object is new", () => {
objectAPI.save(mockDomainObject);
it("Adds a 'created' timestamp to new objects", async () => {
await objectAPI.save(mockDomainObject);
expect(mockDomainObject.created).not.toBeUndefined();
});
it("Calls 'create' on provider if object is new", async () => {
await objectAPI.save(mockDomainObject);
expect(mockProvider.create).toHaveBeenCalled();
expect(mockProvider.update).not.toHaveBeenCalled();
});
it("Calls 'update' on provider if object is not new", () => {
it("Calls 'update' on provider if object is not new", async () => {
mockDomainObject.persisted = Date.now() - FIFTEEN_MINUTES;
mockDomainObject.modified = Date.now();
objectAPI.save(mockDomainObject);
await objectAPI.save(mockDomainObject);
expect(mockProvider.create).not.toHaveBeenCalled();
expect(mockProvider.update).toHaveBeenCalled();
});
it("Sets the current user for 'createdBy' on new objects", async () => {
await objectAPI.save(mockDomainObject);
expect(mockDomainObject.createdBy).toBe(USERNAME);
});
it("Sets the current user for 'modifedBy' on existing objects", async () => {
mockDomainObject.persisted = Date.now() - FIFTEEN_MINUTES;
mockDomainObject.modified = Date.now();
await objectAPI.save(mockDomainObject);
expect(mockDomainObject.modifiedBy).toBe(USERNAME);
});
it("Does not persist if the object is unchanged", () => {
mockDomainObject.persisted =

View File

@ -264,7 +264,7 @@ describe('the plugin', function () {
it('provides an inspector view with the version information if available', () => {
componentObject = component.$root.$children[0];
const propertiesEls = componentObject.$el.querySelectorAll('.c-inspect-properties__row');
expect(propertiesEls.length).toEqual(4);
expect(propertiesEls.length).toEqual(6);
const found = Array.from(propertiesEls).some((propertyEl) => {
return (propertyEl.children[0].innerHTML.trim() === 'Version'
&& propertyEl.children[1].innerHTML.trim() === 'v1');

View File

@ -19,8 +19,12 @@
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
export default class RemoveAction {
#transaction;
constructor(openmct) {
this.name = 'Remove';
this.key = 'remove';
this.description = 'Remove this object from its containing object.';
@ -29,17 +33,25 @@ export default class RemoveAction {
this.priority = 1;
this.openmct = openmct;
this.removeFromComposition = this.removeFromComposition.bind(this); // for access to private transaction variable
}
invoke(objectPath) {
async invoke(objectPath) {
let object = objectPath[0];
let parent = objectPath[1];
this.showConfirmDialog(object).then(() => {
this.removeFromComposition(parent, object);
if (this.inNavigationPath(object)) {
this.navigateTo(objectPath.slice(1));
}
}).catch(() => {});
try {
await this.showConfirmDialog(object);
} catch (error) {
return; // form canceled, exit invoke
}
await this.removeFromComposition(parent, object);
if (this.inNavigationPath(object)) {
this.navigateTo(objectPath.slice(1));
}
}
showConfirmDialog(object) {
@ -81,20 +93,21 @@ export default class RemoveAction {
this.openmct.router.navigate('#/browse/' + urlPath);
}
removeFromComposition(parent, child) {
let composition = parent.composition.filter(id =>
!this.openmct.objects.areIdsEqual(id, child.identifier)
);
async removeFromComposition(parent, child) {
this.startTransaction();
this.openmct.objects.mutate(parent, 'composition', composition);
const composition = this.openmct.composition.get(parent);
composition.remove(child);
if (!this.isAlias(child, parent)) {
this.openmct.objects.mutate(child, 'location', null);
}
if (this.inNavigationPath(child) && this.openmct.editor.isEditing()) {
this.openmct.editor.save();
}
if (!this.isAlias(child, parent)) {
this.openmct.objects.mutate(child, 'location', null);
}
await this.saveTransaction();
}
isAlias(child, parent) {
@ -132,4 +145,23 @@ export default class RemoveAction {
&& parentType.definition.creatable
&& Array.isArray(parent.composition);
}
startTransaction() {
if (!this.openmct.objects.isTransactionActive()) {
this.#transaction = this.openmct.objects.startTransaction();
}
}
saveTransaction() {
if (!this.#transaction) {
return;
}
return this.#transaction.commit()
.catch(error => {
throw error;
}).finally(() => {
this.openmct.objects.endTransaction();
});
}
}

View File

@ -38,6 +38,8 @@ describe('the inspector', () => {
folderItem = {
name: 'folder',
type: 'folder',
createdBy: 'John Q',
modifiedBy: 'Public',
id: 'mock-folder-key',
identifier: {
namespace: '',
@ -74,6 +76,8 @@ describe('the inspector', () => {
const [
title,
type,
createdBy,
modifiedBy,
notes,
timestamp
] = details;
@ -87,6 +91,14 @@ describe('the inspector', () => {
.toEqual('Type');
expect(type.value.toLowerCase())
.toEqual(folderItem.type);
expect(createdBy.name)
.toEqual('Created By');
expect(createdBy.value)
.toEqual(folderItem.createdBy);
expect(modifiedBy.name)
.toEqual('Modified By');
expect(modifiedBy.value)
.toEqual(folderItem.modifiedBy);
expect(notes.value)
.toEqual('This object should have some notes');

View File

@ -90,10 +90,13 @@ export default {
return;
}
const UNKNOWN_USER = 'Unknown';
const title = this.domainObject.name;
const typeName = this.type ? this.type.definition.name : `Unknown: ${this.domainObject.type}`;
const timestampLabel = this.domainObject.modified ? 'Modified' : 'Created';
const timestamp = this.domainObject.modified ? this.domainObject.modified : this.domainObject.created;
const createdTimestamp = this.domainObject.created;
const createdBy = this.domainObject.createdBy ? this.domainObject.createdBy : UNKNOWN_USER;
const modifiedBy = this.domainObject.modifiedBy ? this.domainObject.modifiedBy : UNKNOWN_USER;
const modifiedTimestamp = this.domainObject.modified ? this.domainObject.modified : this.domainObject.created;
const notes = this.domainObject.notes;
const version = this.domainObject.version;
@ -105,6 +108,14 @@ export default {
{
name: 'Type',
value: typeName
},
{
name: 'Created By',
value: createdBy
},
{
name: 'Modified By',
value: modifiedBy
}
];
@ -115,15 +126,28 @@ export default {
});
}
if (timestamp !== undefined) {
const formattedTimestamp = Moment.utc(timestamp)
if (createdTimestamp !== undefined) {
const formattedCreatedTimestamp = Moment.utc(createdTimestamp)
.format('YYYY-MM-DD[\n]HH:mm:ss')
+ ' UTC';
details.push(
{
name: timestampLabel,
value: formattedTimestamp
name: 'Created',
value: formattedCreatedTimestamp
}
);
}
if (modifiedTimestamp !== undefined) {
const formattedModifiedTimestamp = Moment.utc(modifiedTimestamp)
.format('YYYY-MM-DD[\n]HH:mm:ss')
+ ' UTC';
details.push(
{
name: 'Modified',
value: formattedModifiedTimestamp
}
);
}