From f0f11cb9dc5d8b5c7abc0a82f3d58df872212576 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 6 Sep 2012 17:43:50 +0400 Subject: [PATCH] #631: added #edit #update actions to platforms/repositories_controller, wrote migration, updated models --- .gitignore | 1 + .../platforms/repositories_controller.rb | 17 +++++++++++++++++ .../projects/build_lists_controller.rb | 2 +- app/models/ability.rb | 6 +++--- app/models/repository.rb | 2 +- .../platforms/repositories/_form.html.haml | 8 ++++++-- app/views/platforms/repositories/edit.html.haml | 8 ++++++++ app/views/platforms/repositories/show.html.haml | 7 ++++++- config/locales/models/repository.en.yml | 3 +++ config/locales/models/repository.ru.yml | 3 +++ ...48_add_publish_wtihout_qa_to_repositories.rb | 5 +++++ 11 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 app/views/platforms/repositories/edit.html.haml create mode 100644 db/migrate/20120906115648_add_publish_wtihout_qa_to_repositories.rb diff --git a/.gitignore b/.gitignore index ef7fd18e7..0511a9ffc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*~ .bundle .rvmrc .DS_Store diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index 7e617e7d5..e52faea39 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -14,6 +14,23 @@ class Platforms::RepositoriesController < Platforms::BaseController @projects = @projects.search(params[:query]).search_order if params[:query].present? end + def edit + end + + def update + if @repository.update_attributes( + :description => params[:repository][:description], + :publish_wtihout_qa => (params[:repository][:publish_wtihout_qa] || @repository.publish_wtihout_qa) + ) + flash[:notice] = I18n.t("flash.repository.updated") + redirect_to platform_repository_path(@platform, @repository) + else + flash[:error] = I18n.t("flash.repository.update_error") + flash[:warning] = @repository.errors.full_messages.join('. ') + render :action => :edit + end + end + def new @repository = Repository.new @platform_id = params[:platform_id] diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index e12eced17..3edff9b3d 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -49,7 +49,7 @@ class Projects::BuildListsController < Projects::BaseController @repository = @project.repositories.where(:id => @platform.repository_ids).first params[:build_list][:save_to_repository_id] = @repository.id - params[:build_list][:auto_publish] = false if @platform.released + params[:build_list][:auto_publish] = false if @platform.released && !@repository.publish_wtihout_qa Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform| diff --git a/app/models/ability.rb b/app/models/ability.rb index c356badc8..c9dafc70f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -93,9 +93,9 @@ class Ability can [:read, :projects_list], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} - can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can([:create, :edit, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?} - can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} + can([:change_visibility, :settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} @@ -125,7 +125,7 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' - cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} + cannot [:create, :destroy, :edit, :update, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} cannot :clear, Platform, :platform_type => 'main' cannot :destroy, Issue diff --git a/app/models/repository.rb b/app/models/repository.rb index 491d219e8..0069872de 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -14,7 +14,7 @@ class Repository < ActiveRecord::Base before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy, :unless => lambda {Thread.current[:skip]} - attr_accessible :name, :description + attr_accessible :name, :description, :publish_wtihout_qa attr_readonly :name, :platform_id def base_clone(attrs = {}) diff --git a/app/views/platforms/repositories/_form.html.haml b/app/views/platforms/repositories/_form.html.haml index 2539464d6..7c5a9c5c4 100644 --- a/app/views/platforms/repositories/_form.html.haml +++ b/app/views/platforms/repositories/_form.html.haml @@ -1,9 +1,13 @@ -.leftlist= f.label :name, t("activerecord.attributes.repository.name"), :class => :label -.rightlist= f.text_field :name, :class => 'text_field' +- unless ['edit', 'update'].include? controller.action_name + .leftlist= f.label :name, t("activerecord.attributes.repository.name"), :class => :label + .rightlist= f.text_field :name, :class => 'text_field' .leftlist= f.label :description, t("activerecord.attributes.repository.description"), :class => :label .rightlist= f.text_field :description, :class => 'text_field' +.leftlist= f.label :publish_wtihout_qa, t("activerecord.attributes.repository.publish_wtihout_qa"), :class => :label +.rightlist= f.check_box :publish_wtihout_qa, :class => 'check_box' + .both .button_block diff --git a/app/views/platforms/repositories/edit.html.haml b/app/views/platforms/repositories/edit.html.haml new file mode 100644 index 000000000..d9fe2895c --- /dev/null +++ b/app/views/platforms/repositories/edit.html.haml @@ -0,0 +1,8 @@ +-set_meta_tags :title => title_object(@repository) += render 'submenu' += render 'sidebar' + +%h3.fix= "#{t("layout.repositories.about")}: #{@repository.name}" + += form_for @repository, :url => platform_repository_path(@platform, @repository), :html => { :class => :form } do |f| + = render "form", :f => f diff --git a/app/views/platforms/repositories/show.html.haml b/app/views/platforms/repositories/show.html.haml index 5540913de..98a924949 100644 --- a/app/views/platforms/repositories/show.html.haml +++ b/app/views/platforms/repositories/show.html.haml @@ -2,7 +2,12 @@ = render 'submenu' = render 'sidebar' -%h3.fix= "#{t("layout.repositories.about")}: #{@repository.name}" +%h3.fix + = "#{t("layout.repositories.about")}: " + - if can? :edit, @repository + = link_to @repository.name, edit_platform_repository_path(@platform, @repository) + - else + = @repository.name %p= @repository.description diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 7f8ad732b..a1778bb60 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -29,7 +29,9 @@ en: flash: repository: saved: Repository added + updated: Repository updated save_error: Unable to add repository + update_error: Unable to update repository destroyed: Repository deleted project_added: Project added to repository project_not_added: Project adding error. A project with such name already exists in this repository. Remove the old project first @@ -44,6 +46,7 @@ en: repository: name: Name description: Description + publish_wtihout_qa: Publication after release platform_id: Platform platform: Platform created_at: Created diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index b01307e1c..b0abe1d3d 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -29,7 +29,9 @@ ru: flash: repository: saved: Репозиторий успешно добавлен + updated: Репозиторий успешно обновлен save_error: Не удалось добавить репозиторий + update_error: Не удалось обновить репозиторий destroyed: Репозиторий успешно удален project_added: Проект добавлен к репозиторию project_not_added: Не удалось добавить проект. В этом репозитории уже есть проект с таким именем. Сначала нужно удалить старый проект @@ -44,6 +46,7 @@ ru: repository: name: Название description: Описание + publish_wtihout_qa: Публикация после релиза platform_id: Платформа platform: Платформа created_at: Создан diff --git a/db/migrate/20120906115648_add_publish_wtihout_qa_to_repositories.rb b/db/migrate/20120906115648_add_publish_wtihout_qa_to_repositories.rb new file mode 100644 index 000000000..c5620669b --- /dev/null +++ b/db/migrate/20120906115648_add_publish_wtihout_qa_to_repositories.rb @@ -0,0 +1,5 @@ +class AddPublishWtihoutQaToRepositories < ActiveRecord::Migration + def change + add_column :repositories, :publish_wtihout_qa, :boolean, :default => false + end +end