Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role attribution to notebook entries and export #6793

Merged
merged 2 commits into from
Jul 13, 2023
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
6 changes: 4 additions & 2 deletions src/plugins/notebook/actions/ExportNotebookAsTextAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ export default class ExportNotebookAsTextAction {
if (changes.exportMetaData) {
const createdTimestamp = entry.createdOn;
const createdBy = this.getUserName(entry.createdBy);
const createdByRole = entry.createdByRole;
const modifiedBy = this.getUserName(entry.modifiedBy);
const modifiedByRole = entry.modifiedByRole;
const modifiedTimestamp = entry.modified ?? entry.created;
notebookAsText += `Created on ${this.formatTimeStamp(
createdTimestamp
)} by user ${createdBy}\n\n`;
)} by user ${createdBy}${createdByRole ? `: ${createdByRole}` : ''}\n\n`;
notebookAsText += `Updated on ${this.formatTimeStamp(
modifiedTimestamp
)} by user ${modifiedBy}\n\n`;
)} by user ${modifiedBy}${modifiedByRole ? `: ${modifiedByRole}` : ''}\n\n`;
}

if (changes.exportTags) {
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/notebook/components/NotebookEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<span class="c-ne__created-date">{{ createdOnDate }}</span>
<span class="c-ne__created-time">{{ createdOnTime }}</span>
<span v-if="entry.createdBy" class="c-ne__creator">
<span class="icon-person"></span> {{ entry.createdBy }}
<span class="icon-person"></span>
{{
entry.createdByRole ? `${entry.createdBy}: ${entry.createdByRole}` : entry.createdBy
}}
</span>
</div>
<span v-if="!readOnly && !isLocked" class="c-ne__local-controls--hidden">
Expand Down Expand Up @@ -433,10 +436,17 @@ export default {
this.timestampAndUpdate();
},
async timestampAndUpdate() {
const user = await this.openmct.user.getCurrentUser();

const [user, activeRole] = await Promise.all([
this.openmct.user.getCurrentUser(),
this.openmct.user.getActiveRole?.()
]);
if (user === undefined) {
this.entry.modifiedBy = UNKNOWN_USER;
} else {
this.entry.modifiedBy = user.getName();
if (activeRole) {
this.entry.modifiedByRole = activeRole;
}
}

this.entry.modified = Date.now();
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/notebook/utils/notebook-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ async function getUsername(openmct) {
return username;
}

async function getActiveRole(openmct) {
let role = null;
if (openmct.user.hasProvider()) {
role = await openmct.user.getActiveRole?.();
}

return role;
}

export const DEFAULT_CLASS = 'notebook-default';
const TIME_BOUNDS = {
START_BOUND: 'tc.startBound',
Expand Down Expand Up @@ -156,11 +165,15 @@ export async function addNotebookEntry(
const embeds = embed ? [embed] : [];

const id = `entry-${uuid()}`;
const createdBy = await getUsername(openmct);
const [createdBy, createdByRole] = await Promise.all([
getUsername(openmct),
getActiveRole(openmct)
]);
const entry = {
id,
createdOn: date,
createdBy,
createdByRole,
text: entryText,
embeds
};
Expand Down