Skip to content

Commit

Permalink
Merge pull request #10 from FvD/T5
Browse files Browse the repository at this point in the history
Integración de cambios en ixplorer.es
  • Loading branch information
FvD committed Sep 6, 2021
2 parents b710115 + 3a1e373 commit 69808a6
Show file tree
Hide file tree
Showing 56 changed files with 5,520 additions and 870 deletions.
70 changes: 37 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
Meta
doc
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
# Example code in package build process
*-Ex.R
# Output files from R CMD build
/*.tar.gz
# Output files from R CMD check
/*.Rcheck/
# RStudio files
.Rproj.user/
# produced vignettes
vignettes/*.html
vignettes/*.pdf
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth
# knitr and R markdown default cache directories
/*_cache/
/cache/
# Temporary files created by R markdown
*.utf8.md
*.knit.md
.Rproj.user
inst/doc
.Renviron
.gitignore
.gitignore
.ixplorer*
Meta
doc
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
# Example code in package build process
*-Ex.R
# Output files from R CMD build
/*.tar.gz
# Output files from R CMD check
/*.Rcheck/
# RStudio files
.Rproj.user/
# produced vignettes
vignettes/*.html
vignettes/*.pdf
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth
# knitr and R markdown default cache directories
/*_cache/
/cache/
# Temporary files created by R markdown
*.utf8.md
*.knit.md
.Rproj.user
inst/doc
.Renviron
.gitignore

.ixplorer*
.ixplorer


temp.R
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
URL: https://github.com/ixpantia/ixplorer
BugReports: https://github.com/ixpantia/ixplorer/issues

2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export(add_token)
export(create_tickets)
export(current_tickets)
export(dashboard)
export(incluye_upstream)
export(list_closed_tickets)
export(list_open_tickets)
import(dplyr)
import(miniUI)
import(shiny)
importFrom(dplyr,"%>%")
206 changes: 100 additions & 106 deletions R/authenticate.R
Original file line number Diff line number Diff line change
@@ -1,106 +1,100 @@
#' @import shiny
#' @import miniUI
NULL

#' Authenticate to ixplorer
#'
#' Make the connection to your repository through the ixplorer gadget and be
#' able to create tickets, review tickets without re-writing your credentials
#'
#' @export
add_token <- function() {

ui <- miniPage(
gadgetTitleBar("ixplorer authentication",
left = miniTitleBarCancelButton(inputId = "cancel",
label = "Cancel",
primary = FALSE),
right = miniTitleBarButton(inputId = "done",
label = "Done",
primary = TRUE)),

miniContentPanel(

textInput(inputId = "ixplorer_token",
label = "API token",
width = "100%",
placeholder = "Paste your ixplorer token here"),

textInput(inputId = "ixplorer_url",
label = "ixplorer url",
width = "100%",
placeholder = "Paste your ixplorer url here"),

textInput(inputId = "ixplorer_project_name",
label = "Name of the upstream project",
width = "100%",
placeholder = "Paste your ixplorer upstream project name here"),

textInput(inputId = "ixplorer_repo_name",
label = "ixplorer repository name",
width = "100%",
placeholder = "Paste your ixplorer repository name here"),

textInput(inputId = "ixplorer_user_name",
label = "Your ixplorer user name",
width = "100%",
placeholder = "Paste your ixplorer user name here"),

checkboxInput(inputId = "token_persist",
value = 0,
label = "Persist token? (do no use on shared computer)",
width = "100%"
)

)
)

server <- function(input, output, session) {

observeEvent(input$done, {

Sys.setenv("IXTOKEN" = input$ixplorer_token)
Sys.setenv("IXURL" = input$ixplorer_url)
Sys.setenv("IXPROJECT" = input$ixplorer_project_name)
Sys.setenv("IXREPO" = input$ixplorer_repo_name)
Sys.setenv("IXUSER" = input$ixplorer_user_name)

token <- paste0("IXTOKEN=", input$ixplorer_token)
url <- paste0("IXURL=", input$ixplorer_url)
project <- paste0("IXPROJECT=", input$ixplorer_project_name)
repo <- paste0("IXREPO=", input$ixplorer_repo_name)
user <- paste0("IXUSER=", input$ixplorer_user_name)

access_data <- c(token, url, project, repo, user)

if (input$token_persist == 1) {
working_directory <- rstudioapi::getActiveProject()
ixplorer_file <- paste0(working_directory, "/.ixplorer")
conn <- file(ixplorer_file, open = "w")
writeLines(access_data, con = conn, sep = "\n", useBytes = FALSE)
close(conn)

gitignore <- paste0(working_directory, "/.gitignore")
if (file.exists(gitignore)) {
conn <- file(gitignore)
archivos_ignorados <- readLines(conn)
writeLines(c(archivos_ignorados,".ixplorer"), conn) #lo sobre escribe
close(conn)
} else {
conn <- file(gitignore, open = "w")
writeLines(".ixplorer", con = conn, sep = "\n", useBytes = FALSE)
close(conn)
}

}
stopApp(NULL)
})

observeEvent(input$cancel, {
# do nothing
stopApp(NULL)
})
}

runGadget(ui, server, viewer = dialogViewer("ixplorer"))
}
#' @import shiny
#' @import miniUI
NULL

#' @title Autentificación en ixplorer
#' @description Guarda en su computadora por medio del sistema de
#' autentificación del OS de su computadora.
#'
#' @details En caso de que los credenciales ya existan solo se ingresa el url
#' y se confirma si quiere conservar los credenciales en su computador o quiere
#' borrarlos luego de la siguiente consulta.
#'
#' @export
add_token <- function() {

ui <- miniPage(
gadgetTitleBar("Autentificación en ixplorer",
left = miniTitleBarCancelButton(inputId = "cancel",
label = "Cancelar",
primary = FALSE),
right = miniTitleBarButton(inputId = "done",
label = "Listo",
primary = TRUE)),
miniContentPanel(
textInput(inputId = "ixplorer_url",
label = "URL de ixplorer",
width = "100%",
placeholder = "Copie su ixplorer URl aquí."),
uiOutput("token_user"),
checkboxInput(inputId = "token_persist",
value = 1,
label = "Persistencia de las credenciales en este computador. (No usar en computadoras compartidas)",
width = "100%"
)
)
)

server <- function(input, output, session) {

output$token_user <- renderUI({
req(input$ixplorer_url)

instancia <- sub("\\..*", "", input$ixplorer_url)

verifica_cred <- tryCatch(
keyring::key_get(paste0("token_", instancia)),
error = function(cond) "no_credenciales")

if(verifica_cred == "no_credenciales") {
div(textInput(inputId = "ixplorer_token",
label = "Token de acceso",
width = "100%",
placeholder = "Ingrese su Token de acceso aquí"),
textInput(inputId = "ixplorer_user_name",
label = "Su nombre de usuario.",
width = "100%",
placeholder = "Ingrese su nombre de usuario aquí."))
}

})

observeEvent(input$done, {

instancia <- sub("\\..*", "", input$ixplorer_url)

verifica_cred <- tryCatch(
keyring::key_get(paste0("token_", instancia)),
error = function(cond) "no_credenciales")


if(verifica_cred == "no_credenciales") {

if(is.null(input$ixplorer_url) == FALSE |
is.null(input$ixplorer_token) == FALSE |
is.null(input$ixplorer_user_name) == FALSE) {

keyring::key_set_with_value(
service = paste0("token_", instancia),
password = paste(input$ixplorer_url,
input$ixplorer_token,
input$ixplorer_user_name,
input$token_persist,
sep = "/"))
}

} else {

}

stopApp(TRUE)
})

observeEvent(input$cancel, {
# do nothing
stopApp(TRUE)
})
}

runGadget(ui, server, viewer = dialogViewer("ixplorer"))
}
Loading

0 comments on commit 69808a6

Please sign in to comment.