Skip to content

Commit

Permalink
Use Flag::SpecifiedFlags to replace 2 more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 16, 2018
1 parent be95e08 commit 2a27c17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
22 changes: 5 additions & 17 deletions src/api/app/helpers/flag_helper.rb
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions src/api/app/models/flag.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2a27c17

Please sign in to comment.