diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 79d3c04b4..ee46406ce 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -33,6 +33,8 @@ class Api::V1::BuildListsController < Api::V1::BaseController end def publish + @build_list.publisher = current_user + @build_list.save render_json :publish end diff --git a/app/controllers/platforms/mass_builds_controller.rb b/app/controllers/platforms/mass_builds_controller.rb index 956862630..27c261e95 100644 --- a/app/controllers/platforms/mass_builds_controller.rb +++ b/app/controllers/platforms/mass_builds_controller.rb @@ -30,9 +30,9 @@ class Platforms::MassBuildsController < Platforms::BaseController def publish if params[:status] == 'test_failed' - @mass_build.publish_test_faild_builds + @mass_build.publish_test_faild_builds current_user else - @mass_build.publish_success_builds + @mass_build.publish_success_builds current_user end redirect_to(platform_mass_builds_path(@mass_build.platform), :notice => t("flash.platform.publish_success")) end diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 9df8fd43d..35199f2e0 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -173,6 +173,7 @@ class Projects::BuildListsController < Projects::BaseController end + @build_list.publisher = current_user if @build_list.save && @build_list.can_publish? && @build_list.now_publish redirect_to :back, :notice => t('layout.build_lists.publish_success') else diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 7c4c79f0a..b79be2446 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -62,7 +62,7 @@ class UserMailer < ActionMailer::Base mail( :to => email_with_name(user, user.email), :subject => subject, - :from => email_with_name(build_list.user) + :from => email_with_name(build_list.publisher || build_list.user) ) do |format| format.html end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 7fe598a20..00baeee09 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -136,21 +136,32 @@ class ActivityFeedObserver < ActiveRecord::Observer end when 'BuildList' - if [BuildList::BUILD_PUBLISHED, + if ( record.status_changed? && + [BuildList::BUILD_PUBLISHED, BuildList::SUCCESS, BuildList::BUILD_ERROR, BuildList::PROJECT_VERSION_NOT_FOUND, BuildList::FAILED_PUBLISH, BuildList::TESTS_FAILED - ].include? record.status or - (record.status == BuildList::BUILD_PENDING && record.bs_id_changed?) + ].include?(record.status) + ) or (record.status == BuildList::BUILD_PENDING && record.bs_id_changed?) record.project.admins.each do |recipient| + user = record.publisher || record.user ActivityFeed.create( :user => recipient, :kind => 'build_list_notification', - :data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at, - :project_id => record.project_id, :project_name => record.project.name, :project_owner => record.project.owner.uname, - :user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_id} + :data => { + :task_num => record.bs_id, + :build_list_id => record.id, + :status => record.status, + :updated_at => record.updated_at, + :project_id => record.project_id, + :project_name => record.project.name, + :project_owner => record.project.owner.uname, + :user_name => user.name, + :user_email => user.email, + :user_id => user.id + } ) end end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3dbbad32e..7af5e6045 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -10,6 +10,7 @@ class BuildList < ActiveRecord::Base belongs_to :save_to_repository, :class_name => 'Repository' belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :user + belongs_to :publisher, :class_name => 'User' belongs_to :advisory belongs_to :mass_build, :counter_cache => true has_many :items, :class_name => "BuildList::Item", :dependent => :destroy @@ -156,6 +157,7 @@ class BuildList < ActiveRecord::Base after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages] + after_transition :on => :publish, :do => :set_publisher after_transition :on => :cancel, :do => :cancel_job after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users @@ -476,6 +478,11 @@ class BuildList < ActiveRecord::Base self.use_save_to_repository = true if save_to_platform.main? end + def set_publisher + self.publisher ||= user + save + end + def current_ability @current_ability ||= Ability.new(user) end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 58ba4035d..01a7e0477 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -77,20 +77,22 @@ class MassBuild < ActiveRecord::Base end later :cancel_all, :queue => :clone_build - def publish_success_builds - publish BuildList::SUCCESS, BuildList::FAILED_PUBLISH + def publish_success_builds(user) + publish user, BuildList::SUCCESS, BuildList::FAILED_PUBLISH end later :publish_success_builds, :queue => :clone_build - def publish_test_faild_builds - publish BuildList::TESTS_FAILED + def publish_test_faild_builds(user) + publish user, BuildList::TESTS_FAILED end later :publish_test_faild_builds, :queue => :clone_build private - def publish(*statuses) - build_lists.where(:status => statuses).order(:id).find_in_batches(:batch_size => 50) do |bls| + def publish(user, *statuses) + builds = build_lists.where(:status => statuses) + builds.update_all(:publisher_id => user.id) + builds.order(:id).find_in_batches(:batch_size => 50) do |bls| bls.each{ |bl| bl.can_publish? && bl.now_publish } end end diff --git a/app/views/api/v1/build_lists/show.json.jbuilder b/app/views/api/v1/build_lists/show.json.jbuilder index da96b0acf..a108c7f76 100644 --- a/app/views/api/v1/build_lists/show.json.jbuilder +++ b/app/views/api/v1/build_lists/show.json.jbuilder @@ -40,7 +40,13 @@ json.build_list do |json| :json => json_build_for_platform end - json.partial! 'api/v1/shared/owner', :owner => @build_list.project.owner + json.user do |json_user| + json.partial! 'api/v1/shared/member', :member => @build_list.user, :tag => json_user + end + + json.publisher do |json_publisher| + json.partial! 'api/v1/shared/member', :member => @build_list.publisher, :tag => json_publisher + end if @build_list.publisher inc_repos = Repository.includes(:platform).where(:id => @build_list.include_repos) json.include_repos inc_repos do |json_include_repos, repo| diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index 56abee61c..94f8bcdcb 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -25,6 +25,10 @@ .rightlist = link_to @build_list.user.try(:fullname), @build_list.user .both + .leftlist= t("activerecord.attributes.build_list.publisher") + .rightlist + = link_to @build_list.publisher.try(:fullname), @build_list.publisher if @build_list.publisher + .both .leftlist= t("activerecord.attributes.build_list.build_for_platform") .rightlist - bfp = @build_list.build_for_platform diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 81147c210..02bed316b 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -29,6 +29,7 @@ en: auto_publish: Automated publising project_version: Version user: User + publisher: Publisher preferences: Preferences started_at: Build started at duration: Build duration in seconds diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 1407b8f70..c3c93fbed 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -29,6 +29,7 @@ ru: auto_publish: Автоматическая публикация project_version: Версия user: Пользователь + publisher: Публикатор preferences: Настройки duration: Длительность билда в секундах mass_build_id: Массовая сборка diff --git a/db/migrate/20130328112110_add_published_user_to_build_list.rb b/db/migrate/20130328112110_add_published_user_to_build_list.rb new file mode 100644 index 000000000..b7d31b4e5 --- /dev/null +++ b/db/migrate/20130328112110_add_published_user_to_build_list.rb @@ -0,0 +1,5 @@ +class AddPublishedUserToBuildList < ActiveRecord::Migration + def change + add_column :build_lists, :publisher_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 62a94da91..723c833d8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130327120129) do +ActiveRecord::Schema.define(:version => 20130328112110) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -137,6 +137,7 @@ ActiveRecord::Schema.define(:version => 20130327120129) do t.boolean "auto_create_container", :default => false t.text "extra_repositories" t.text "extra_build_lists" + t.integer "publisher_id" end add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"