Skip to content

Commit

Permalink
feat: get permission for roles
Browse files Browse the repository at this point in the history
  • Loading branch information
tin900 committed Apr 25, 2024
1 parent 77311fd commit 88fb147
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export(get_group_users)
export(get_module_items)
export(get_modules)
export(get_page_content)
export(get_roles)
export(get_section_information)
export(get_student_summaries)
export(get_user_course_assignment_data)
Expand Down
26 changes: 26 additions & 0 deletions R/get_roles.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Retrieve Roles for a Canvas Account
#'
#' This function retrieves a paginated list of the roles available to a specific account in the Canvas LMS system.
#'
#' @param canvas A list containing the base URL and API key for the Canvas LMS instance.
#' @param account_id The ID of the account for which you want to retrieve the roles.
#' @param per_page The number of roles to retrieve per page (default is 100).
#'
#' @return A data frame containing the roles available to the specified account.
#'
#'
#' @export
get_roles <- function(canvas, account_id, per_page = 100) {
url <- paste0(canvas$base_url, "/api/v1/accounts/", account_id, "/roles?per_page=", per_page)
response <- httr::GET(url, httr::add_headers(Authorization = paste("Bearer", canvas$api_key)))

if (httr::status_code(response) != 200) {
stop("Failed to retrieve roles. Please check your authentication and API endpoint.")
}

roles <- httr::content(response, "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE)

return(roles)
}

20 changes: 10 additions & 10 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,16 +1050,16 @@ reference:
# - show_results
# - show_result
#
# title: Roles
# desc: >
# Manage roles.
# contents:
# - list_roles
# - get_role
# - create_role
# - deactivate_role
# - activate_role
# - update_role
- title: Roles
desc: >
Manage roles.
contents:
- list_roles
# - get_role
# - create_role
# - deactivate_role
# - activate_role
# - update_role
# title: Rubrics
# desc: >
# Manage rubrics.
Expand Down
21 changes: 21 additions & 0 deletions man/get_roles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88fb147

Please sign in to comment.