lib/rally_user_helper.rb
# Check to see if User has _any_ permission within a specific workspace
Check to see if User has _any_ permission within a specific workspace
Check to see if User has _any_ permission within a specific workspace
def does_user_have_workspace_permission?(workspace, user)
      workspace_permission_exists = false
      use_cache = false
      if @cached_users != nil then
        if @cached_users.has_key?(user.UserName) then use_cache = true end
      end
      if use_cache then
        this_user = @cached_users[user.UserName]
        user_permissions = this_user.UserPermissions
        user_permissions.each do | this_permission |
          if this_permission._type == "WorkspacePermission" then
            if this_permission.Workspace.ObjectID.to_s == workspace["ObjectID"].to_s then
              workspace_permission_exists = true
              break
            end
          end
        end
      else 
        workspace_permission_query = RallyAPI::RallyQuery.new()
        workspace_permission_query.type = :workspacepermission
        workspace_permission_query.fetch = "Workspace,Name,ObjectID,Role,User"
        workspace_permission_query.page_size = 200 
        workspace_permission_query.order = "Name Asc"
        workspace_permission_query.query_string = "(User.UserName = \"" + user.UserName + "\")"
        query_results = @rally.find(workspace_permission_query)
        workspace_permission_exists = false
        query_results.each { |wp|
          if ( wp.Workspace.ObjectID == workspace["ObjectID"])
            workspace_permission_exists = true
            break
          end
        }
      end
      return workspace_permission_exists
    end
def does_user_have_workspace_permission? ( workspace , user ) workspace_permission_exists = false use_cache = false if @cached_users != nil then if @cached_users . has_key? ( user . UserName ) then use_cache = true end end if use_cache then this_user = @cached_users [ user . UserName ] user_permissions = this_user . UserPermissions user_permissions . each do | this_permission | if this_permission . _type == "WorkspacePermission" then if this_permission . Workspace . ObjectID . to_s == workspace [ "ObjectID" ] . to_s then workspace_permission_exists = true break end end end else workspace_permission_query = RallyAPI :: RallyQuery . new ( ) workspace_permission_query . type = :workspacepermission workspace_permission_query . fetch = "Workspace,Name,ObjectID,Role,User" workspace_permission_query . page_size = 200 workspace_permission_query . order = "Name Asc" workspace_permission_query . query_string = "(User.UserName = \"" + user . UserName + "\")" query_results = @rally . find ( workspace_permission_query ) workspace_permission_exists = false query_results . each { | wp | if ( wp . Workspace . ObjectID == workspace [ "ObjectID" ] ) workspace_permission_exists = true break end } end return workspace_permission_exists end
Check to see if User has _any_ permission within a specific workspace
Check to see if User has _any_ permission within a specific workspace
# set default return value # first try to lookup against cached user list -- much faster than re-querying Rally # first try to lookup against cached user list -- much faster than re-querying Rally # loop through permissions and look to see if there's an existing permission for this # workspace, and if so, has it changed # Cache does not exist or user isn't in it - query info from Rally #optional - default is 200 # Look to see if any existing WorkspacePermissions for this user match the one we're examining # If so, check to see if the workspace permissions are any different
workspace
user