Merge pull request #350 from abf/rosa-build:349-automatic-metadata-regeneration

#349: automatic metadata regeneration
This commit is contained in:
avokhmin 2014-02-12 21:18:57 +04:00
commit c89265dfd3
17 changed files with 136 additions and 17 deletions

View File

@ -0,0 +1,17 @@
RosaABF.controller('AutomaticMetadataRegenerationController', ['$scope', '$http', function($scope, $http) {
// See: Platfrom::AUTOMATIC_METADATA_REGENERATIONS
$scope.items = {
'day': 'platform.automatic_metadata_regeneration.day',
'week': 'platform.automatic_metadata_regeneration.week'
};
$scope.platform_id = null;
$scope.update = function() {
$http.put(
Routes.platform_path($scope.platform_id),
{platform: {automatic_metadata_regeneration: $scope.amr}, format: 'json'}
);
}
}]);

View File

@ -11,6 +11,8 @@ var _locales = {
'Всего %1 тега',
'Всего %1 тегов'
],
'platform.automatic_metadata_regeneration.day': 'Раз в день',
'platform.automatic_metadata_regeneration.week': 'Раз в неделю',
<%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %>
},
<%I18n.locale = :en%>
@ -23,6 +25,8 @@ var _locales = {
'Total %1 tag',
'Total %1 tags'
],
'platform.automatic_metadata_regeneration.day': 'Once a day',
'platform.automatic_metadata_regeneration.week': 'Once a week',
<%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %>
}
};

View File

@ -43,16 +43,28 @@ class Platforms::PlatformsController < Platforms::BaseController
@admin_uname = params[:admin_uname]
platform_params = params[:platform] || {}
platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released)
platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released, :automatic_metadata_regeneration)
platform_params[:owner] = User.find(@admin_id) if @admin_id.present?
if @platform.update_attributes(platform_params)
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
render action: :edit
respond_to do |format|
format.html do
if @platform.update_attributes(platform_params)
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
render action: :edit
end
end
format.json do
if @platform.update_attributes(platform_params)
render json: { notice: I18n.t("flash.platform.saved") }.to_json
else
render json: { error: I18n.t("flash.platform.save_error") }.to_json, status: 422
end
end
end
end

View File

@ -69,6 +69,21 @@ class UserMailer < ActionMailer::Base
end
end
def metadata_regeneration_notification(platform, user)
set_locale user
@user, @platform = user, platform
subject = "[#{platform.name}] "
subject << I18n.t("notifications.subjects.metadata_regeneration", status: I18n.t("layout.regeneration_statuses.last_regenerated_statuses.#{platform.human_regeneration_status}"))
mail(
to: email_with_name(user, user.email),
subject: subject,
from: email_with_name(platform.owner)
) do |format|
format.html
end
end
def invite_approve_notification(register_request)
set_locale register_request
@register_request = register_request

View File

@ -23,7 +23,7 @@ class Group < Avatar
attr_accessible :uname, :description
attr_readonly :uname
delegate :email, to: :owner
delegate :email, :user_appeal, to: :owner
after_create :add_owner_to_members

View File

@ -5,6 +5,7 @@ class Platform < ActiveRecord::Base
include Modules::Models::FileStoreClean
include Modules::Models::RegenerationStatus
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
VISIBILITIES = %w(open hidden)
NAME_PATTERN = /[\w\-\.]+/
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
@ -30,6 +31,7 @@ class Platform < ActiveRecord::Base
validates :description, presence: true
validates :visibility, presence: true, inclusion: {in: VISIBILITIES}
validates :automatic_metadata_regeneration, inclusion: {in: AUTOMATIC_METADATA_REGENERATIONS}, allow_blank: true
validates :name, uniqueness: {case_sensitive: false}, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ }
validates :distrib_type, presence: true, inclusion: {in: APP_CONFIG['distr_types']}
validate lambda {
@ -63,12 +65,15 @@ class Platform < ActiveRecord::Base
scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION)
accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes, :automatic_metadata_regeneration
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner
state_machine :status, initial: :ready do
after_transition on: :ready, do: :notify_users
event :ready do
transition regenerating: :ready
end
@ -234,6 +239,10 @@ class Platform < ActiveRecord::Base
end
end
def self.autostart_metadata_regeneration(value)
Platform.main.where(automatic_metadata_regeneration: value).each(&:regenerate)
end
protected
def create_directory
@ -259,4 +268,10 @@ class Platform < ActiveRecord::Base
repositories.update_all(publish_without_qa: false)
end
end
def notify_users
users = members.includes(:notifier).select{ |u| u.notifier.can_notify? }
users.each{ |u| UserMailer.metadata_regeneration_notification(self, u).deliver }
end
end

View File

@ -21,15 +21,25 @@
.leftlist= t('activerecord.attributes.regeneration_status.status')
.rightlist= t("layout.regeneration_statuses.statuses.#{@platform.human_status}")
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_at')
.rightlist= @platform.last_regenerated_at
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_status')
.rightlist= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}")
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_log_sha1')
.rightlist= link_to_file_store('regeneration.log', @platform.last_regenerated_log_sha1)
.both
.leftlist= t('activerecord.attributes.platform.automatic_metadata_regeneration')
.rightlist{ 'ng-controller' => 'AutomaticMetadataRegenerationController', 'ng-init' => "platform_id = #{@platform.id}" }
%select{ 'ng-options' => 'k as (v | i18n) for (k, v) in items', 'ng-model' => 'amr', 'ng-change' => 'update()', 'ng-init' => "amr = '#{@platform.automatic_metadata_regeneration.to_s}'" }
%option{ value: '' }
.both
.leftside
.rightside= link_to t('layout.regeneration_statuses.regenerate_metadata'), regenerate_metadata_platform_path(@platform), method: :put, confirm: t('layout.confirm'), class: 'button'
.both

View File

@ -0,0 +1,11 @@
%p
Metadata regeneration for platform
= link_to @platform.name, platform_url(@platform)
completed with status
%b
= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}")
%p
More detailed information you can get by link:
= link_to t('layout.platforms.metadata'), edit_platform_url(@platform)
= render 'footer'

View File

@ -0,0 +1,11 @@
%p
Регенерация метаданных для платформы
= link_to @platform.name, platform_url(@platform)
завершена со статусом
%b
= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}")
%p
Более подробную информацию можно получить по ссылке:
= link_to t('layout.platforms.metadata'), edit_platform_url(@platform)
= render 'footer'

View File

@ -20,6 +20,7 @@ en:
issue_assign_notification: New task assigned
invite_approve_notification: Invitation to ABF
for_arch: for arch %{arch}.
metadata_regeneration: Metadata regeneration «%{status}»
bodies:
view_it_on: View it on

View File

@ -20,6 +20,7 @@ ru:
issue_assign_notification: Вам назначили задачу
invite_approve_notification: Приглашение в ABF
for_arch: для архитектуры %{arch}.
metadata_regeneration: Регенерация метаданных «%{status}»
bodies:
view_it_on: Смотрите это на

View File

@ -92,6 +92,7 @@ en:
updated_at: Updated
distrib_type: Source type
visibility: Status
automatic_metadata_regeneration: Automatic metadata regeneration
visibility_types:
open: Public
hidden: Private

View File

@ -92,6 +92,7 @@ ru:
updated_at: Обновлена
distrib_type: Тип дистрибутива
visibility: Статус
automatic_metadata_regeneration: Автоматическая регенерация метаданных
visibility_types:
open: Публичный
hidden: Приватный

View File

@ -50,3 +50,11 @@ end
every :sunday, at: '4am' do
runner 'Product.autostart_iso_builds_once_a_week', output: 'log/autostart_iso_builds.log'
end
every :day, at: '1am' do
runner 'Platfrom.autostart_metadata_regeneration("day")', output: 'log/autostart_platform_metadata_regeneration.log'
end
every :saturday, at: '2am' do
runner 'Platfrom.autostart_metadata_regeneration("week")', output: 'log/autostart_platform_metadata_regeneration.log'
end

View File

@ -0,0 +1,5 @@
class AddAutomaticMetadataRegenerationToPlatform < ActiveRecord::Migration
def change
add_column :platforms, :automatic_metadata_regeneration, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140113215223) do
ActiveRecord::Schema.define(:version => 20140211175858) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -316,20 +316,21 @@ ActiveRecord::Schema.define(:version => 20140113215223) do
create_table "platforms", :force => true do |t|
t.string "description"
t.string "name", :null => false
t.string "name", :null => false
t.integer "parent_platform_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "released", :default => false, :null => false
t.boolean "released", :default => false, :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false
t.integer "status"
t.datetime "last_regenerated_at"
t.integer "last_regenerated_status"
t.string "last_regenerated_log_sha1"
t.string "automatic_metadata_regeneration"
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false

View File

@ -27,6 +27,12 @@ describe Platform do
end
it {should_not allow_value('custom_status').for(:visibility)}
['', nil] + Platform::AUTOMATIC_METADATA_REGENERATIONS.each do |value|
it {should allow_value(value).for(:automatic_metadata_regeneration)}
end
it {should_not allow_value('custom_status').for(:visibility)}
it { should have_readonly_attribute(:name) }
it { should have_readonly_attribute(:distrib_type) }
it { should have_readonly_attribute(:parent_platform_id) }