#757: add validation for new fields

This commit is contained in:
Vokhmin Alexey V 2013-02-19 12:31:01 +04:00
parent 38498a6e66
commit 61e9d24bb5
6 changed files with 21 additions and 9 deletions

View File

@ -115,21 +115,21 @@ class Projects::BuildListsController < Projects::BaseController
def autocomplete_to_extra
platforms = Platform.includes(:repositories).search(params[:term]).search_order.limit(5)
results = []
platforms.each{ |p| p.repositories.each{ |r| results << {id: r.id, label: "#{p.name}/#{r.name}", value: "#{p.name}/#{r.name}"} } }
platforms.each{ |p| p.repositories.each{ |r| results << {:id => r.id, :label => "#{p.name}/#{r.name}", :value => "#{p.name}/#{r.name}"} } }
bl = BuildList.where(id: params[:term], container_status: BuildList::BUILD_PUBLISHED).first
results << {id: "#{bl.id}-build-list", value: bl.id, label: "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl
bl = BuildList.where(:id => params[:term], :container_status => BuildList::BUILD_PUBLISHED).first
results << {:id => "#{bl.id}-build-list", :value => bl.id, :label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})"} if bl
render json: results.to_json
end
def add_extra
if params[:extra_id] =~ /-build-list$/
id = params[:extra_id].gsub(/-build-list$/, '')
subject = BuildList.where(id: id, container_status: BuildList::BUILD_PUBLISHED).first
subject = BuildList.where(:id => id, :container_status => BuildList::BUILD_PUBLISHED).first
else
subject = Repository.find params[:extra_id]
end
render partial: 'extra', locals: {subject: subject}
render :partial => 'extra', :locals => {:subject => subject}
end
protected

View File

@ -42,11 +42,19 @@ class BuildList < ActiveRecord::Base
validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id)
}
validate lambda {
errors.add(:extra_repositories, I18n.t('flash.build_list.wrong_extra_repositories')) if extra_repositories.present? && Repository.where(:id => extra_repositories).count != extra_repositories.count
}, :on => :create
validate lambda {
errors.add(:extra_containers, I18n.t('flash.build_list.wrong_extra_containers')) if extra_containers.present? && BuildList.where(:id => extra_containers, :container_status => BUILD_PUBLISHED).count != extra_containers.count
}, :on => :create
before_validation(:on => :create) do
if save_to_repository && save_to_repository.platform.main?
self.extra_repositories = nil
self.extra_containers = nil
end
self.extra_repositories = extra_repositories.uniq if extra_repositories.present?
self.extra_containers = extra_containers.uniq if extra_containers.present?
end
before_create :use_save_to_repository_for_main_platforms

View File

@ -33,10 +33,10 @@
%table.tablesorter{:cellpadding => "0", :cellspacing => "0"}
%tbody
- Repository.where(id: @build_list.extra_repositories).each do |repo|
= render 'extra', subject: repo
= render 'extra', :subject => repo
- BuildList.where(id: @build_list.extra_containers).each do |bl|
= render 'extra', subject: bl
= render 'extra', :subject => bl
%h3= t("activerecord.attributes.build_list.preferences")
- [:auto_publish, :auto_create_container, :use_save_to_repository].each do |kind|

View File

@ -75,9 +75,9 @@
- if @build_list.extra_containers.present? || @build_list.extra_repositories.present?
.leftlist= t("activerecord.attributes.build_list.extra_repos")
.rightlist
- Repository.where(id: @build_list.extra_repositories).each do |repo|
- Repository.where(:id => @build_list.extra_repositories).each do |repo|
%p= link_to "#{repo.platform.name}/#{repo.name}", [repo.platform, repo]
- BuildList.where(id: @build_list.extra_containers).each do |bl|
- BuildList.where(:id => @build_list.extra_containers).each do |bl|
%p= link_to "#{bl.id} (#{bl.project.name} - #{bl.arch.name})", bl
.both

View File

@ -163,3 +163,5 @@ en:
frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates
wrong_include_repos: Include repos have to belongs to build for platform
wrong_commit_hash: Unable find commit '%{commit_hash}' in project
wrong_extra_repositories: Some repositories does not exist
wrong_extra_containers: Some containers does not exist

View File

@ -162,3 +162,5 @@ ru:
frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления
wrong_include_repos: Включаемые репозитории должны принадлежать платформе для сборки
wrong_commit_hash: Невозможно найти коммит '%{commit_hash}' в проекте
wrong_extra_repositories: Некоторые репозитории не существуют
wrong_extra_containers: Некоторые контейнеры не существуют