Skip to content

Commit

Permalink
Merge pull request #482 from carpentries/fix-permissions
Browse files Browse the repository at this point in the history
fix template page permissions issue
  • Loading branch information
zkamvar authored Jun 16, 2023
2 parents 055824f + 7a79de7 commit cde8907
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions R/render_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
file.append(tmpin, links)
path_in <- tmpin
Expand Down
21 changes: 17 additions & 4 deletions tests/testthat/test-render_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 file", {
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"))
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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, "<em>mowdrank</em> divs", fixed = TRUE)

})

0 comments on commit cde8907

Please sign in to comment.