From cc68163238231b41c29691b62a6cf7c81521cbe3 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 16 Mar 2012 02:56:12 +0400 Subject: [PATCH] [issue #279] Fixed some bugs: * Redirect to repositroies page when remove repository. * Fixed sorting background in Datatables styles. * Fixed save button translation in platforms form. * Fixed platform save & create flashes. * Fixed cancel buttons in platform, product & repository forms. * Redirect to created product on creation. * Redirect to platform's products page after product destruction. * Fixed permissions to Build button on product page. * Fixed permissions to Add button on repository page. * Fixed forbidden redirect when trying to acces RepositoriesController#projects_list by unprivilleged user. --- app/assets/stylesheets/design/custom.scss | 9 +++++++++ app/controllers/platforms_controller.rb | 6 +++--- app/controllers/products_controller.rb | 4 ++-- app/controllers/repositories_controller.rb | 2 +- app/models/ability.rb | 8 ++++---- app/views/platforms/_form.html.haml | 11 ++++++++--- app/views/platforms/new.html.haml | 7 ++++++- app/views/products/_form.html.haml | 2 +- app/views/products/show.html.haml | 2 +- app/views/repositories/_form.html.haml | 2 +- app/views/repositories/_project.js.erb | 23 +++++++++------------- app/views/repositories/show.html.haml | 3 ++- config/locales/models/platform.en.yml | 2 ++ config/locales/models/platform.ru.yml | 6 ++++-- 14 files changed, 53 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 0149f339e..ec3dcdf84 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -568,3 +568,12 @@ div#crontab_generator .leftlist select, div#crontab_generator .rightlist select { margin-top: 10px; } + +table.dataTable tr.odd td.sorting_1 { + background-color: #F0F0F6; +} + +table.dataTable tr.even td.sorting_1 { + background-color: #FFFFFF; +} + diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 4b8033067..792818cbb 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -57,10 +57,10 @@ class PlatformsController < ApplicationController @platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id) if @platform.save - flash[:notice] = I18n.t("flash.platform.saved") + flash[:notice] = I18n.t("flash.platform.created") redirect_to @platform else - flash[:error] = I18n.t("flash.platform.save_error") + flash[:error] = I18n.t("flash.platform.create_error") render :action => :new end end @@ -125,7 +125,7 @@ class PlatformsController < ApplicationController @platform.delay.destroy if @platform flash[:notice] = t("flash.platform.destroyed") - redirect_to root_path + redirect_to platforms_path end def forbidden diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index dbac9d9bf..50bda2244 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -35,7 +35,7 @@ class ProductsController < ApplicationController @product = @platform.products.new params[:product] if @product.save flash[:notice] = t('flash.product.saved') - redirect_to @platform + redirect_to platform_product_path(@platform, @product) else flash[:error] = t('flash.product.save_error') render :action => :new @@ -58,7 +58,7 @@ class ProductsController < ApplicationController def destroy @product.destroy flash[:notice] = t("flash.product.destroyed") - redirect_to @platform + redirect_to platform_products_path(@platform) end protected diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ec15d9e13..4f8476cde 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -36,7 +36,7 @@ class RepositoriesController < ApplicationController platform_id = @repository.platform_id flash[:notice] = t("flash.repository.destroyed") - redirect_to platform_path(platform_id) + redirect_to platform_repositories_path(platform_id) end def create diff --git a/app/models/ability.rb b/app/models/ability.rb index 562a1974e..6d2884dd4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -79,10 +79,10 @@ class Ability can(:destroy, Platform) {|platform| owner? platform} can :autocomplete_user_uname, Platform - can :read, Repository, :platform => {:visibility => 'open'} - can :read, Repository, :platform => {:owner_type => 'User', :owner_id => user.id} - can :read, Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} - can(:read, Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} + can [:read, :projects_list], Repository, :platform => {:visibility => 'open'} + 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([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index f3a5082e3..344ce9594 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -1,19 +1,24 @@ - unless ['edit', 'update'].include? controller.action_name .leftlist= f.label :name, :class => :label .rightlist= f.text_field :name, :class => 'text_field' + .both .leftlist= f.label :description, :class => :label -.rightlist= f.text_field :description, :class => 'text_field' +.rightlist= f.text_area :description, :class => 'text_field' +.both - unless ['edit', 'update'].include? controller.action_name .leftlist= f.label :distrib_type, :class => :label .rightlist= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types']) + .both .leftlist= f.label :parent, :class => :label .rightlist= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true + .both .leftlist= f.label :released, :class => :label .rightlist= f.check_box :released, :class => 'check_box' +.both .leftlist= label_tag "", t("layout.platforms.admin_id"), :class => :label .rightlist= autocomplete_field_tag 'admin_id', @admin_uname, autocomplete_user_uname_platforms_path, :id_element => '#admin_id_field' @@ -21,9 +26,9 @@ .both .button_block - = submit_tag t("layout.clone") + = submit_tag t("layout.save") -#%input.button{:type => "submit", :class => "button"} -#= image_tag("choose.png", :alt => t("layout.save")) -#= t("layout.clone") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), @platforms_path, :class => "button" + = link_to t("layout.cancel"), @platform.new_record? ? root_path : platform_path(@platform), :class => "button" diff --git a/app/views/platforms/new.html.haml b/app/views/platforms/new.html.haml index a6fad7b32..069b4e8ac 100644 --- a/app/views/platforms/new.html.haml +++ b/app/views/platforms/new.html.haml @@ -1,4 +1,9 @@ -.block +%h3= t("layout.platforms.new_header") + += form_for :platform, :url => platforms_path, :html => { :class => :form } do |f| + = render :partial => "form", :locals => {:f => f} + +-#.block .secondary-navigation %ul.wat-cf %li.first= link_to "#{t("layout.platforms.list")}", @platforms_path diff --git a/app/views/products/_form.html.haml b/app/views/products/_form.html.haml index d2ad6df09..b3dbc07b5 100644 --- a/app/views/products/_form.html.haml +++ b/app/views/products/_form.html.haml @@ -48,5 +48,5 @@ -#= image_tag("choose.png", :alt => t("layout.save")) -#= t("layout.clone") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), platform_path(@platform), :class => "button" + = link_to t("layout.cancel"), @product.new_record? ? platform_path(@platform) : platform_product_path(@platform, @product), :class => "button" diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index 7543a439e..dd705cdc1 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -12,7 +12,7 @@ = link_to image_tag("x.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") -# if @product.can_clone? =# link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button" - - if can?(:create, @product => ProductBuildList) + - if can?(:create, @product.product_build_lists.build) = link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm") %h3= t("layout.products.build_lists_monitoring") diff --git a/app/views/repositories/_form.html.haml b/app/views/repositories/_form.html.haml index 95ee827e1..81adfa1d3 100644 --- a/app/views/repositories/_form.html.haml +++ b/app/views/repositories/_form.html.haml @@ -12,4 +12,4 @@ -#= image_tag("choose.png", :alt => t("layout.save")) -#= t("layout.clone") %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), @repositories_path, :class => "button" + = link_to t("layout.cancel"), @repository.new_record? ? platform_repositories_path(@platform) : platform_repository_path(@platform, @repository), :class => "button" diff --git a/app/views/repositories/_project.js.erb b/app/views/repositories/_project.js.erb index ee2d1c630..161410627 100644 --- a/app/views/repositories/_project.js.erb +++ b/app/views/repositories/_project.js.erb @@ -15,22 +15,17 @@ %>", "<%=j project.description %>", "<%= - j(link_to(' '.html_safe, remove_project_repository_path(@repository, :project_id => project.id), :method => :delete, :confirm => t("layout.confirm"))) - #j link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id) + if can? :remove_project, @repository + j(link_to(' '.html_safe, + remove_project_repository_path(@repository, :project_id => project.id), + :method => :delete, :confirm => t("layout.confirm") + ) + ) + else + '' + end %>" ]<%= project == @projects.last ? '' : ',' %> <% end %> ] - <% - # %tr{:id => "Row#{project_counter}", :class => cycle('odd', 'even')} - # %td - # = link_to project do - # .table-sort-left= image_tag visibility_icon(project.visibility) - # .table-sort-right #{project.owner.uname} / #{project.name} - # %td.td2 - # %span= project.description - # %td.buttons - # = link_to remove_project_repository_path(@repository, :project_id => project.id), :method => :delete, :confirm => t("layout.confirm") do - # %span.delete   - %> } diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 736d07c32..9ce6c7959 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -8,7 +8,8 @@ %br %br %h3.fix= t("layout.projects.list_header") -= link_to t("layout.projects.add"), add_project_repository_path(@repository), :class => 'button' +- if can? :add_project, @repository + = link_to t("layout.projects.add"), add_project_repository_path(@repository), :class => 'button' = render :partial => 'proj_list'#, :object => @projects =# will_paginate @projects diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index e833f1ceb..8aa081421 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -39,7 +39,9 @@ en: flash: platform: saved: Platform saved + created: Platform created save_error: Platform saves error + create_error: Platform create error freezed: Platform freezed freeze_error: Platform freezing error, try again unfreezed: Platform unfreezed diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index 26cf1ab0d..330ccad14 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -38,8 +38,10 @@ ru: flash: platform: - saved: Платформа успешно добавлена - save_error: Не удалось создать платформу + saved: Платформа успешно сохранена + created: Платформа успешно добавлена + save_error: Не удалось сохранить платформу + create_error: Не удалось создать платформу freezed: Платформа успешно заморожена freeze_error: Не удалось заморозить платформу, попробуйте еще раз unfreezed: Платформа успешно разморожена