From 679bb5316859def5b49ebe130a642a3f7855de4d Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 15 Jun 2023 10:47:07 -0700 Subject: [PATCH 1/4] add test to validate permissions reassignment --- tests/testthat/test-render_html.R | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-render_html.R b/tests/testthat/test-render_html.R index 606a15a5f..c46010b8f 100644 --- a/tests/testthat/test-render_html.R +++ b/tests/testthat/test-render_html.R @@ -11,6 +11,19 @@ test_that("sandpaper.links can be included", { expect_no_match(render_html(tmp), "\\[link at the end\\]") }) +test_that("sandpaper.links can be included even with read-only template", { + skip_if_not(rmarkdown::pandoc_available("2.11")) + tmp <- withr::local_tempfile() + tnk <- withr::local_tempfile() + writeLines("This has a [link at the end] in a separate file[^1]\n\n[^1]: :)", tmp) + + perm <- fs::file_info(tmp)$permissions + withr::defer(fs::file_chmod(tmp, perm), priority = "first") + fs::file_chmod(tmp, "a-w") + writeLines("[link at the end]: https://example.com/link", tnk) + withr::local_options(list("sandpaper.links" = tnk)) + expect_no_match(render_html(tmp), "\\[link at the end\\]") +}) test_that("tabs are preserved", { skip_if_not(rmarkdown::pandoc_available("2.11")) @@ -63,7 +76,7 @@ test_that("footnotes are rendered", { }) test_that("pandoc structure is rendered correctly", { - + skip_if_not(rmarkdown::pandoc_available("2.11")) out <- fs::file_temp() withr::local_file(out) @@ -83,7 +96,7 @@ test_that("pandoc structure is rendered correctly", { }) test_that("paragraphs after objectives block are parsed correctly", { - + skip_if_not(rmarkdown::pandoc_available("2.11")) tmp <- fs::file_temp() out <- fs::file_temp() @@ -136,7 +149,7 @@ test_that("render_html applies the internal lua filter", { formation = function(x) { x <- sub("[<]div id[=]\"collapseSolution1\".+", "[solution collapse]", x) sub("[<]div id[=]\"collapseInstructor1\".+", "[instructor collapse]", x) - + } expect_snapshot(cat(res), transform = formation) }) @@ -194,5 +207,5 @@ test_that("render_html applies external lua filters", { writeLines(lu, lua) res <- render_html(example_markdown, paste0("--lua-filter=", lua)) expect_match(res, "mowdrank divs", fixed = TRUE) - + }) From 92093753836a68b364b005b2b57350b6119334ef Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 15 Jun 2023 10:52:43 -0700 Subject: [PATCH 2/4] add comment about the change inline --- R/render_html.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/render_html.R b/R/render_html.R index 4926ef90d..f50736500 100644 --- a/R/render_html.R +++ b/R/render_html.R @@ -49,6 +49,9 @@ render_html <- function(path_in, ..., quiet = FALSE) { # if we have links, we concatenate our input files tmpin <- tempfile(fileext = ".md") fs::file_copy(path_in, tmpin) + # if the file is not readable by the user, then we need to make it readable + # https://github.com/carpentries/sandpaper/issues/479 + fs::file_chmod(tmpin, "u+w") cat("\n", file = tmpin, append = TRUE) file.append(tmpin, links) path_in <- tmpin From b492209587774ee4b83d5f911ce2ee84b4ccddca Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 15 Jun 2023 10:53:34 -0700 Subject: [PATCH 3/4] bump version and news --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ tests/testthat/test-render_html.R | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dc174a02a..5855eb975 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sandpaper Title: Create and Curate Carpentries Lessons -Version: 0.12.3 +Version: 0.12.4 Authors@R: c( person(given = "Zhian N.", family = "Kamvar", diff --git a/NEWS.md b/NEWS.md index 67e498ed8..dd86f841d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# sandpaper 0.12.4 (unreleased) + +* A bug in walled systems where templated pages (e.g. 404) could not be written + due to permissions issues has been fixed (reported: @ocaisa, #479; fixed: + @zkamvar, #482). + # sandpaper 0.12.3 (2023-06-01) * A bug where the git credentials are accidentally changed when a lesson is diff --git a/tests/testthat/test-render_html.R b/tests/testthat/test-render_html.R index c46010b8f..c6544a857 100644 --- a/tests/testthat/test-render_html.R +++ b/tests/testthat/test-render_html.R @@ -11,7 +11,7 @@ test_that("sandpaper.links can be included", { expect_no_match(render_html(tmp), "\\[link at the end\\]") }) -test_that("sandpaper.links can be included even with read-only template", { +test_that("sandpaper.links can be included even with read-only template file", { skip_if_not(rmarkdown::pandoc_available("2.11")) tmp <- withr::local_tempfile() tnk <- withr::local_tempfile() From 7a79de740f32a92223dc58bb432e9b0308ed1c9a Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 15 Jun 2023 12:05:50 -0700 Subject: [PATCH 4/4] Update R/render_html.R Co-authored-by: ocaisa --- R/render_html.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/render_html.R b/R/render_html.R index f50736500..e56eb071a 100644 --- a/R/render_html.R +++ b/R/render_html.R @@ -49,7 +49,7 @@ render_html <- function(path_in, ..., quiet = FALSE) { # if we have links, we concatenate our input files tmpin <- tempfile(fileext = ".md") fs::file_copy(path_in, tmpin) - # if the file is not readable by the user, then we need to make it readable + # if the file is not writable by the user, then we need to make it writable # https://github.com/carpentries/sandpaper/issues/479 fs::file_chmod(tmpin, "u+w") cat("\n", file = tmpin, append = TRUE)