lib/jamf/api/classic/api_objects/patch_title.rb in ruby-jss-2.0.0b3 vs lib/jamf/api/classic/api_objects/patch_title.rb in ruby-jss-2.0.0b5

- old
+ new

@@ -178,10 +178,11 @@ info[:id] = info[:id].to_i info[:source_name_id] = "#{info[:source_id]}-#{info[:name_id]}" info[:source_id] = info[:source_id].to_i end return data unless source_id + data.select { |p| p[:source_id] == source_id } end # The same as @see APIObject.all_names but also takes an optional # source_id: parameter, which limites the results to @@ -309,13 +310,15 @@ # 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 # - def self.fetch(identifier = nil, **params) - # default api - api = params[:api] ? params[:api] : Jamf.cnx + 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 @@ -347,12 +350,12 @@ # def self.valid_id(ident, refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api id = all_ids(refresh, cnx: cnx).include?(ident) ? ident : nil - id ||= map_all_ids_to(:source_name_id).invert[ident] - id ||= map_all_ids_to(:name).invert[ident] + id ||= map_all(:id, to: :source_name_id).invert[ident] + id ||= map_all(:id, to: :name).invert[ident] id end # Attributes ##################################### @@ -374,11 +377,10 @@ # @return [Boolean] Are new patches announced by email? attr_reader :email_notification alias email_notification? email_notification - # def initialize(**args) super if in_jss @name_id = @init_data[:name_id] @@ -419,15 +421,15 @@ # @return [Hash{String => Jamf::PatchTitle::Version}] The Jamf::PatchVersions fetched for # this title, keyed by version string def versions return @versions unless in_jss return @versions unless @versions.empty? + # if we are in jss, and versions is empty, re-fetch them @versions = self.class.fetch(id: id).versions end - # @return [Hash] Subset of @versions, containing those which have packages # assigned # def versions_with_packages versions.select { |_ver_string, vers| vers.package_assigned? } @@ -440,10 +442,11 @@ # @return [void] # def email_notification=(new_setting) return if email_notification == new_setting raise Jamf::InvalidDataError, 'New Setting must be boolean true or false' unless Jamf::TRUE_FALSE.include? @email_notification = new_setting + @need_to_update = true end # Set web notifications on or off # @@ -452,10 +455,11 @@ # @return [void] # def web_notification=(new_setting) return if web_notification == new_setting raise Jamf::InvalidDataError, 'New Setting must be boolean true or false' unless Jamf::TRUE_FALSE.include? @web_notification = new_setting + @need_to_update = true end # this is called by Jamf::PatchTitle::Version#package= to update @changed_pkgs which # is used by #rest_xml to change the package assigned to a patch version @@ -465,12 +469,12 @@ @need_to_update = true end # wrapper to fetch versions after creating def create - response = super - response + super + end # wrapper to clear @changed_pkgs after updating def update response = super @@ -533,9 +537,10 @@ velem = versions_elem.add_element 'version' velem.add_element('software_version').text = vers.to_s pkg = velem.add_element 'package' # leave am empty package element to remove the pkg assignement next if versions[vers].package_id == :none + pkg.add_element('id').text = versions[vers].package_id.to_s end # do vers end end # class Patch