Merge pull request #64 from abf/rosa-build:53-information-about-user-who-published-build-list

#53: Save and show information about user who published build list
This commit is contained in:
warpc 2013-04-02 18:29:34 +04:00
commit 0a2c88e071
13 changed files with 58 additions and 17 deletions

View File

@ -33,6 +33,8 @@ class Api::V1::BuildListsController < Api::V1::BaseController
end end
def publish def publish
@build_list.publisher = current_user
@build_list.save
render_json :publish render_json :publish
end end

View File

@ -30,9 +30,9 @@ class Platforms::MassBuildsController < Platforms::BaseController
def publish def publish
if params[:status] == 'test_failed' if params[:status] == 'test_failed'
@mass_build.publish_test_faild_builds @mass_build.publish_test_faild_builds current_user
else else
@mass_build.publish_success_builds @mass_build.publish_success_builds current_user
end end
redirect_to(platform_mass_builds_path(@mass_build.platform), :notice => t("flash.platform.publish_success")) redirect_to(platform_mass_builds_path(@mass_build.platform), :notice => t("flash.platform.publish_success"))
end end

View File

@ -173,6 +173,7 @@ class Projects::BuildListsController < Projects::BaseController
end end
@build_list.publisher = current_user
if @build_list.save && @build_list.can_publish? && @build_list.now_publish if @build_list.save && @build_list.can_publish? && @build_list.now_publish
redirect_to :back, :notice => t('layout.build_lists.publish_success') redirect_to :back, :notice => t('layout.build_lists.publish_success')
else else

View File

@ -62,7 +62,7 @@ class UserMailer < ActionMailer::Base
mail( mail(
:to => email_with_name(user, user.email), :to => email_with_name(user, user.email),
:subject => subject, :subject => subject,
:from => email_with_name(build_list.user) :from => email_with_name(build_list.publisher || build_list.user)
) do |format| ) do |format|
format.html format.html
end end

View File

@ -136,21 +136,32 @@ class ActivityFeedObserver < ActiveRecord::Observer
end end
when 'BuildList' when 'BuildList'
if [BuildList::BUILD_PUBLISHED, if ( record.status_changed? &&
[BuildList::BUILD_PUBLISHED,
BuildList::SUCCESS, BuildList::SUCCESS,
BuildList::BUILD_ERROR, BuildList::BUILD_ERROR,
BuildList::PROJECT_VERSION_NOT_FOUND, BuildList::PROJECT_VERSION_NOT_FOUND,
BuildList::FAILED_PUBLISH, BuildList::FAILED_PUBLISH,
BuildList::TESTS_FAILED BuildList::TESTS_FAILED
].include? record.status or ].include?(record.status)
(record.status == BuildList::BUILD_PENDING && record.bs_id_changed?) ) or (record.status == BuildList::BUILD_PENDING && record.bs_id_changed?)
record.project.admins.each do |recipient| record.project.admins.each do |recipient|
user = record.publisher || record.user
ActivityFeed.create( ActivityFeed.create(
:user => recipient, :user => recipient,
:kind => 'build_list_notification', :kind => 'build_list_notification',
:data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at, :data => {
:project_id => record.project_id, :project_name => record.project.name, :project_owner => record.project.owner.uname, :task_num => record.bs_id,
:user_name => record.user.name, :user_email => record.user.email, :user_id => record.user_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
end end

View File

@ -10,6 +10,7 @@ class BuildList < ActiveRecord::Base
belongs_to :save_to_repository, :class_name => 'Repository' belongs_to :save_to_repository, :class_name => 'Repository'
belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :build_for_platform, :class_name => 'Platform'
belongs_to :user belongs_to :user
belongs_to :publisher, :class_name => 'User'
belongs_to :advisory belongs_to :advisory
belongs_to :mass_build, :counter_cache => true belongs_to :mass_build, :counter_cache => true
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
@ -156,6 +157,7 @@ class BuildList < ActiveRecord::Base
after_transition :on => :published, after_transition :on => :published,
:do => [:set_version_and_tag, :actualize_packages] :do => [:set_version_and_tag, :actualize_packages]
after_transition :on => :publish, :do => :set_publisher
after_transition :on => :cancel, :do => :cancel_job after_transition :on => :cancel, :do => :cancel_job
after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users 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? self.use_save_to_repository = true if save_to_platform.main?
end end
def set_publisher
self.publisher ||= user
save
end
def current_ability def current_ability
@current_ability ||= Ability.new(user) @current_ability ||= Ability.new(user)
end end

View File

@ -77,20 +77,22 @@ class MassBuild < ActiveRecord::Base
end end
later :cancel_all, :queue => :clone_build later :cancel_all, :queue => :clone_build
def publish_success_builds def publish_success_builds(user)
publish BuildList::SUCCESS, BuildList::FAILED_PUBLISH publish user, BuildList::SUCCESS, BuildList::FAILED_PUBLISH
end end
later :publish_success_builds, :queue => :clone_build later :publish_success_builds, :queue => :clone_build
def publish_test_faild_builds def publish_test_faild_builds(user)
publish BuildList::TESTS_FAILED publish user, BuildList::TESTS_FAILED
end end
later :publish_test_faild_builds, :queue => :clone_build later :publish_test_faild_builds, :queue => :clone_build
private private
def publish(*statuses) def publish(user, *statuses)
build_lists.where(:status => statuses).order(:id).find_in_batches(:batch_size => 50) do |bls| 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 } bls.each{ |bl| bl.can_publish? && bl.now_publish }
end end
end end

View File

@ -40,7 +40,13 @@ json.build_list do |json|
:json => json_build_for_platform :json => json_build_for_platform
end 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) inc_repos = Repository.includes(:platform).where(:id => @build_list.include_repos)
json.include_repos inc_repos do |json_include_repos, repo| json.include_repos inc_repos do |json_include_repos, repo|

View File

@ -25,6 +25,10 @@
.rightlist .rightlist
= link_to @build_list.user.try(:fullname), @build_list.user = link_to @build_list.user.try(:fullname), @build_list.user
.both .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") .leftlist= t("activerecord.attributes.build_list.build_for_platform")
.rightlist .rightlist
- bfp = @build_list.build_for_platform - bfp = @build_list.build_for_platform

View File

@ -29,6 +29,7 @@ en:
auto_publish: Automated publising auto_publish: Automated publising
project_version: Version project_version: Version
user: User user: User
publisher: Publisher
preferences: Preferences preferences: Preferences
started_at: Build started at started_at: Build started at
duration: Build duration in seconds duration: Build duration in seconds

View File

@ -29,6 +29,7 @@ ru:
auto_publish: Автоматическая публикация auto_publish: Автоматическая публикация
project_version: Версия project_version: Версия
user: Пользователь user: Пользователь
publisher: Публикатор
preferences: Настройки preferences: Настройки
duration: Длительность билда в секундах duration: Длительность билда в секундах
mass_build_id: Массовая сборка mass_build_id: Массовая сборка

View File

@ -0,0 +1,5 @@
class AddPublishedUserToBuildList < ActiveRecord::Migration
def change
add_column :build_lists, :publisher_id, :integer
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -137,6 +137,7 @@ ActiveRecord::Schema.define(:version => 20130327120129) do
t.boolean "auto_create_container", :default => false t.boolean "auto_create_container", :default => false
t.text "extra_repositories" t.text "extra_repositories"
t.text "extra_build_lists" t.text "extra_build_lists"
t.integer "publisher_id"
end end
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id" add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"