Skip to content

Commit

Permalink
feat: unskip permissions on resume if non-guest + remove old skip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Dec 10, 2024
1 parent 2cc724b commit 821abf8
Showing 1 changed file with 142 additions and 138 deletions.
280 changes: 142 additions & 138 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@ document.getElementById("guided-button-has-docs-data").addEventListener("click",
});

const checkIfChangesMetadataPageShouldBeShown = async (pennsieveDatasetID) => {
// TODO: Brioader support for guests who are editing a changed dataset.

// let isGuest = await window.isWorkspaceGuest();
let existingDataset = window.sodaJSONObj?.["starting-point"]?.["type"] === "bf";
let ineligible = false;
if (existingDataset) {
Expand Down Expand Up @@ -4417,6 +4414,7 @@ const guidedUnSkipPage = (pageId) => {
const subPagesCapsule = `${pageId}-capsule`;
document.getElementById(subPagesCapsule).classList.remove("hidden");
}

// remove the page from window.sodaJSONObj array if it is there
if (window.sodaJSONObj["skipped-pages"].includes(pageId)) {
window.sodaJSONObj["skipped-pages"].splice(
Expand Down Expand Up @@ -6319,158 +6317,156 @@ window.openPage = async (targetPageID) => {

if (targetPageID === "guided-designate-permissions-tab") {
console.log("In permissions tab");
let isGuest = await window.isWorkspaceGuest();
if (!isGuest) {
// Get the users that can be granted permissions
const usersReq = await client.get(
`manage_datasets/ps_get_users?selected_account=${window.defaultBfAccount}`
);
const usersThatCanBeGrantedPermissions = usersReq.data.users;

// Get the teams that can be granted permissions
// Note: This is in a try catch because guest accounts do not have access to the teams endpoint
// so the request will fail and teamsThatCanBeGrantedPermissions will remain an empty array
let teamsThatCanBeGrantedPermissions = [];
try {
const teamsReq = await client.get(
`manage_datasets/ps_get_teams?selected_account=${window.defaultBfAccount}`
);
teamsThatCanBeGrantedPermissions = window.getSortedTeamStrings(teamsReq.data.teams);
} catch (error) {
const emessage = userErrorMessage(error);
}
// Get the users that can be granted permissions
const usersReq = await client.get(
`manage_datasets/ps_get_users?selected_account=${window.defaultBfAccount}`
);
const usersThatCanBeGrantedPermissions = usersReq.data.users;

// Reset the dropdown with the new users and teams
guidedAddUsersAndTeamsToDropdown(
usersThatCanBeGrantedPermissions,
teamsThatCanBeGrantedPermissions
// Get the teams that can be granted permissions
// Note: This is in a try catch because guest accounts do not have access to the teams endpoint
// so the request will fail and teamsThatCanBeGrantedPermissions will remain an empty array
let teamsThatCanBeGrantedPermissions = [];
try {
const teamsReq = await client.get(
`manage_datasets/ps_get_teams?selected_account=${window.defaultBfAccount}`
);
teamsThatCanBeGrantedPermissions = window.getSortedTeamStrings(teamsReq.data.teams);
} catch (error) {
const emessage = userErrorMessage(error);
}

if (pageNeedsUpdateFromPennsieve("guided-designate-permissions-tab")) {
// Show the loading page while the page's data is being fetched from Pennsieve
setPageLoadingState(true);
try {
let sparcUsersDivided = [];
// Reset the dropdown with the new users and teams
guidedAddUsersAndTeamsToDropdown(
usersThatCanBeGrantedPermissions,
teamsThatCanBeGrantedPermissions
);

//sparc users results needs to be formatted
usersThatCanBeGrantedPermissions.forEach((element) => {
//first two elements of this array will just be an email with no name
sparcUsersDivided.push(element.split(" !|**|!"));
});
if (pageNeedsUpdateFromPennsieve("guided-designate-permissions-tab")) {
// Show the loading page while the page's data is being fetched from Pennsieve
setPageLoadingState(true);
try {
let sparcUsersDivided = [];

const permissions = await api.getDatasetPermissions(
window.defaultBfAccount,
window.sodaJSONObj["digital-metadata"]["pennsieve-dataset-id"],
false
);
//sparc users results needs to be formatted
usersThatCanBeGrantedPermissions.forEach((element) => {
//first two elements of this array will just be an email with no name
sparcUsersDivided.push(element.split(" !|**|!"));
});

//Filter out the integration user
const filteredPermissions = permissions.filter((permission) => {
return !permission.includes("Integration User");
});
const permissions = await api.getDatasetPermissions(
window.defaultBfAccount,
window.sodaJSONObj["digital-metadata"]["pennsieve-dataset-id"],
false
);

let partialUserDetails = [];
let finalTeamPermissions = [];
let piOwner = [];

//so check for PI owner as well
for (const userPermission of filteredPermissions) {
// Will include teams and users
let userRoleSplit = userPermission.split(",");
// Will look like:
// ['User: John Doe ', ' role: owner']
// need to split above
let nameSplit = userRoleSplit[0].split(":"); // will appear as ['Team', ' DRC Team']
let roleSplit = userRoleSplit[1].split(":"); // will appear as [' role', ' Viewer']
let userName = nameSplit[1].trim();
let userPermiss = roleSplit[1].trim();
let teamOrUser = nameSplit[0].trim().toLowerCase();

if (teamOrUser === "team") {
finalTeamPermissions.push({
UUID: userName,
permission: userPermiss,
teamString: userName,
permissionSource: "Pennsieve",
deleteFromPennsieve: false,
});
} else {
partialUserDetails.push({
permission: userPermiss,
userName: userName,
});
}
//Filter out the integration user
const filteredPermissions = permissions.filter((permission) => {
return !permission.includes("Integration User");
});

let partialUserDetails = [];
let finalTeamPermissions = [];
let piOwner = [];

//so check for PI owner as well
for (const userPermission of filteredPermissions) {
// Will include teams and users
let userRoleSplit = userPermission.split(",");
// Will look like:
// ['User: John Doe ', ' role: owner']
// need to split above
let nameSplit = userRoleSplit[0].split(":"); // will appear as ['Team', ' DRC Team']
let roleSplit = userRoleSplit[1].split(":"); // will appear as [' role', ' Viewer']
let userName = nameSplit[1].trim();
let userPermiss = roleSplit[1].trim();
let teamOrUser = nameSplit[0].trim().toLowerCase();

if (teamOrUser === "team") {
finalTeamPermissions.push({
UUID: userName,
permission: userPermiss,
teamString: userName,
permissionSource: "Pennsieve",
deleteFromPennsieve: false,
});
} else {
partialUserDetails.push({
permission: userPermiss,
userName: userName,
});
}
// After loop use the array of objects to find the UUID and email
let finalUserPermissions = [];

partialUserDetails.map((object) => {
sparcUsersDivided.forEach((element) => {
if (element[0].includes(object["userName"])) {
// name was found now get UUID
let userEmailSplit = element[0].split(" (");
if (object["permission"] === "owner") {
//set for pi owner
piOwner.push({
UUID: object.permission,
name: userEmailSplit[0],
userString: element[0],
permissionSource: "Pennsieve",
deleteFromPennsieve: false,
});
//update PI owner key
} else {
finalUserPermissions.push({
UUID: element[1],
permission: object.permission,
userName: userEmailSplit[0],
userString: element[0],
permissonSource: "Pennsieve",
deleteFromPennsieve: false,
});
}
}
// After loop use the array of objects to find the UUID and email
let finalUserPermissions = [];

partialUserDetails.map((object) => {
sparcUsersDivided.forEach((element) => {
if (element[0].includes(object["userName"])) {
// name was found now get UUID
let userEmailSplit = element[0].split(" (");
if (object["permission"] === "owner") {
//set for pi owner
piOwner.push({
UUID: object.permission,
name: userEmailSplit[0],
userString: element[0],
permissionSource: "Pennsieve",
deleteFromPennsieve: false,
});
//update PI owner key
} else {
finalUserPermissions.push({
UUID: element[1],
permission: object.permission,
userName: userEmailSplit[0],
userString: element[0],
permissonSource: "Pennsieve",
deleteFromPennsieve: false,
});
}
});
}
});
});

window.sodaJSONObj["digital-metadata"]["team-permissions"] = finalTeamPermissions;
window.sodaJSONObj["digital-metadata"]["user-permissions"] = finalUserPermissions;
window.sodaJSONObj["digital-metadata"]["pi-owner"] = piOwner[0];
window.sodaJSONObj["digital-metadata"]["team-permissions"] = finalTeamPermissions;
window.sodaJSONObj["digital-metadata"]["user-permissions"] = finalUserPermissions;
window.sodaJSONObj["digital-metadata"]["pi-owner"] = piOwner[0];

window.sodaJSONObj["pages-fetched-from-pennsieve"].push(
"guided-designate-permissions-tab"
);
} catch (error) {
clientError(error);
const emessage = error.response.data.message;
await guidedShowOptionalRetrySwal(emessage, "guided-designate-permissions-tab");
// If the user chooses not to retry re-fetching the page data, mark the page as fetched
// so the the fetch does not occur again
window.sodaJSONObj["pages-fetched-from-pennsieve"].push(
"guided-designate-permissions-tab"
);
}
window.sodaJSONObj["pages-fetched-from-pennsieve"].push(
"guided-designate-permissions-tab"
);
} catch (error) {
clientError(error);
const emessage = error.response.data.message;
await guidedShowOptionalRetrySwal(emessage, "guided-designate-permissions-tab");
// If the user chooses not to retry re-fetching the page data, mark the page as fetched
// so the the fetch does not occur again
window.sodaJSONObj["pages-fetched-from-pennsieve"].push(
"guided-designate-permissions-tab"
);
}
}

//If the PI owner is empty, set the PI owner to the user that is currently curating
if (Object.keys(window.sodaJSONObj["digital-metadata"]["pi-owner"]).length === 0) {
//Get the user information of the user that is currently curating
const user = await api.getUserInformation();

const loggedInUserString = `${user["firstName"]} ${user["lastName"]} (${user["email"]})`;
const loggedInUserUUID = user["id"];
const loggedInUserName = `${user["firstName"]} ${user["lastName"]}`;
const loggedInUserPiObj = {
userString: loggedInUserString,
UUID: loggedInUserUUID,
name: loggedInUserName,
};
setGuidedDatasetPiOwner(loggedInUserPiObj);
}
//If the PI owner is empty, set the PI owner to the user that is currently curating
if (Object.keys(window.sodaJSONObj["digital-metadata"]["pi-owner"]).length === 0) {
//Get the user information of the user that is currently curating
const user = await api.getUserInformation();

renderPermissionsTable();
guidedResetUserTeamPermissionsDropdowns();
const loggedInUserString = `${user["firstName"]} ${user["lastName"]} (${user["email"]})`;
const loggedInUserUUID = user["id"];
const loggedInUserName = `${user["firstName"]} ${user["lastName"]}`;
const loggedInUserPiObj = {
userString: loggedInUserString,
UUID: loggedInUserUUID,
name: loggedInUserName,
};
setGuidedDatasetPiOwner(loggedInUserPiObj);
}

renderPermissionsTable();
guidedResetUserTeamPermissionsDropdowns();
}

if (targetPageID === "guided-assign-license-tab") {
Expand Down Expand Up @@ -7968,8 +7964,11 @@ window.guidedResumeProgress = async (datasetNameToResume) => {
}

if (!datasetHasAlreadyBeenSuccessfullyUploaded) {
console.log("DOing this resume logic");
// If the dataset is being edited on Pensieve, check to make sure the folders and files are still the same.
if (datasetResumeJsonObj["starting-point"]?.["type"] === "bf") {
console.log("DOing this resume logic inner");

// Check to make sure the dataset is not locked
const datasetIsLocked = await api.isDatasetLocked(
window.defaultBfAccount,
Expand Down Expand Up @@ -8049,6 +8048,11 @@ window.guidedResumeProgress = async (datasetNameToResume) => {
guidedSkipPage(pageID);
}

let guest = await window.isWorkspaceGuest();
if (!guest) {
guidedUnSkipPage("guided-designate-permissions-tab");
}

// Skip this page incase it was not skipped in a previous session
guidedSkipPage("guided-select-starting-point-tab");

Expand Down

0 comments on commit 821abf8

Please sign in to comment.