lib/rally_user_helper.rb
def project_permissions_different?(project, user, new_permission)

      # set default return value
      project_permission_changed = false
      use_cache = false

      # first try to lookup against cached user list -- much faster than re-querying Rally
      if @cached_users != nil then
        if @cached_users.has_key?(user.UserName) then use_cache = true end
      end

      if use_cache then
        number_matching_projects = 0
        this_user = @cached_users[user.UserName]

        # loop through permissions and look to see if there's an existing permission for this
        # workspace, and if so, has it changed
        user_permissions = this_user.UserPermissions
        user_permissions.each do | this_permission |

          if this_permission._type == "ProjectPermission" then
            # user has existing permissions in this project - let's compare new role against existing
            if this_permission.Project.ObjectID.to_s == project["ObjectID"].to_s then
              number_matching_projects += 1
              if this_permission.Role != new_permission then
                project_permission_changed = true
              end
            end
          end
        end

        # This is a new project permission - set the changed bit to true
        if number_matching_projects == 0 then
            project_permission_changed = true
        end

      else # Cache does not exist or user isn't in it - query info from Rally

        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 #optional - default is 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_changed = false
        number_matching_projects = 0

        # 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
        query_results.each { |pp|

          if ( pp.Project.ObjectID == project["ObjectID"])
            number_matching_projects+=1
            if pp.Role != new_permission then project_permission_changed = true end
          end
        }
        # This is a new project permission - set the changed bit to true
        if number_matching_projects == 0 then project_permission_changed = true end
      end
      return project_permission_changed
    end
# check if the new permissions are different than what the user currently has
# if we don't do this, we will delete and recreate permissions each time and that
# will make the revision history on user really, really, really, really ugly
check if the new permissions are different than what the user currently has
if we don't do this, we will delete and recreate permissions each time and that
will make the revision history on user really, really, really, really ugly
check if the new permissions are different than what the user currently has if we don ' t do this we will delete and recreate permissions each time and that will make the revision history on user really really really really ugly
def project_permissions_different?(project, user, new_permission)
      project_permission_changed = 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
        number_matching_projects = 0
        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
              number_matching_projects += 1
              if this_permission.Role != new_permission then
                project_permission_changed = true
              end
            end
          end
        end
        if number_matching_projects == 0 then
            project_permission_changed = true
        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_changed = false
        number_matching_projects = 0
        query_results.each { |pp|
          if ( pp.Project.ObjectID == project["ObjectID"])
            number_matching_projects+=1
            if pp.Role != new_permission then project_permission_changed = true end
          end
        }
        if number_matching_projects == 0 then project_permission_changed = true end
      end
      return project_permission_changed
    end
def project_permissions_different? ( project , user , new_permission ) project_permission_changed = 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 number_matching_projects = 0 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 number_matching_projects += 1 if this_permission . Role != new_permission then project_permission_changed = true end end end end if number_matching_projects == 0 then project_permission_changed = true 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_changed = false number_matching_projects = 0 query_results . each { | pp | if ( pp . Project . ObjectID == project [ "ObjectID" ] ) number_matching_projects += 1 if pp . Role != new_permission then project_permission_changed = true end end } if number_matching_projects == 0 then project_permission_changed = true end end return project_permission_changed end
check if the new permissions are different than what the user currently has
if we don't do this, we will delete and recreate permissions each time and that
will make the revision history on user really, really, really, really ugly
check if the new permissions are different than what the user currently has if we don ' t do this we will delete and recreate permissions each time and that will make the revision history on user really really really really ugly
# set default return value # 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 # This is a new project permission - set the changed bit to true # 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 # This is a new project permission - set the changed bit to true
project
user
new_permission