lib/jamf/api/classic/api_objects/patch_title.rb in ruby-jss-4.1.0 vs lib/jamf/api/classic/api_objects/patch_title.rb in ruby-jss-4.1.1b1

- old
+ new

@@ -311,35 +311,49 @@ # Patch titles only have an id-based GET resource in the API. # so all other lookup values have to be converted to ID before # the call to super # + # NOTE: The only truely unique identifiers are id and source_name_id + # def self.fetch(identifier = nil, **params) # default connection if unspecified cnx = params.delete :cnx cnx ||= params.delete :api # backward compatibility, deprecated cnx ||= Jamf.cnx # source: and source_id: are considered the same, source_id: wins params[:source_id] ||= params[:source] - # if given a source name, this converts it to an id - params[:source_id] = Jamf::PatchInternalSource.valid_id params[:source_id] - params[:source_id] ||= Jamf::PatchExternalSource.valid_id params[:source_id] + # if given a source name in params[:source_id] this converts it to an id + if params[:source_id] + params[:source_id] = Jamf::PatchInternalSource.valid_id(params[:source_id], cnx: cnx) + params[:source_id] ||= Jamf::PatchExternalSource.valid_id(params[:source_id], cnx: cnx) + end - # build a possible source_name_id - params[:source_name_id] ||= "#{params[:source_id]}-#{params[:name_id]}" - id = if identifier - valid_id identifier + valid_id identifier, cnx: cnx + elsif params[:id] - all_ids.include?(params[:id]) ? params[:id] : nil + all_ids(cnx: cnx).include?(params[:id]) ? params[:id] : nil + elsif params[:source_name_id] - map_all_ids_to(:source_name_id).invert[params[:source_name_id]] + # TODO: make 'map_all' work with :source_name_id + # map_all(:source_name_id, to: :id, cnx: cnx)[params[:source_name_id]] + map_all(:id, to: :source_name_id, cnx: cnx).invert[params[:source_name_id]] + + # WARNING: name_id may not be unique + elsif params[:name_id] + # TODO: make 'map_all' work with :source_name_id + # map_all(:source_name_id, to: :id, cnx: cnx)[params[:source_name_id]] + map_all(:id, to: :name_id, cnx: cnx).invert[params[:name_id]] + + # WARNING: name_id may not be unique elsif params[:name] - map_all_ids_to(:name).invert[params[:name]] + # map_all_ids_to(:name, cnx: cnx).invert[params[:name]] + map_all(:name, to: :id, cnx: cnx)[params[:name]] end raise Jamf::NoSuchItemError, "No matching #{name} found" unless id super id: id, cnx: cnx @@ -390,17 +404,14 @@ # source: and source_id: are considered the same, source_id: wins @init_data[:source_id] ||= @init_data[:source] raise Jamf::MissingDataError, 'source: and name_id: must be provided' unless @init_data[:name_id] && @init_data[:source_id] - @source_id = Jamf::PatchSource.valid_id(@init_data[:source_id]) - + @source_id = Jamf::PatchSource.valid_id(@init_data[:source_id], cnx: @cnx) raise Jamf::NoSuchItemError, "No Patch Sources match '#{@init_data[:source]}'" unless source_id @name_id = @init_data[:name_id] - - valid_name_id = Jamf::PatchSource.available_name_ids(@source_id).include? @name_id - + valid_name_id = Jamf::PatchSource.available_name_ids(@source_id, cnx: @cnx).include? @name_id raise Jamf::NoSuchItemError, "source #{@init_data[:source]} doesn't offer name_id '#{@init_data[:name_id]}'" unless valid_name_id end @source_name_id = "#{@source_id}-#{@name_id}"