forked from PecanProject/pecan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into PecanProjectGH-2572-permission-issues-in-…
…docker
- Loading branch information
Showing
96 changed files
with
2,954 additions
and
4,056 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
library(dplyr) | ||
|
||
#' Retrieve the details of a PEcAn format, based on format_id | ||
#' @param format_id Format ID (character) | ||
#' @return Format details | ||
#' @author Tezan Sahu | ||
#* @get /<format_id> | ||
getFormat <- function(format_id, res){ | ||
|
||
dbcon <- PEcAn.DB::betyConnect() | ||
|
||
Format <- tbl(dbcon, "formats") %>% | ||
select(format_id = id, name, notes, header, mimetype_id) %>% | ||
filter(format_id == !!format_id) | ||
|
||
Format <- tbl(dbcon, "mimetypes") %>% | ||
select(mimetype_id = id, mimetype = type_string) %>% | ||
inner_join(Format, by = "mimetype_id") %>% | ||
select(-mimetype_id) | ||
|
||
qry_res <- Format %>% collect() | ||
|
||
if (nrow(qry_res) == 0) { | ||
PEcAn.DB::db.close(dbcon) | ||
res$status <- 404 | ||
return(list(error="Format not found")) | ||
} | ||
else { | ||
# Convert the response from tibble to list | ||
response <- list() | ||
for(colname in colnames(qry_res)){ | ||
response[colname] <- qry_res[colname] | ||
} | ||
|
||
format_vars <- tbl(dbcon, "formats_variables") %>% | ||
select(name, unit, format_id, variable_id) %>% | ||
filter(format_id == !!format_id) | ||
format_vars <- tbl(dbcon, "variables") %>% | ||
select(variable_id = id, description, units) %>% | ||
inner_join(format_vars, by="variable_id") %>% | ||
mutate(unit = ifelse(unit %in% "", units, unit)) %>% | ||
select(-variable_id, -format_id, -units) %>% | ||
collect() | ||
|
||
PEcAn.DB::db.close(dbcon) | ||
|
||
response$format_variables <- format_vars | ||
return(response) | ||
} | ||
} | ||
|
||
######################################################################### | ||
|
||
#' Search for PEcAn format(s) containing wildcards for filtering | ||
#' @param format_name Format name search string (character) | ||
#' @param mimetype Mime type search string (character) | ||
#' @param ignore_case Logical. If `TRUE` (default) use case-insensitive search otherwise, use case-sensitive search | ||
#' @return Formats subset matching the model search string | ||
#' @author Tezan Sahu | ||
#* @get / | ||
searchFormats <- function(format_name="", mimetype="", ignore_case=TRUE, res){ | ||
format_name <- URLdecode(format_name) | ||
mimetype <- URLdecode(mimetype) | ||
|
||
dbcon <- PEcAn.DB::betyConnect() | ||
|
||
Formats <- tbl(dbcon, "formats") %>% | ||
select(format_id = id, format_name=name, mimetype_id) %>% | ||
filter(grepl(!!format_name, format_name, ignore.case=ignore_case)) | ||
|
||
Formats <- tbl(dbcon, "mimetypes") %>% | ||
select(mimetype_id = id, mimetype = type_string) %>% | ||
inner_join(Formats, by = "mimetype_id") %>% | ||
filter(grepl(!!mimetype, mimetype, ignore.case=ignore_case)) %>% | ||
select(-mimetype_id) %>% | ||
arrange(format_id) | ||
|
||
qry_res <- Formats %>% collect() | ||
|
||
PEcAn.DB::db.close(dbcon) | ||
|
||
if (nrow(qry_res) == 0) { | ||
res$status <- 404 | ||
return(list(error="Format(s) not found")) | ||
} | ||
else { | ||
return(list(formats=qry_res, count = nrow(qry_res))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
library(dplyr) | ||
|
||
get.file <- function(filepath, userid) { | ||
# Check if the file path is valid | ||
if(! file.exists(filepath)){ | ||
return(list(status = "Error", message = "File not found")) | ||
} | ||
|
||
# Check if the workflow for run after obtaining absolute path is owned by the user or not | ||
parent_dir <- normalizePath(dirname(filepath)) | ||
|
||
run_id <- substr(parent_dir, stringi::stri_locate_last(parent_dir, regex="/")[1] + 1, stringr::str_length(parent_dir)) | ||
|
||
if(Sys.getenv("AUTH_REQ") == TRUE) { | ||
dbcon <- PEcAn.DB::betyConnect() | ||
|
||
Run <- tbl(dbcon, "runs") %>% | ||
filter(id == !!run_id) | ||
Run <- tbl(dbcon, "ensembles") %>% | ||
select(ensemble_id=id, workflow_id) %>% | ||
full_join(Run, by="ensemble_id") %>% | ||
filter(id == !!run_id) | ||
user_id <- tbl(dbcon, "workflows") %>% | ||
select(workflow_id=id, user_id) %>% full_join(Run, by="workflow_id") %>% | ||
filter(id == !!run_id) %>% | ||
pull(user_id) | ||
|
||
PEcAn.DB::db.close(dbcon) | ||
|
||
if(! user_id == userid) { | ||
return(list(status = "Error", message = "Access forbidden")) | ||
} | ||
} | ||
|
||
# Read the data in binary form & return it | ||
bin <- readBin(filepath,'raw', n = file.info(filepath)$size) | ||
return(list(file_contents = bin)) | ||
} |
Oops, something went wrong.