Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
whoHasAccess<-function(entityId) {
    moreResults<-T
    aas<-list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        page<-synRestGET(sprintf("/entity/%s/accessApproval?limit=999%s&offset=0%s", entityId, pageSize, offset))$results
    ups<-list()    if approvedUsers<-list((length(page)==0) moreResults<-F
   cat(sprintf("There are %d access approvals foraas entity %s<- append(aas, page)
        offset<-offset+pageSize
    }
    ups<-list()
    approvedUsers<-list()
    cat(sprintf("There are %d access approvals for entity %s\n", length(aas), entityId))
    for (aa in aas) {
        # cat(sprintf("approval id=%s requirement id=%s, user id=%s\n", aa$id, aa$requirementId, aa$accessorId))
        userId<-aa$accessorId
        reqId<-aa$requirementId
        if (!any(approvedUsers[[userId]]==reqId)) {
            approvedUsers[[userId]]<-append(approvedUsers[[userId]], reqId)
        }
        if (is.null(ups[[userId]])) {
            ups[[userId]]<-synRestGET(sprintf("/userProfile/%s", userId))
        }
        cat(".")
    }
    cat("\n")
    for (userId in names(approvedUsers)) {
        displayName<-ups[[userId]]$displayName
        userName<-ups[[userId]]$userName
        if (is.null(displayName)) {
            cat(sprintf("%s (id=%s) is approved for access requirement(s) %s\n", userName, userId,
                paste(approvedUsers[[userId]], collapse=",")))
        } else {
            cat(sprintf("%s (username=%s, id=%s) is approved for access requirement(s) %s\n", displayName, userName, userId,
                paste(approvedUsers[[userId]], collapse=",")))
        }
    }
}

...

Code Block
doesUserHaveAccess<-function(entityId, principalId) {

    moreResults<-T
    aas<-synRestGET(sprintf("/entity/%s/accessApproval?limit=999&offset=0", entityId))$resultslist()
    offset<-0
    pageSize<-25
    while approvedRequirements<-list(moreResults)  {
  cat(sprintf("There are %d access approvals for entity %s\n", length(aas), entityId)) page<-synRestGET(sprintf("/entity/%s/accessApproval?limit=%s&offset=%s", entityId, pageSize, offset))$results
     for  (aa in aas) {if (length(page)==0) moreResults<-F
        # cat(sprintf("approval id=%s requirement id=%s, user id=%s\n", aa$id, aa$requirementId, aa$accessorId))aas <- append(aas, page)
        offset<-offset+pageSize
    }
    userId<-aa$accessorIdapprovedRequirements<-list()
    cat(sprintf("There are %d access approvals reqId<-aa$requirementIdfor entity %s\n", length(aas), entityId))
    iffor (userId==principalId && !any(approvedRequirements==reqId))aa in aas) {
            approvedRequirements<-append(approvedRequirements, reqId)
           	# cat(sprintf("\nuserapproval %s was approved forid=%s requirement id=%s, by %s on user id=%s\n", principalIdaa$id, reqIdaa$requirementId, aa$createdBy, aa$createdOnaa$accessorId))
		}         cat(".")userId<-aa$accessorId
     }   reqId<-aa$requirementId
 cat("\n")     allRequirements<-list()  if (userId==principalId  ars<-synRestGET(sprintf("/entity/%s/accessRequirement", entityId))$results
&& !any(approvedRequirements==reqId)) {
   for (ar in ars) {         allRequirements<approvedRequirements<-append(allRequirementsapprovedRequirements, ar$idreqId)
    }     if (length(allRequirements)>0) allRequirements<-sort(unlist(allRequirements))
    if (length(approvedRequirements)>0) approvedRequirements<-sort(unlist(approvedRequirements))
    if (identical(allRequirements, approvedRequirements)) { 	cat(sprintf("\nuser %s was approved for requirement %s by %s on %s\n", principalId, reqId, aa$createdBy, aa$createdOn))
		}
        messagecat(sprintf("."User)
%s DOES have access approvals}
for ALL %d access requirement(s) on %s",cat("\n")
    allRequirements<-list()
         principalId, length(allRequirements)ars<-synRestGET(sprintf("/entity/%s/accessRequirement", entityId))$results
    for (ar }in elsears) {
        if (length(approvedRequirements>0)allRequirements<-append(allRequirements, ar$id)
{    }
        if (length(allRequirements)>0) allRequirements<-sort(unlist(allRequirements))
    if (length(approvedRequirements)>0) approvedRequirements<-sort(unlist(approvedRequirements))
    if (identical(allRequirements, approvedRequirements)) {
        message(sprintf("User %s does NOTDOES have access approvals for all theALL %d access requirement(s) on %s, only for %s", 
  
             principalId, length(allRequirements), entityId, paste(approvedRequirements, collapse=",")))
    } else {
  } else      if (length(approvedRequirements>0)) {
            message(sprintf("User %s does NOT have access approvals for ANY ofall the %d access requirement(s) on %s, only for %s", 
                principalId, length(allRequirements), entityId, paste(approvedRequirements, collapse=",")))
        } else {
    }
}

(TODO:  We can also display the date/time when approval was granted.)

 

...

        message(sprintf("User %s does NOT have access approvals for ANY of the %d access requirement(s) on %s", 
                principalId, length(allRequirements), entityId))
        }
    }
}

(TODO:  We can also display the date/time when approval was granted.)

 

How to grant access for a specific access requirement:

...

Code Block
removeAccess<-function(entityId, principalId) {

    moreResults<-T
    aas<-list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        page<-synRestGET(sprintf("/entity/%s/accessApproval?limit=999%s&offset=0%s", entityId, pageSize, offset))$results
    cat(sprintf("There are %d access approvals for entity %s\n", if (length(aas), entityId)page)==0) moreResults<-F
   for (aa     aas <- append(aas, page)
        offset<-offset+pageSize
    }
    cat(sprintf("There are %d access approvals for entity %s\n", length(aas), entityId))
    for (aa in aas) {
        # cat(sprintf("approval id=%s requirement id=%s, user id=%s\n", aa$id, aa$requirementId, aa$accessorId))
        userId<-aa$accessorId
        reqId<-aa$requirementId
        if (userId==principalId) {
            synRestDELETE(sprintf("/accessApproval/%s", aa$id))
            cat(sprintf("\nRemoved access approval for access requirement %s.\n", reqId))
        }
        cat(".")
    }
    cat("\n")
}

...

Code Block
whoHasAccessToTeam<-function(teamId) {

    moreResults<-T
    aas<-synRestGET(sprintf(list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        page<-synRestGET(sprintf("/team/%s/accessApproval?limit=999%s&offset=0%s", teamId, pageSize, offset))$results
    ups<-list()    if approvedUsers<-list((length(page)==0) moreResults<-F
   cat(sprintf("There are %d access approvals for Team %s\n", lengthaas <- append(aas), teamId))
    page)
        offset<-offset+pageSize
    }
    ups<-list()
    approvedUsers<-list()
    cat(sprintf("There are %d access approvals for Team %s\n", length(aas), teamId))
    for (aa in aas) {
        userId<-aa$accessorId
        reqId<-aa$requirementId
        if (!any(approvedUsers[[userId]]==reqId)) {
            approvedUsers[[userId]]<-append(approvedUsers[[userId]], reqId)
        }
        if (is.null(ups[[userId]])) {
            ups[[userId]]<-synRestGET(sprintf("/userProfile/%s", userId))
        }
        cat(".")
    }
    cat("\n")
    for (userId in names(approvedUsers)) {
        displayName<-ups[[userId]]$displayName
        userName<-ups[[userId]]$userName
        if (is.null(displayName)) {
            cat(sprintf("%s (id=%s) is approved for access requirement(s) %s\n", userName, userId,
                paste(approvedUsers[[userId]], collapse=",")))
        } else {
            cat(sprintf("%s (username=%s, id=%s) is approved for access requirement(s) %s\n", displayName, userName, userId,
                paste(approvedUsers[[userId]], collapse=",")))
        }
    }
}

...

Code Block
isUserApprovedToJoinTeam<-function(teamId, principalId) {

    moreResults<-T
    aas<-synRestGET(sprintf("/list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        page<-synRestGET(sprintf("/team/%s/accessApproval?limit=999%s&offset=0%s", teamId, pageSize, offset))$results
        if (length(page)==0) moreResults<-F
        aas <- append(aas, page)
        offset<-offset+pageSize
    }
    approvedRequirements<-list()
    cat(sprintf("There are %d access approvals for team %s\n", length(aas), teamId))
    for (aa in aas) {
        userId<-aa$accessorId
        reqId<-aa$requirementId
        if (userId==principalId && !any(approvedRequirements==reqId)) {
            approvedRequirements<-append(approvedRequirements, reqId)
           	cat(sprintf("\nuser %s was approved for requirement %s by %s on %s\n", principalId, reqId, aa$createdBy, aa$createdOn))
		}
        cat(".")
    }
    cat("\n")
    allRequirements<-list()
    ars<-synRestGET(sprintf("/team/%s/accessRequirement", teamId))$results
    for (ar in ars) {
        allRequirements<-append(allRequirements, ar$id)
    }
    if (length(allRequirements)>0) allRequirements<-sort(unlist(allRequirements))
    if (length(approvedRequirements)>0) approvedRequirements<-sort(unlist(approvedRequirements))
    if (identical(allRequirements, approvedRequirements)) {
        message(sprintf("User %s DOES have access approvals for ALL %d access requirement(s) on %s", 
            principalId, length(allRequirements), teamId))
    } else {
        if (length(approvedRequirements>0)) {
            message(sprintf("User %s does NOT have access approvals for all the %d access requirement(s) on %s, only for %s", 
                principalId, length(allRequirements), teamId, paste(approvedRequirements, collapse=",")))
        } else {
            message(sprintf("User %s does NOT have access approvals for ANY of the %d access requirement(s) on %s", 
                principalId, length(allRequirements), teamId))
        }
    }
}

...