From 559f3d2ee944f2cba72e90f5f2c2ef4445db3078 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 20 Oct 2011 23:23:38 +0300 Subject: [PATCH] Fix bug and refactor role relation. Apply platforms JSON display in supplied format. Refs #1959 --- Gemfile | 4 +--- app/controllers/application_controller.rb | 3 +-- app/controllers/platforms_controller.rb | 15 ++++++++++++++- db/schema.rb | 11 +---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index c2aae76a5..112c0e629 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem "russian" gem "grit" gem 'delayed_job' +gem 'whenever', :require => false gem 'unicorn' group :production do @@ -54,9 +55,6 @@ end group :development, :test do gem 'mysql2', '<= 0.2.9' end -gem "capistrano" -gem "capistrano-ext" -gem 'whenever', :require => false group :test do gem 'rspec-rails', '~> 2.6.1' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d58bb528f..e0c23c35d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,8 +4,7 @@ class ApplicationController < ActionController::Base layout :layout_by_resource private def get_role(object_id, object_type, target_id, target_type) - rel=Relation.where(:object_id=>object_id, :object_type=>object_type, :target_id=>target_id, :target_type=>target_type).first - rel ? return rel.roles : return nil + Relation.where(:object_id=>object_id, :object_type=>object_type, :target_id=>target_id, :target_type=>target_type).first.try(:roles) end def checkaccess diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 9494dd461..b94ba4b5c 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -7,7 +7,20 @@ class PlatformsController < ApplicationController before_filter :get_paths, :only => [:new, :create] def index - @platforms = Platform.paginate(:page => params[:platform_page]) + respond_to do |format| + format.html { @platforms = Platform.paginate(:page => params[:platform_page]) } + format.json do + @platforms = Platform.where(:distrib_type => 'mandriva', :visibility => 'open', :platform_type => 'main') + render :json => { + :platforms => @platforms.map do |p| + {:name => p.name, + :architectures => ['i586', 'x86_64'], + :repositories => p.repositories.map(&:name), + :url => "http://abs.rosalab.ru/downloads/platforms/#{p.name}/repository"} + end + } + end + end end def show diff --git a/db/schema.rb b/db/schema.rb index b2973b31e..7cab92c13 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -190,7 +190,6 @@ ActiveRecord::Schema.define(:version => 20111019173246) do t.string "object_type" t.integer "target_id" t.string "target_type" - t.integer "role_id" t.datetime "created_at" t.datetime "updated_at" end @@ -206,12 +205,6 @@ ActiveRecord::Schema.define(:version => 20111019173246) do t.string "visibility", :default => "open" end - create_table "rights", :force => true do |t| - t.string "name" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "role_lines", :force => true do |t| t.integer "role_id" t.integer "relation_id" @@ -221,8 +214,6 @@ ActiveRecord::Schema.define(:version => 20111019173246) do create_table "roles", :force => true do |t| t.string "name" - t.string "to" - t.string "on" t.datetime "created_at" t.datetime "updated_at" end @@ -248,9 +239,9 @@ ActiveRecord::Schema.define(:version => 20111019173246) do t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" - t.string "uname" t.string "nickname" t.text "ssh_key" + t.string "uname" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true