lib/rally_user_helper.rb
# Check to see if User has _any_ permission within a specific project
Check to see if User has _any_ permission within a specific project
Check to see if User has _any_ permission within a specific project
def does_user_have_project_permission?(project, user)
      project_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 == "ProjectPermission" then
            if this_permission.Project.ObjectID.to_s == project["ObjectID"].to_s then
              project_permission_exists = true
              break
            end
          end
        end
      else 
        project_permission_query = RallyAPI::RallyQuery.new()
        project_permission_query.type = :projectpermission
        project_permission_query.fetch = "Project,Name,ObjectID,Role,User"
        project_permission_query.page_size = 200 
        project_permission_query.order = "Name Asc"
        project_permission_query.query_string = "(User.UserName = \"" + user.UserName + "\")"
        query_results = @rally.find(project_permission_query)
        project_permission_exists = false
        query_results.each { |pp|
          if ( pp.Project.ObjectID == project["ObjectID"])
            project_permission_exists = true
            break
          end
        }
      end
      return project_permission_exists
    end
def does_user_have_project_permission? ( project , user ) project_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 == "ProjectPermission" then if this_permission . Project . ObjectID . to_s == project [ "ObjectID" ] . to_s then project_permission_exists = true break end end end else project_permission_query = RallyAPI :: RallyQuery . new ( ) project_permission_query . type = :projectpermission project_permission_query . fetch = "Project,Name,ObjectID,Role,User" project_permission_query . page_size = 200 project_permission_query . order = "Name Asc" project_permission_query . query_string = "(User.UserName = \"" + user . UserName + "\")" query_results = @rally . find ( project_permission_query ) project_permission_exists = false query_results . each { | pp | if ( pp . Project . ObjectID == project [ "ObjectID" ] ) project_permission_exists = true break end } end return project_permission_exists end
Check to see if User has _any_ permission within a specific project
Check to see if User has _any_ permission within a specific project
# 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 # user has existing permissions in this project - let's compare new role against existing # Cache does not exist or user isn't in it - query info from Rally #optional - default is 200 # Look to see if any existing ProjectPermissions for this user match the one we're examining # If so, check to see if the project permissions are any different
project
user