Sha256: 3c63b4e3d61920d7256b4ba03206afdf5128d406e7d32e26f4853cd1f2aa5579

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Katello
  module Validators
    class PriorValidator < ActiveModel::Validator
      def validate(record)
        #need to ensure that prior
        #environment already does not have a successor
        #this is because in v1.0 we want
        # prior to have only one child (unless its the Library)
        has_no_prior = true
        if record.organization
          has_no_prior = record.organization.kt_environments.reject { |env| env == record || env.prior != record.prior || env.prior == env.organization.library }.empty?
        end
        record.errors[:prior] << _("environment can only have one child") unless has_no_prior

        # only Library can have prior=nil
        record.errors[:prior] << _("environment required") unless !record.prior.nil? || record.library?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
katello-2.2.2 app/lib/katello/validators/prior_validator.rb