diff --git a/Gemfile b/Gemfile index 1700498e2..0993572e2 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,8 @@ gem 'delayed_job' # gem 'actionwebservice' #, :git => 'git://github.com/ywen/actionwebservice.git' gem "rails-xmlrpc", '~> 0.3.6' # :git => 'git://github.com/chipiga/rails-xmlrpc.git' +gem 'rails3-jquery-autocomplete' + group :production do gem "airbrake", '~> 3.0.5' # gem 'newrelic_rpm', '~> 3.1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 7275a1ed3..bab319f8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,8 @@ GEM rails-xmlrpc (0.3.6) rails3-generators (0.17.4) railties (>= 3.0.0) + rails3-jquery-autocomplete (1.0.4) + rails (~> 3.0) railties (3.0.11) actionpack (= 3.0.11) activesupport (= 3.0.11) @@ -225,6 +227,7 @@ DEPENDENCIES rails (= 3.0.11) rails-xmlrpc (~> 0.3.6) rails3-generators + rails3-jquery-autocomplete rr rspec-rails (~> 2.7.0) ruby-debug diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 6c75e91d5..0705710f3 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -5,6 +5,7 @@ class PlatformsController < ApplicationController before_filter :get_paths, :only => [:new, :create, :clone] load_and_authorize_resource + autocomplete :user, :uname def build_all @platform.repositories.each do |repository| diff --git a/app/models/product.rb b/app/models/product.rb index e0c00ebbf..c0aab3ac9 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -6,6 +6,7 @@ class Product < ActiveRecord::Base after_validation :merge_tar_errors before_save :destroy_tar? + after_create :add_admin_relations has_attached_file :tar @@ -76,4 +77,11 @@ class Product < ActiveRecord::Base errors[:tar_content_type] = [] end + def add_admin_relations + repository.relations.where(:role => 'admin').each do |rel| + r = relations.build(:role => 'admin', :object_id => rel.object_id, :object_type => rel.object_type) + r.save + end + end + end diff --git a/app/models/repository.rb b/app/models/repository.rb index 6d324bf21..489ca4731 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -18,6 +18,7 @@ class Repository < ActiveRecord::Base before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy + after_create :add_admin_relation attr_accessible :description, :name #, :platform_id @@ -50,4 +51,11 @@ class Repository < ActiveRecord::Base raise "Failed to delete repository #{name} inside platform #{platform.name}." end end + + def add_admin_relations + platform.relations.where(:role => 'admin').each do |rel| + r = relations.build(:role => 'admin', :object_id => rel.object_id, :object_type => rel.object_type) + r.save + end + end end diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index 8b700e1ee..1d575ca07 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -17,6 +17,10 @@ .group = f.label :released, :class => :label = f.check_box :released, :class => 'check_box' + +.group + = label_tag "ID Хозяина", :class => :label + = autocomplete_field_tag 'admin_id', '', user_name_autocomplete_path, :class => 'text_field' .group.navform.wat-cf %button.button{:type => "submit"} diff --git a/config/routes.rb b/config/routes.rb index 7b748bcbe..d35fd918e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,6 +48,7 @@ Rosa::Application.routes.draw do collection do get 'easy_urpmi' + get :autocomplete_user_uname end resources :products do