Initial R function implementations
This commit is contained in:
50
R/Groups.R
Normal file
50
R/Groups.R
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
group_id <- function(name, ...) {
|
||||||
|
checkmate::assert_string(name)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_groupId, conn_ref, name)
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
group_exists <- function(name, ...) {
|
||||||
|
return(!is.na(group_id(name)))
|
||||||
|
}
|
||||||
|
group_create <- function(name, id = NULL, ...) {
|
||||||
|
checkmate::assert_string(name)
|
||||||
|
if (!checkmate::test_null(id)) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
} else {
|
||||||
|
id <- 0
|
||||||
|
}
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_createGroup, conn_ref, as.integer(id), name)
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
group_delete <- function(id, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_deleteGroup, conn_ref, as.integer(id))
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
group <- function(id, withMembers = TRUE, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
checkmate::assert_logical(withMembers)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_group, conn_ref, as.integer(id), as.logical(withMembers))
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
groups <- function(withMembers = FALSE, withDeleted = FALSE, ...)
|
||||||
|
{
|
||||||
|
checkmate::assert_logical(withMembers)
|
||||||
|
checkmate::assert_logical(withDeleted)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(
|
||||||
|
c_rmodb_groups, conn_ref, as.logical(withMembers), as.logical(withDeleted)
|
||||||
|
)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
23
R/Helpers.R
Normal file
23
R/Helpers.R
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
check_namesInclude = function(x, one.of = list(), all.of = list()) {
|
||||||
|
gotOne <- 0
|
||||||
|
gotX <- 0
|
||||||
|
for (n in x) {
|
||||||
|
if (n %in% one.of) {
|
||||||
|
return(TRUE)
|
||||||
|
}
|
||||||
|
if (n %in% all.of) {
|
||||||
|
gotX <- gotX + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gotX != length(all.of)) {
|
||||||
|
return(FALSE)
|
||||||
|
}
|
||||||
|
if (length(one.of) > 0 && gotOne == 0) {
|
||||||
|
return(FALSE)
|
||||||
|
}
|
||||||
|
|
||||||
|
return(TRUE)
|
||||||
|
}
|
||||||
|
test_namesInclude <- checkmate::makeTestFunction(check_namesInclude)
|
||||||
|
assert_namesInclude <- checkmate:: makeAssertionFunction(check_namesInclude)
|
||||||
100
R/Metaobject.R
Normal file
100
R/Metaobject.R
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
|
||||||
|
metaobject_ids <- function(title, ...) {
|
||||||
|
checkmate::assert_string(title)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_metaobjectId, conn_ref, title)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
metaobject_create <- function(meta, obj, id = NULL, ...) {
|
||||||
|
if (!checkmate::test_null(id)) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
} else {
|
||||||
|
id <- 0
|
||||||
|
}
|
||||||
|
|
||||||
|
checkmate::assert_list(meta)
|
||||||
|
checkmate::assert_names(names(meta), must.include = c("title"))
|
||||||
|
assert_namesInclude(names(meta), one.of = c("owner", "owner_id"))
|
||||||
|
if (test_namesInclude(names(meta), all.of = c("owner"))) {
|
||||||
|
checkmate::assert_class(meta$owner, "modb_user")
|
||||||
|
meta$owner_id <- meta$owner$id
|
||||||
|
} else {
|
||||||
|
checkmate::assert_int(meta$owner_id)
|
||||||
|
}
|
||||||
|
meta$owner_id <- as.integer(meta$owner_id)
|
||||||
|
|
||||||
|
assert_namesInclude(names(meta), one.of = c("groups", "group_ids"))
|
||||||
|
if (checkmate::test_null(meta$group_ids)) {
|
||||||
|
meta$group_ids <- list()
|
||||||
|
} else if (test_namesInclude(names(meta), all.of = c("groups"))) {
|
||||||
|
meta$group_ids <- list()
|
||||||
|
for (g in meta$groups) {
|
||||||
|
checkmate::assert_class(g, "modb_group")
|
||||||
|
meta$group_ids <- c(meta$group_ids, g$id)
|
||||||
|
}
|
||||||
|
} else if (checkmate::test_list(meta$group_ids)) {
|
||||||
|
if (length(meta$group_ids) > 0) {
|
||||||
|
checkmate::assert_integerish(unlist(meta$group_ids))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkmate::assert_integerish(meta$group_ids)
|
||||||
|
}
|
||||||
|
meta$group_ids <- c(as.integer(meta$group_ids))
|
||||||
|
|
||||||
|
if (!checkmate::test_null(id)) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
id <- id
|
||||||
|
} else {
|
||||||
|
if (test_namesInclude(names(meta), all.of = c("id"))) {
|
||||||
|
checkmate::assert_int(meta$id)
|
||||||
|
id <- meta$id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
meta_fields <- c(
|
||||||
|
"id", "title", "owner_id", "owner", "groups", "group_ids",
|
||||||
|
"created_on", "updated_on", "deleted_on"
|
||||||
|
)
|
||||||
|
ext <- meta[!(names(meta) %in% meta_fields)]
|
||||||
|
meta <- meta[names(meta) %in% c("title", "owner_id", "group_ids")]
|
||||||
|
|
||||||
|
|
||||||
|
utils::str(meta)
|
||||||
|
utils::str(ext)
|
||||||
|
utils::str(obj)
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_createMetaobject, conn_ref, as.integer(id), meta, obj, ext)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
metaobject_delete <- function(id, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_deleteMetaobject, conn_ref, as.integer(id))
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
metaobject <- function(id, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_metaobject, conn_ref, as.integer(id))
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
metaobjects <- function(withDeleted = FALSE, ...)
|
||||||
|
{
|
||||||
|
checkmate::assert_logical(withDeleted)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(
|
||||||
|
c_rmodb_metaobjects, conn_ref, as.logical(withDeleted)
|
||||||
|
)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
44
R/UserGroups.R
Normal file
44
R/UserGroups.R
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
link_user_group <- function(user, group, ...) {
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
if (checkmate::test_list(user)) {
|
||||||
|
checkmate::assert_names(names(user), must.include = c("id"))
|
||||||
|
user_id <- as.integer(user$id)
|
||||||
|
} else {
|
||||||
|
checkmate::assert_int(user)
|
||||||
|
user_id <- as.integer(user)
|
||||||
|
}
|
||||||
|
if (checkmate::test_list(group)) {
|
||||||
|
checkmate::assert_names(names(group), must.include = c("id"))
|
||||||
|
group_id <- as.integer(group$id)
|
||||||
|
} else {
|
||||||
|
checkmate::assert_int(group)
|
||||||
|
group_id <- as.integer(group)
|
||||||
|
}
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_userAddGroup, conn_ref, user_id, group_id)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink_user_group <- function(user, group, ...) {
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
if (checkmate::test_list(user)) {
|
||||||
|
checkmate::assert_names(names(user), must.include = c("id"))
|
||||||
|
user_id <- as.integer(user$id)
|
||||||
|
} else {
|
||||||
|
checkmate::assert_int(user)
|
||||||
|
user_id <- as.integer(user)
|
||||||
|
}
|
||||||
|
if (checkmate::test_list(group)) {
|
||||||
|
checkmate::assert_names(names(group), must.include = c("id"))
|
||||||
|
group_id <- as.integer(group$id)
|
||||||
|
} else {
|
||||||
|
checkmate::assert_int(group)
|
||||||
|
group_id <- as.integer(group)
|
||||||
|
}
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_userRemoveGroup, conn_ref, user_id, group_id)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
52
R/Users.R
Normal file
52
R/Users.R
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
user_id <- function(name, ...) {
|
||||||
|
checkmate::assert_string(name)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_userId, conn_ref, name)
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
user_exists <- function(name, ...) {
|
||||||
|
return(!is.na(user_id(name)))
|
||||||
|
}
|
||||||
|
user_create <- function(name, email, id = NULL, ...) {
|
||||||
|
checkmate::assert_string(name)
|
||||||
|
checkmate::assert_string(email)
|
||||||
|
if (!checkmate::test_null(id)) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
} else {
|
||||||
|
id <- 0
|
||||||
|
}
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_createUser, conn_ref, as.integer(id), name, email)
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
user_delete <- function(id, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_deleteUser, conn_ref, as.integer(id))
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
user <- function(id, withGroups = TRUE, ...) {
|
||||||
|
checkmate::assert_int(id)
|
||||||
|
checkmate::assert_logical(withGroups)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(c_rmodb_user, conn_ref, as.integer(id), as.logical(withGroups))
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
|
users <- function(withGroups = FALSE, withDeleted = FALSE, ...)
|
||||||
|
{
|
||||||
|
checkmate::assert_logical(withGroups)
|
||||||
|
checkmate::assert_logical(withDeleted)
|
||||||
|
conn_ref <- modb_conn_ref(args = list(...))
|
||||||
|
|
||||||
|
res <- .Call(
|
||||||
|
c_rmodb_users, conn_ref, as.logical(withGroups), as.logical(withDeleted)
|
||||||
|
)
|
||||||
|
|
||||||
|
return(res)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user