Skip to content

Commit

Permalink
[DAPS-1110] add refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
AronPerez committed Feb 3, 2025
1 parent 0676dd8 commit 1417ed3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 62 deletions.
13 changes: 11 additions & 2 deletions web/datafed-ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ app.use(
}),
);

function storeCollectionId(req, res, next) {
if (req.query.collection_id) {
req.session.collection_id = req.query.collection_id;
}
next();
}


app.use(cookieParser(g_session_secret));
app.use(
helmet({
Expand Down Expand Up @@ -622,6 +630,7 @@ app.get("/ui/authn", (a_req, a_resp) => {
} catch (err) {
redirect_path = "/ui/error";
logger.error("/ui/authn", getCurrentLineNumber(), err);
delete a_req.session.collection_id;
}

// TODO Account may be disable from SDMS (active = false)
Expand Down Expand Up @@ -1549,7 +1558,7 @@ app.post("/api/cat/search", (a_req, a_resp) => {
*
* This function generates the authorization URL that a user can follow to provide
* authorization and consent via Globus Auth.
*
* @param {string} [collection_id=""] - The specified collection id
* @param {Array<string>} [requested_scopes=[]] - The scopes on the token(s) being requested.
* In the case of accessing a mapped collection, this should include the mapped
* collection's UUID, such as: `https://auth.globus.org/scopes/YOUR-UUID-HERE/data_access`.
Expand All @@ -1569,7 +1578,7 @@ app.post("/api/cat/search", (a_req, a_resp) => {
* { custom_param: 'value' }
* );
*/
app.get("/api/globus/authorize_url", (a_req, a_resp) => {
app.get("/api/globus/authorize_url", storeCollectionId, (a_req, a_resp) => {
const client_id = g_oauth_credentials.clientId;
const redirect_uri = g_oauth_credentials.redirectUri;
const { requested_scopes, state, refresh_tokens, query_params } = a_req.query;
Expand Down
12 changes: 7 additions & 5 deletions web/static/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,15 +1013,17 @@ export function themeSave(a_theme, a_cb) {
}

export function getGlobusAuthorizeURL(
requested_scopes,
a_cb,
refresh_tokens = false,
query_params = {},
state = "_default",
a_cb,
collection_id,
requested_scopes,
refresh_tokens = false,
query_params = {},
state = "_default",
) {
_asyncGet(
"/api/globus/authorize_url",
{
collection_id,
refresh_tokens,
requested_scopes: requested_scopes.join(","),
query_params: JSON.stringify(query_params),
Expand Down
119 changes: 64 additions & 55 deletions web/static/components/endpoint-browse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ class EndpointBrowser {
// Fetch directory listing
api.epDirList(this.props.endpoint.id, this.state.path, false, (data) => {
this.updateTree(data);
// this.handleApiResponse(data);

// // Reset loading state
// this.state.loading = false;
// $("#file_tree").fancytree("enable");
});
}

Expand All @@ -216,71 +211,85 @@ class EndpointBrowser {
* @param {Object} data - The data to update the tree with

Check failure on line 211 in web/static/components/endpoint-browse/index.js

View workflow job for this annotation

GitHub Actions / lint-javascript

Invalid JSDoc @param "data" type "Object"; prefer: "object"
*/
updateTree(data) {
let source;
const source = this.getTreeSource(data);
$.ui.fancytree.getTree("#file_tree").reload(source);
this.state.loading = false;
$("#file_tree").fancytree("enable");

}

/**
* Get tree source data
* @param {Object} data - API response data

Check failure on line 223 in web/static/components/endpoint-browse/index.js

View workflow job for this annotation

GitHub Actions / lint-javascript

Invalid JSDoc @param "data" type "Object"; prefer: "object"
* @returns {Array} Tree source data
*/
getTreeSource(data) {
if (data.code) {
if (data.code === "ConsentRequired") {
api.getGlobusAuthorizeURL(data.required_scopes, (ok, data) => {
source = [
{
title: `<span class='ui-state-error'>Consent Required: Please provide <a href="${data.authorize_url}">consent</a>.</span>`,
icon: false,
is_dir: true,
},
];
return this.handleApiError(data);
}
return [
{
title: CONFIG.PATH.CURRENT,
icon: CONFIG.UI.ICONS.FOLDER,
key: CONFIG.PATH.CURRENT,
is_dir: true,
},
{
title: CONFIG.PATH.UP,
icon: CONFIG.UI.ICONS.FOLDER,
key: CONFIG.PATH.UP,
is_dir: true,
},
...data.DATA.map((entry) =>
entry.type === "dir"
? {
title: entry.name,
icon: CONFIG.UI.ICONS.FOLDER,
key: entry.name,
is_dir: true,
}
: {
title: entry.name,
icon: CONFIG.UI.ICONS.FILE,
key: entry.name,
is_dir: false,
size: util.sizeToString(entry.size),
date: new Date(entry.last_modified.replace(" ", "T")).toLocaleString(),
},
),
];
}

$.ui.fancytree.getTree("#file_tree").reload(source);
this.state.loading = false;
$("#file_tree").fancytree("enable");
});
} else {
source = [
/**
* Handle API error responses
* @param {Object} data - API response data

Check failure on line 265 in web/static/components/endpoint-browse/index.js

View workflow job for this annotation

GitHub Actions / lint-javascript

Invalid JSDoc @param "data" type "Object"; prefer: "object"
* @returns {Array} Error message source
*/
handleApiError(data) {
if (data.code === "ConsentRequired") {
api.getGlobusAuthorizeURL((ok, data) => {
const source = [
{
title: `<span class='ui-state-error'>Error: ${data.message}</span>`,
title: `<span class='ui-state-error'>Consent Required: Please provide <a href="${data.authorize_url}">consent</a>.</span>`,
icon: false,
is_dir: true,
},
];
}

$.ui.fancytree.getTree("#file_tree").reload(source);
this.state.loading = false;
$("#file_tree").fancytree("enable");
}, this.props.endpoint.id, data.required_scopes);
} else {
source = [
{
title: CONFIG.PATH.CURRENT,
icon: CONFIG.UI.ICONS.FOLDER,
key: CONFIG.PATH.CURRENT,
is_dir: true,
},
return [
{
title: CONFIG.PATH.UP,
icon: CONFIG.UI.ICONS.FOLDER,
key: CONFIG.PATH.UP,
title: `<span class='ui-state-error'>Error: ${data.message}</span>`,
icon: false,
is_dir: true,
},
...data.DATA.map((entry) =>
entry.type === "dir"
? {
title: entry.name,
icon: CONFIG.UI.ICONS.FOLDER,
key: entry.name,
is_dir: true,
}
: {
title: entry.name,
icon: CONFIG.UI.ICONS.FILE,
key: entry.name,
is_dir: false,
size: util.sizeToString(entry.size),
date: new Date(
entry.last_modified.replace(" ", "T"),
).toLocaleString(),
},
),
];
}

$.ui.fancytree.getTree("#file_tree").reload(source);
this.state.loading = false;
$("#file_tree").fancytree("enable");
}

/**
Expand Down

0 comments on commit 1417ed3

Please sign in to comment.