From 3c60347a23337796e35bd595a29735f528f763bb Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 15 Mar 2012 03:25:58 +0400 Subject: [PATCH] [issue #279] Fixes. * Almost finished permissions fixes * Removed is_template from product * Some fixes in crontab_generator partial --- app/assets/stylesheets/design/custom.scss | 10 ++ app/models/ability.rb | 14 ++- app/models/product.rb | 12 +- app/views/platforms/_sidebar.html.haml | 5 +- app/views/platforms/show.html.haml | 9 +- app/views/products/_crontab.html.haml | 119 +++++++++--------- app/views/products/_form.html.haml | 3 - config/locales/models/product.en.yml | 1 + config/locales/models/product.ru.yml | 1 + ...223151_remove_is_template_from_products.rb | 9 ++ db/schema.rb | 3 +- 11 files changed, 107 insertions(+), 79 deletions(-) create mode 100644 db/migrate/20120314223151_remove_is_template_from_products.rb diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 799f82d9d..0149f339e 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -558,3 +558,13 @@ div.dataTables_processing { div.rightlist textarea { resize: none; } + +div#crontab_generator .leftlist, +div#crontab_generator .rightlist { + width: 50%; +} + +div#crontab_generator .leftlist select, +div#crontab_generator .rightlist select { + margin-top: 10px; +} diff --git a/app/models/ability.rb b/app/models/ability.rb index 5bf37c3c0..bfa2bef58 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -73,8 +73,10 @@ class Ability can :read, Platform, :owner_type => 'User', :owner_id => user.id can :read, Platform, :owner_type => 'Group', :owner_id => user.group_ids can(:read, Platform, read_relations_for('platforms')) {|platform| local_reader? platform} - can([:update, :build_all], Platform) {|platform| local_admin? platform} - can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform} +# can([:update, :build_all], Platform) {|platform| local_admin? platform} + can([:freeze, :unfreeze, :update], Platform) {|platform| local_admin? platform} + #can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform} + can(:destroy, Platform) {|platform| owner? platform} can :autocomplete_user_uname, Platform can :read, Repository, :platform => {:visibility => 'open'} @@ -86,7 +88,8 @@ class Ability can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} - can(:manage, Product, read_relations_for('products', 'platforms')) {|product| local_admin? product.platform} + # TODO: WTF??? + #can(:manage, Product, read_relations_for('products', 'platforms')) {|product| local_admin? product.platform} can(:create, ProductBuildList) {|pbl| pbl.product.can_build? and can?(:update, pbl.product)} can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} @@ -111,10 +114,13 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' - cannot :destroy, Repository, :platform => {:platform_type => 'personal'} + cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} cannot :fork, Project, :owner_id => user.id, :owner_type => user.class.to_s cannot :destroy, Issue + cannot :manage, Product, :platform => {:platform_type => 'personal'} + cannot [:clone, :build_all, :freeze, :unfreeze], Platform, :platform_type => 'personal' + can :create, Subscribe do |subscribe| !subscribe.subscribeable.subscribes.exists?(:user_id => user.id) end diff --git a/app/models/product.rb b/app/models/product.rb index e52a700f0..9e3d222e8 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -23,13 +23,13 @@ class Product < ActiveRecord::Base @delete_tar = value end - def can_clone? - is_template - end +# def can_clone? +# is_template +# end - def can_build? - !is_template - end +# def can_build? +# !is_template +# end def clone_from!(template) raise "Only templates can be cloned" unless template.can_clone? diff --git a/app/views/platforms/_sidebar.html.haml b/app/views/platforms/_sidebar.html.haml index 2ef8ac458..83512fb8b 100644 --- a/app/views/platforms/_sidebar.html.haml +++ b/app/views/platforms/_sidebar.html.haml @@ -9,8 +9,9 @@ = link_to t("layout.platforms.about"), platform_path(@platform) %li{:class => (contr == :repositories) ? 'active' : ''} = link_to t("layout.repositories.list_header"), platform_repositories_path(@platform) - %li{:class => (contr == :products) ? 'active' : ''} - = link_to t("layout.products.list_header"), platform_products_path(@platform) + - if can? :read, @platform.products.build + %li{:class => (contr == :products) ? 'active' : ''} + = link_to t("layout.products.list_header"), platform_products_path(@platform) -#- if current_user.owner_of? @platform or current_user.admin? %li{:class => (act == :index && contr == :private_users) ? 'active' : ''} = link_to t("layout.platforms.private_users"), platform_private_users_path(@platform) diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index d5076c630..b1f2acb6e 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -29,11 +29,14 @@ %td= @platform.distrib_type .buttons_block - = link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated" if can? :build_all, @platform + - if can? :build_all, @platform + = link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated" - if @platform.released? - = link_to t("layout.platforms.unfreeze"), unfreeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_unfreeze"), :method => :post, :class => "button left_floated" if can? :unfreeze, @platform + - if can? :unfreeze, @platform + = link_to t("layout.platforms.unfreeze"), unfreeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_unfreeze"), :method => :post, :class => "button left_floated" - else - = link_to t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze"), :method => :post, :class => "button left_floated" if can? :freeze, @platform + - if can? :freeze, @platform + = link_to t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze"), :method => :post, :class => "button left_floated" = link_to "Клонировать", clone_platform_path(@platform), :class => "button left_floated" if can? :clone, @platform .both diff --git a/app/views/products/_crontab.html.haml b/app/views/products/_crontab.html.haml index d489ad3ca..68668f4c1 100644 --- a/app/views/products/_crontab.html.haml +++ b/app/views/products/_crontab.html.haml @@ -71,80 +71,81 @@ %a{ :href => "#" }= t("layout.products.cron_tab_generator.show") #crontab_generator{ :style => "display: none;" } - .columns.wat-cf - .column.left - %h3.title= t("layout.products.cron_tab_generator.minutes") - .group - = label_tag :minute_chooser_every, t("layout.products.cron_tab_generator.every_minute"), :class => :label - = radio_button_tag :minute_chooser, 0, @product.cron_tab_minutes.blank?, :id => :minute_chooser_every, :class => "chooser cron" + .leftlist + %h3.title= t("layout.products.cron_tab_generator.minutes") + .group + = label_tag :minute_chooser_every, t("layout.products.cron_tab_generator.every_minute"), :class => :label + = radio_button_tag :minute_chooser, 0, @product.cron_tab_minutes.blank?, :id => :minute_chooser_every, :class => "chooser cron" - = label_tag :minute_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label - = radio_button_tag :minute_chooser, 1, @product.cron_tab_minutes.present?, :id => :minute_chooser_choose, :class => "chooser cron" + = label_tag :minute_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label + = radio_button_tag :minute_chooser, 1, @product.cron_tab_minutes.present?, :id => :minute_chooser_choose, :class => "chooser cron" - .group - %select{ :name => :minute, :id => :minute, :multiple => true, :disabled => @product.cron_tab_minutes.blank?, :class => "cron" } - - (0..59).each do |min| - %option{ :value => min, :selected => @product.cron_tab_minutes.include?(min) }= min + .group + %select{ :name => :minute, :id => :minute, :multiple => true, :disabled => @product.cron_tab_minutes.blank?, :class => "cron" } + - (0..59).each do |min| + %option{ :value => min, :selected => @product.cron_tab_minutes.include?(min) }= min - .column.right - %h3.title= t("layout.products.cron_tab_generator.hours") - .group - = label_tag :hour_chooser_every, t("layout.products.cron_tab_generator.every_hour"), :class => :label - = radio_button_tag :hour_chooser, 0, @product.cron_tab_hours.blank?, :id => :minute_chooser_every, :class => "chooser cron" + .rightlist + %h3.title= t("layout.products.cron_tab_generator.hours") + .group + = label_tag :hour_chooser_every, t("layout.products.cron_tab_generator.every_hour"), :class => :label + = radio_button_tag :hour_chooser, 0, @product.cron_tab_hours.blank?, :id => :minute_chooser_every, :class => "chooser cron" - = label_tag :hour_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label - = radio_button_tag :hour_chooser, 1, @product.cron_tab_hours.present?, :id => :minute_chooser_choose, :class => "chooser cron" + = label_tag :hour_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label + = radio_button_tag :hour_chooser, 1, @product.cron_tab_hours.present?, :id => :minute_chooser_choose, :class => "chooser cron" - .group - %select{ :name => :hour, :id => :hour, :multiple => true, :disabled => @product.cron_tab_hours.blank?, :class => "cron" } - - (0..23).each do |hour| - %option{ :value => hour, :selected => @product.cron_tab_hours.include?(hour) }= hour + .group + %select{ :name => :hour, :id => :hour, :multiple => true, :disabled => @product.cron_tab_hours.blank?, :class => "cron" } + - (0..23).each do |hour| + %option{ :value => hour, :selected => @product.cron_tab_hours.include?(hour) }= hour + .both - .columns.wat-cf - .column.left - %h3.title= t("layout.products.cron_tab_generator.days") - .group - = label_tag :day_chooser_every, t("layout.products.cron_tab_generator.every_day"), :class => :label - = radio_button_tag :day_chooser, 0, @product.cron_tab_days.blank?, :id => :day_chooser_every, :class => "chooser cron" + .leftlist + %h3.title= t("layout.products.cron_tab_generator.days") + .group + = label_tag :day_chooser_every, t("layout.products.cron_tab_generator.every_day"), :class => :label + = radio_button_tag :day_chooser, 0, @product.cron_tab_days.blank?, :id => :day_chooser_every, :class => "chooser cron" - = label_tag :day_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label - = radio_button_tag :day_chooser, 1, @product.cron_tab_days.present?, :id => :day_chooser_choose, :class => "chooser cron" + = label_tag :day_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label + = radio_button_tag :day_chooser, 1, @product.cron_tab_days.present?, :id => :day_chooser_choose, :class => "chooser cron" - .group - %select{ :name => "day", :id => "day", :multiple => true, :disabled => @product.cron_tab_days.blank?, :class => "cron" } - - (1..31).each do |day| - %option{ :value => day, :selected => @product.cron_tab_days.include?(day) }= day + .group + %select{ :name => "day", :id => "day", :multiple => true, :disabled => @product.cron_tab_days.blank?, :class => "cron" } + - (1..31).each do |day| + %option{ :value => day, :selected => @product.cron_tab_days.include?(day) }= day - .column.right - %h3.title= t("layout.products.cron_tab_generator.months") - .group - = label_tag :month_chooser_every, t("layout.products.cron_tab_generator.every_month"), :class => :label - = radio_button_tag :month_chooser, 0, @product.cron_tab_months.blank?, :id => :month_chooser_every, :class => "chooser cron" + .rightlist + %h3.title= t("layout.products.cron_tab_generator.months") + .group + = label_tag :month_chooser_every, t("layout.products.cron_tab_generator.every_month"), :class => :label + = radio_button_tag :month_chooser, 0, @product.cron_tab_months.blank?, :id => :month_chooser_every, :class => "chooser cron" - = label_tag :month_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label - = radio_button_tag :month_chooser, 1, @product.cron_tab_months.present?, :id => :month_chooser_choose, :class => "chooser cron" + = label_tag :month_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label + = radio_button_tag :month_chooser, 1, @product.cron_tab_months.present?, :id => :month_chooser_choose, :class => "chooser cron" - .group - %select{ :name => "month", :id => "month", :multiple => true, :disabled => @product.cron_tab_months.blank?, :class => "cron" } - - (1..12).each do |month| - %option{ :value => month, :selected => @product.cron_tab_months.include?(month) }= I18n.localize(Time.local(2000, month), :format => "%B") + .group + %select{ :name => "month", :id => "month", :multiple => true, :disabled => @product.cron_tab_months.blank?, :class => "cron" } + - (1..12).each do |month| + %option{ :value => month, :selected => @product.cron_tab_months.include?(month) }= I18n.localize(Time.local(2000, month), :format => "%B") + .both - .columns.wat-cf - .column.left - %h3.title= t("layout.products.cron_tab_generator.weekdays") - .group - = label_tag :weekday_chooser_every, t("layout.products.cron_tab_generator.every_weekday"), :class => :label - = radio_button_tag :weekday_chooser, 0, @product.cron_tab_weekdays.blank?, :id => :weekday_chooser_every, :class => "chooser cron" + .leftlist + %h3.title= t("layout.products.cron_tab_generator.weekdays") + .group + = label_tag :weekday_chooser_every, t("layout.products.cron_tab_generator.every_weekday"), :class => :label + = radio_button_tag :weekday_chooser, 0, @product.cron_tab_weekdays.blank?, :id => :weekday_chooser_every, :class => "chooser cron" - = label_tag :weekday_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label - = radio_button_tag :weekday_chooser, 1, @product.cron_tab_weekdays.present?, :id => :weekday_chooser_choose, :class => "chooser cron" + = label_tag :weekday_chooser_choose, t("layout.products.cron_tab_generator.choose"), :class => :label + = radio_button_tag :weekday_chooser, 1, @product.cron_tab_weekdays.present?, :id => :weekday_chooser_choose, :class => "chooser cron" - .group - %select{ :name => "weekday", :id => "weekday", :multiple => true, :disabled => @product.cron_tab_weekdays.blank?, :class => "cron" } - - Date::DAYNAMES.each_with_index do |day, index| - %option{ :value => index, :selected => @product.cron_tab_weekdays.include?(index) }= t("layout.weekdays.#{day}") + .group + %select{ :name => "weekday", :id => "weekday", :multiple => true, :disabled => @product.cron_tab_weekdays.blank?, :class => "cron" } + - Date::DAYNAMES.each_with_index do |day, index| + %option{ :value => index, :selected => @product.cron_tab_weekdays.include?(index) }= t("layout.weekdays.#{day}") + .both +.both .leftlist= form.label :cron_tab, :class => :label .rightlist= form.text_field :cron_tab, :id => "cron", :class => "text_field", :style => "width: 40%", :disabled => !@product.use_cron, :value => @product.cron_tab -= @product.cron_command +=# @product.cron_command .both diff --git a/app/views/products/_form.html.haml b/app/views/products/_form.html.haml index 3fe806e34..d2ad6df09 100644 --- a/app/views/products/_form.html.haml +++ b/app/views/products/_form.html.haml @@ -36,9 +36,6 @@ .both = render :partial => "products/crontab", :locals => { :form => f } - -.leftlist= f.label :is_template, :class => :label -.rightlist= f.check_box :is_template, :class => 'check_box' - content_for :commented do .leftlist= f.label :system_wide, :class => :label diff --git a/config/locales/models/product.en.yml b/config/locales/models/product.en.yml index 4a64ab00c..bc1288716 100644 --- a/config/locales/models/product.en.yml +++ b/config/locales/models/product.en.yml @@ -41,6 +41,7 @@ en: attributes: product: name: Name + description: Description platform_id: Platform build_status: Build status build_path: ISO path diff --git a/config/locales/models/product.ru.yml b/config/locales/models/product.ru.yml index a845b4990..aa4a0f718 100644 --- a/config/locales/models/product.ru.yml +++ b/config/locales/models/product.ru.yml @@ -41,6 +41,7 @@ ru: attributes: product: name: Название + description: Описание platform_id: Платформа build_status: Статус последней сборки build_path: Путь к iso diff --git a/db/migrate/20120314223151_remove_is_template_from_products.rb b/db/migrate/20120314223151_remove_is_template_from_products.rb new file mode 100644 index 000000000..b130c4f1a --- /dev/null +++ b/db/migrate/20120314223151_remove_is_template_from_products.rb @@ -0,0 +1,9 @@ +class RemoveIsTemplateFromProducts < ActiveRecord::Migration + def up + remove_column :products, :is_template + end + + def down + add_column :products, "is_template", :boolean, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 2b8fc29b9..37ffee4b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120314162313) do +ActiveRecord::Schema.define(:version => 20120314223151) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -249,7 +249,6 @@ ActiveRecord::Schema.define(:version => 20120314162313) do t.string "tar_content_type" t.integer "tar_file_size" t.datetime "tar_updated_at" - t.boolean "is_template", :default => false t.boolean "system_wide", :default => false t.text "cron_tab" t.boolean "use_cron", :default => false