Skip to content

Commit

Permalink
[api] avoid conflicting flags in projects
Browse files Browse the repository at this point in the history
Do not copy a flag if it has been set with same specification level.
No matter if it is an enable or disable one.
  • Loading branch information
adrianschroeter committed Dec 12, 2014
1 parent e12f202 commit 665e4f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/api/app/models/flag.rb
Expand Up @@ -4,6 +4,13 @@ class Flag < ActiveRecord::Base

belongs_to :architecture

validate :validate_duplicates, :on => :create
def validate_duplicates
if Flag.where("status = ? AND repo = ? AND project_id = ? AND package_id = ? AND architecture_id = ? AND flag = ?", self.status, self.repo, self.project_id, self.package_id, self.architecture_id, self.flag).exists?
errors.add(:flag, "Flag already exists")
end
end

def to_xml(builder)
raise RuntimeError.new( "FlagError: No flag-status set. \n #{self.inspect}" ) if self.status.nil?
options = Hash.new
Expand Down
4 changes: 3 additions & 1 deletion src/api/app/models/project.rb
Expand Up @@ -1136,7 +1136,9 @@ def branch_copy_flags(project)
project.flags.each do |f|
next if %w(build lock).include?(f.flag)
next if f.flag == 'publish' and disable_publish_for_branches
next if self.flags.where(status: f.status, flag: f.flag, architecture: f.architecture, repo: f.repo).exists?
# NOTE: it does not matter if that flag is set to enable or disable, so we do not check fro
# for same flag status here explizit
next if self.flags.where(flag: f.flag, architecture: f.architecture, repo: f.repo).exists?

self.flags.create(status: f.status, flag: f.flag, architecture: f.architecture, repo: f.repo)
end
Expand Down

0 comments on commit 665e4f0

Please sign in to comment.