From 2a01474d0376b4a73b7809b85f7e939e3e2ac97c Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 11 Feb 2015 01:08:39 +0300 Subject: [PATCH] #452: added "Builds settings" for user --- app/controllers/users/settings_controller.rb | 31 ++++++++++------ app/models/build_list.rb | 5 +-- app/models/concerns/external_nodable.rb | 15 ++++++++ app/models/mass_build.rb | 9 +---- app/models/user.rb | 3 +- app/models/user_builds_setting.rb | 11 ++++++ app/views/users/base/_submenu.html.slim | 4 ++ .../users/settings/builds_settings.html.slim | 37 +++++++++++++++++++ .../locales/models/user_builds_setting.en.yml | 20 ++++++++++ .../locales/models/user_builds_setting.ru.yml | 20 ++++++++++ config/locales/users.en.yml | 1 + config/routes.rb | 2 + ...50210192749_create_user_builds_settings.rb | 12 ++++++ db/schema.rb | 10 ++++- 14 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 app/models/concerns/external_nodable.rb create mode 100644 app/models/user_builds_setting.rb create mode 100644 app/views/users/settings/builds_settings.html.slim create mode 100644 config/locales/models/user_builds_setting.en.yml create mode 100644 config/locales/models/user_builds_setting.ru.yml create mode 100644 db/migrate/20150210192749_create_user_builds_settings.rb diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 5f196bccf..7a2724dfb 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -13,11 +13,10 @@ class Users::SettingsController < Users::BaseController @user.send_confirmation_instructions end flash[:notice] = t('flash.user.saved') - redirect_to profile_settings_path - else - flash[:error] = t('flash.user.save_error') - flash[:warning] = @user.errors.full_messages.join('. ') + redirect_to profile_settings_path and return end + flash[:error] = t('flash.user.save_error') + flash[:warning] = @user.errors.full_messages.join('. ') end end @@ -31,12 +30,10 @@ class Users::SettingsController < Users::BaseController if request.patch? if @user.update_with_password(params[:user]) flash[:notice] = t('flash.user.saved') - redirect_to private_settings_path - else - flash[:error] = t('flash.user.save_error') - flash[:warning] = @user.errors.full_messages.join('. ') - render(action: :private) + redirect_to private_settings_path and return end + flash[:error] = t('flash.user.save_error') + flash[:warning] = @user.errors.full_messages.join('. ') end end @@ -44,10 +41,20 @@ class Users::SettingsController < Users::BaseController if request.patch? if @user.notifier.update_attributes(params[:settings_notifier]) flash[:notice] = I18n.t("flash.settings.saved") - redirect_to notifiers_settings_path - else - flash[:error] = I18n.t("flash.settings.save_error") + redirect_to notifiers_settings_path and return end + flash[:error] = I18n.t("flash.settings.save_error") + end + end + + def builds_settings + @user.builds_setting ||= @user.build_builds_setting + if request.patch? + if @user.builds_setting.update_attributes(params[:user_builds_setting]) + flash[:notice] = I18n.t("flash.settings.saved") + redirect_to builds_settings_settings_path and return + end + flash[:error] = I18n.t("flash.settings.save_error") end end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 90463a9be..025081307 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -5,6 +5,7 @@ class BuildList < ActiveRecord::Base include Feed::BuildList include BuildListObserver include EventLoggable + include ExternalNodable self.per_page = 25 @@ -32,7 +33,6 @@ class BuildList < ActiveRecord::Base RELEASE_UPDATE_TYPES = [UPDATE_TYPE_BUGFIX, UPDATE_TYPE_SECURITY] EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm] - EXTERNAL_NODES = %w[owned everything] AUTO_PUBLISH_STATUSES = [ AUTO_PUBLISH_STATUS_NONE = 'none', @@ -50,7 +50,6 @@ class BuildList < ActiveRecord::Base presence: true validates_numericality_of :priority, greater_than_or_equal_to: 0 - validates :external_nodes, inclusion: { in: EXTERNAL_NODES }, allow_blank: true validates :auto_publish_status, inclusion: { in: AUTO_PUBLISH_STATUSES } validates :update_type, inclusion: UPDATE_TYPES, unless: Proc.new { |b| b.advisory.present? } @@ -80,7 +79,7 @@ class BuildList < ActiveRecord::Base attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash, :arch_id, :project_id, :save_to_repository_id, :update_type, :save_to_platform_id, :project_version, :auto_create_container, - :extra_repositories, :extra_build_lists, :extra_params, :external_nodes, + :extra_repositories, :extra_build_lists, :extra_params, :include_testing_subrepository, :auto_publish_status, :use_cached_chroot, :use_extra_tests, :save_buildroot diff --git a/app/models/concerns/external_nodable.rb b/app/models/concerns/external_nodable.rb new file mode 100644 index 000000000..12d2801b9 --- /dev/null +++ b/app/models/concerns/external_nodable.rb @@ -0,0 +1,15 @@ +module ExternalNodable + extend ActiveSupport::Concern + + EXTERNAL_NODES = %w(owned everything) + + included do + validates :external_nodes, + inclusion: { in: EXTERNAL_NODES }, + allow_blank: true + + + attr_accessible :external_nodes + end + +end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 270154dc5..322522d79 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -1,7 +1,7 @@ class MassBuild < ActiveRecord::Base + include ExternalNodable AUTO_PUBLISH_STATUSES = %w(none default testing) - EXTERNAL_NODES = %w(owned everything) STATUSES, HUMAN_STATUSES = [], {} [ @@ -48,8 +48,7 @@ class MassBuild < ActiveRecord::Base attr_accessible :arches, :auto_publish_status, :projects_list, :build_for_platform_id, :extra_repositories, :extra_build_lists, :increase_release_tag, :use_cached_chroot, :use_extra_tests, :description, :extra_mass_builds, - :include_testing_subrepository, :auto_create_container, :external_nodes, - :repositories + :include_testing_subrepository, :auto_create_container, :repositories validates :save_to_platform_id, :build_for_platform_id, @@ -58,10 +57,6 @@ class MassBuild < ActiveRecord::Base :user_id, presence: true - validates :external_nodes, - inclusion: { in: EXTERNAL_NODES }, - allow_blank: true - validates :projects_list, presence: true, length: { maximum: 500_000 } diff --git a/app/models/user.rb b/app/models/user.rb index c33ab12b2..a7d89fe1a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,8 @@ class User < Avatar :recoverable, :rememberable, :validatable, :lockable, :confirmable devise :omniauthable, omniauth_providers: [:facebook, :google_oauth2, :github] - has_one :notifier, class_name: 'SettingsNotifier', dependent: :destroy #:notifier + has_one :notifier, class_name: 'SettingsNotifier', dependent: :destroy #:notifier + has_one :builds_setting, class_name: 'UserBuildsSetting', dependent: :destroy has_many :activity_feeds, dependent: :destroy diff --git a/app/models/user_builds_setting.rb b/app/models/user_builds_setting.rb new file mode 100644 index 000000000..85264ad40 --- /dev/null +++ b/app/models/user_builds_setting.rb @@ -0,0 +1,11 @@ +class UserBuildsSetting < ActiveRecord::Base + include ExternalNodable + + belongs_to :user + + validates :user, presence: true + + attr_accessible :platforms, + :use_extra_tests + +end diff --git a/app/views/users/base/_submenu.html.slim b/app/views/users/base/_submenu.html.slim index 878898505..d69c473f8 100644 --- a/app/views/users/base/_submenu.html.slim +++ b/app/views/users/base/_submenu.html.slim @@ -25,6 +25,10 @@ a href=private_settings_path i.fa.fa-cog> = t('layout.users.user_private_settings') + li class=('active' if act == :builds_settings) + a href=builds_settings_settings_path + i.fa.fa-cogs> + = t('layout.users.builds_settings') li class=('active' if act == :notifiers) a href=notifiers_settings_path i.fa.fa-inbox> diff --git a/app/views/users/settings/builds_settings.html.slim b/app/views/users/settings/builds_settings.html.slim new file mode 100644 index 000000000..d5b52dbe7 --- /dev/null +++ b/app/views/users/settings/builds_settings.html.slim @@ -0,0 +1,37 @@ +- set_meta_tags title: t('.title') += render 'users/base/submenu' + + +.container.col-md-offset-2.col-md-8 + .row + = simple_form_for @user.builds_setting, + url: builds_settings_settings_path, + wrapper: :horizontal_form, + wrapper_mappings: { boolean: :horizontal_boolean } do |f| + + fieldset + legend + = t('.heading') + + .row + .col-sm-4 + = f.label :platforms + = f.hint :platforms + = f.collection_check_boxes :platforms, availables_main_platforms, :id, :name, + checked: @user.builds_setting.platforms, + collection_wrapper_tag: :div, + collection_wrapper_class: 'form-group', + item_wrapper_tag: :div, + item_wrapper_class: 'col-sm-9' do |b| + .checkbox + = b.label { b.check_box + b.text } + + + .col-sm-8 + = f.input :external_nodes, collection: external_nodes, include_blank: true + = f.input :use_extra_tests, as: :boolean + + .clearfix + hr + = submit_button_tag + diff --git a/config/locales/models/user_builds_setting.en.yml b/config/locales/models/user_builds_setting.en.yml new file mode 100644 index 000000000..e637ff187 --- /dev/null +++ b/config/locales/models/user_builds_setting.en.yml @@ -0,0 +1,20 @@ +en: + + users: + settings: + builds_settings: + title: "Builds settings" + heading: "Builds settings" + + simple_form: + labels: + user_builds_setting: + platforms: "Platforms" + external_nodes: "External nodes" + use_extra_tests: "Use extra tests" + # placeholders: + hints: + user_builds_setting: + platforms: "Select a platforms that you'd like to use." + external_nodes: "Select the type of nodes that you'd like to use." + use_extra_tests: "Uncheck this to disable extra tests." diff --git a/config/locales/models/user_builds_setting.ru.yml b/config/locales/models/user_builds_setting.ru.yml new file mode 100644 index 000000000..de05e0b57 --- /dev/null +++ b/config/locales/models/user_builds_setting.ru.yml @@ -0,0 +1,20 @@ +ru: + + users: + settings: + builds_settings: + title: "Настройки сборок" + heading: "Настройки сборок" + + simple_form: + labels: + user_builds_setting: + platforms: "Платформы" + external_nodes: "Дополнительные ноды" + use_extra_tests: "Использовать дополнительные тесты" + # placeholders: + hints: + user_builds_setting: + platforms: "Выберите платформы, которые вы хотели бы использовать." + external_nodes: "Выберите ноды, которые вы хотели бы использовать." + use_extra_tests: "Снимите тут, чтобы отключить дополнительные тесты." diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 78a108da1..5919ac1ca 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -5,6 +5,7 @@ en: new: Create profile: Profile settings: Settings + builds_settings: Builds settings new_header: New user edit_header: Edit list_header: Users diff --git a/config/routes.rb b/config/routes.rb index db47f96b3..dbda47e83 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -248,6 +248,8 @@ Rosa::Application.routes.draw do patch :private get :notifiers patch :notifiers + get :builds_settings + patch :builds_settings put :reset_auth_token end end diff --git a/db/migrate/20150210192749_create_user_builds_settings.rb b/db/migrate/20150210192749_create_user_builds_settings.rb new file mode 100644 index 000000000..0be678c69 --- /dev/null +++ b/db/migrate/20150210192749_create_user_builds_settings.rb @@ -0,0 +1,12 @@ +class CreateUserBuildsSettings < ActiveRecord::Migration + def change + create_table :user_builds_settings do |t| + t.integer :user_id, null: false + t.text :platforms, null: false, default: [], array: true + t.boolean :use_extra_tests, null: false, default: true + t.string :external_nodes + end + + add_index :user_builds_settings, :user_id, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a59b0325..c84ab0f56 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150112204757) do +ActiveRecord::Schema.define(version: 20150210192749) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -628,4 +628,12 @@ ActiveRecord::Schema.define(version: 20150112204757) do t.index ["subject_id", "subject_type"], :name => "index_tokens_on_subject_id_and_subject_type" end + create_table "user_builds_settings", force: true do |t| + t.integer "user_id", null: false + t.text "platforms", default: [], null: false, array: true + t.boolean "use_extra_tests", default: true, null: false + t.string "external_nodes" + t.index ["user_id"], :name => "index_user_builds_settings_on_user_id", :unique => true + end + end