Versions Compared

Key

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

NOTE:

...

 The scripts below are replaced by the tool set now built into Synapse.  To access:

  1. Log into Synapse as an ACT member.

  2. Go to the dataset of interest.

  3. Select Tools > Change User Access - or - Manage Access Requirements

If the tools built in to Synapse do not meet your needs, kindly contact the Synapse Engineering Team via JIRA.


Table of Contents

 

This page contains the instructions to be followed by the Access and Compliance team for managing access restrictions on data in Synapse.

...

Code Block
whoHasAccess<-function(entityId) {
    aas<-synRestGET(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$accessorId }
    approvedRequirements<-list()
  reqId<-aa$requirementId  cat(sprintf("There are %d access approvals for entity if%s\n", (userId==principalId && !any(approvedRequirements==reqIdlength(aas), entityId))
{    for (aa in aas) {
    approvedRequirements<-append(approvedRequirements, reqId)            	# cat(sprintf("\nuserapproval id=%s was approved for requirement id=%s, by %s on user id=%s\n", principalIdaa$id, reqIdaa$requirementId, aa$createdBy, aa$createdOnaa$accessorId))
		}
        userId<-aa$accessorId
     cat(".")   reqId<-aa$requirementId
 }     cat("\n")  if (userId==principalId  allRequirements<-list()
&& !any(approvedRequirements==reqId)) {
   ars<-synRestGET(sprintf("/entity/%s/accessRequirement", entityId))$results        for (ar in ars) {approvedRequirements<-append(approvedRequirements, reqId)
           allRequirements<-append(allRequirements, ar$id)
    }
    if (length(allRequirements)>0) allRequirements<-sort(unlist(allRequirements))	cat(sprintf("\nuser %s was approved for requirement %s by %s on %s\n", principalId, reqId, aa$createdBy, aa$createdOn))
		}
       if (length(approvedRequirements)>0) approvedRequirements<-sort(unlist(approvedRequirements))
cat(".")
    }
   if (identical(allRequirements, approvedRequirements)) {cat("\n")
    allRequirements<-list()
    messagears<-synRestGET(sprintf("User %s DOES have access approvals/entity/%s/accessRequirement", entityId))$results
    for ALL(ar %d access requirement(sin ars) on{
%s",              principalId, lengthallRequirements<-append(allRequirements), entityId)ar$id)
    }
else {   if (length(allRequirements)>0) allRequirements<-sort(unlist(allRequirements))
    if (length(approvedRequirements>0approvedRequirements)>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 {
        } elseif (length(approvedRequirements>0)) {
            message(sprintf("User %s does NOT have access approvals for ANYall of 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.)

 

How to grant access for a specific access requirement:

Use the following function, which you can cut/paste into your R session:

Code Block
grantAccess<-function(requirementId, principalId) {     actApproval <- listmessage(sprintf(concreteType=""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:

Use the following function, which you can cut/paste into your R session:

Code Block
grantAccess<-function(requirementId, principalId) {
    actApproval <- list(concreteType="org.sagebionetworks.repo.model.ACTAccessApproval", requirementId=requirementId, accessorId=principalId, approvalStatus="APPROVED")
    actApproval<-synRestPOST("/accessApproval", actApproval)
}

...

Use the following function, which you can cut/paste into your R session:

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

    moreResults<-T
    aas<-list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        aas<page<-synRestGET(sprintf("/entity/%s/accessApproval?limit=999%s&offset=0", entityId))$results%s", entityId, pageSize, offset))$results
        if (length(page)==0) moreResults<-F
        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 reqId<-aa$requirementIdaccess requirement %s.\n", reqId))
     if (userId==principalId) {  }
          synRestDELETE(sprintfcat("/accessApproval/%s", aa$id)).")
     }
      cat(sprintf("\nRemoved access approval for access requirement %s.\n", reqId))"\n")
}

 

How to list the access requirements for a Team:

Use the following function, which you can cut/paste into your R session:

Code Block
listRequirementsForTeam<-function(teamId) {
    ars<-synRestGET(sprintf("/team/%s/accessRequirement", teamId))$results
    for (ar in ars) {
}        if cat(ar$concreteType=="org.sagebionetworks.repo.model.ACTAccessRequirement") {
    }        text<-ar$actContactInfo
  cat("\n") }

 

How to list the access requirements for a Team:

Use the following function, which you can cut/paste into your R session:

Code Block
listRequirementsForTeam<-function(teamId) {     } else {
            ars<-synRestGET(sprintf("/team/%s/accessRequirement", teamId))$resultstext<-ar$termsOfUse
       for (ar}
in ars) {      cat(sprintf("id=%s type=%s  if (ar$concreteType==text=%s...\n", ar$id, substring(text=ar$concreteType, first=1+nchar("org.sagebionetworks.repo.model.ACTAccessRequirement") {
   ), substr(text, 1, 50)))
    }
   text<-ar$actContactInfo
}

 

How to find out who was approved to join a Team:

Use the following function, which you can cut/paste into your R session:

Code Block
whoHasAccessToTeam<-function(teamId) {

    moreResults<-T
 } else { aas<-list()
    offset<-0
      text<pageSize<-ar$termsOfUse25
    while (moreResults) {
 }         catpage<-synRestGET(sprintf("id=%s type=%s text=%s...\n/team/%s/accessApproval?limit=%s&offset=%s", ar$idteamId, substring(text=ar$concreteType, first=1+nchar("org.sagebionetworks.repo.model.")), substr(text, 1, 50)))pageSize, offset))$results
        if (length(page)==0) moreResults<-F
     } }

 

How to find out who was approved to join a Team:

Use the following function, which you can cut/paste into your R session:

Code Block
whoHasAccessToTeam<-function(teamId) {  aas <- append(aas, page)
        aas<-synRestGET(sprintf("/team/%s/accessApproval?limit=999&offset=0", teamId))$resultsoffset<-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=",")))
        }
    }
}

...

Use the following function, which you can cut/paste into your R session:

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

    moreResults<-T
    aas<-list()
    offset<-0
    pageSize<-25
    while (moreResults) {
        aas<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))
        }
    }
}

...