diff --git a/src/api/app/helpers/flag_helper.rb b/src/api/app/helpers/flag_helper.rb index 0dc6d04eddf..b8da57c8ea8 100644 --- a/src/api/app/helpers/flag_helper.rb +++ b/src/api/app/helpers/flag_helper.rb @@ -125,32 +125,20 @@ def set_repository_by_product(flag, status, product_name, patchlevel = nil) end def enabled_for?(flag_type, repo, arch) - state = find_flag_state(flag_type, repo, arch) + state = find_flag_status(flag_type, repo, arch) logger.debug "enabled_for #{flag_type} repo:#{repo} arch:#{arch} state:#{state}" state.to_sym == :enable end def disabled_for?(flag_type, repo, arch) - state = find_flag_state(flag_type, repo, arch) + state = find_flag_status(flag_type, repo, arch) logger.debug "disabled_for #{flag_type} repo:#{repo} arch:#{arch} state:#{state}" state.to_sym == :disable end - def find_flag_state(flag_type, repo, arch) - flag = flags.of_type(flag_type).select { |f| f.is_relevant_for?(repo, arch) }.max_by(&:specifics) - - state = flag.try(:status) || :default - - if state == :default - if respond_to?('project') - logger.debug 'flagcheck: package has default state, checking project' - state = project.find_flag_state(flag_type, repo, arch) - else - state = FlagHelper.default_for(flag_type) - end - end - - state + def find_flag_status(flag_type, repo, arch) + flags = Flag::SpecifiedFlags.new(self, flag_type) + flags.effective_flag(repo, arch).status end def self.xml_disabled_for?(xmlhash, flagtype) diff --git a/src/api/app/models/flag.rb b/src/api/app/models/flag.rb index f6db1b5b82c..5c0391ff2a6 100644 --- a/src/api/app/models/flag.rb +++ b/src/api/app/models/flag.rb @@ -114,26 +114,6 @@ def to_xml(builder) builder.send(status.to_s, options) end - # returns true when flag is relevant for the given repo/arch combination - def is_relevant_for?(in_repo, in_arch) - arch = architecture ? architecture.name : nil - - return true if arch.nil? && repo.nil? - return true if arch.nil? && !repo.nil? && in_repo == repo - return true if arch && repo.nil? && in_arch == arch - return true if in_arch == arch && in_repo == repo - - false - end - - def specifics - count = 0 - count += 1 if status == 'disable' - count += 2 if architecture - count += 4 if repo - count - end - # TODO: used by bento. Remove when dropping old UI. def fullname ret = flag