From ad46e256546e7c0702b4837f5737c9d60ce19658 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 26 Jul 2013 19:38:39 +0400 Subject: [PATCH] #83: added #start_sync and #stop_sync actions into Repository API --- .../api/v1/repositories_controller.rb | 10 ++++++++++ app/models/ability.rb | 4 ++-- app/models/repository.rb | 12 ++++++++++-- .../repositories/_regenerate_metadata.html.haml | 8 -------- config/routes.rb | 16 +++++++++------- 5 files changed, 31 insertions(+), 19 deletions(-) delete mode 100644 app/views/platforms/repositories/_regenerate_metadata.html.haml diff --git a/app/controllers/api/v1/repositories_controller.rb b/app/controllers/api/v1/repositories_controller.rb index 642ad7ca0..93076072b 100644 --- a/app/controllers/api/v1/repositories_controller.rb +++ b/app/controllers/api/v1/repositories_controller.rb @@ -33,6 +33,16 @@ class Api::V1::RepositoriesController < Api::V1::BaseController def key_pair end + def start_sync + @repository.start_sync + render :nothing => true + end + + def stop_sync + @repository.stop_sync + render :nothing => true + end + def add_project project = Project.where(:id => params[:project_id]).first if project diff --git a/app/models/ability.rb b/app/models/ability.rb index 27707e5b4..9e2e886e3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -119,7 +119,7 @@ class Ability can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list, :projects], Repository, read_relations_for('repositories')) {|repository| can? :show, repository.platform} can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} - can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata, :lock_sync, :unlock_sync], Repository) {|repository| local_admin? repository.platform} + can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata, :lock_sync, :unlock_sync, :start_sync, :stop_sync], Repository) {|repository| local_admin? repository.platform} can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)} can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)} can(:clear, Platform) {|platform| owner?(platform) && platform.personal?} @@ -164,7 +164,7 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' cannot [:create, :destroy], Repository, :platform => {:platform_type => 'personal'}, :name => 'main' - cannot [:remove_members, :remove_member, :add_member, :lock_sync, :unlock_sync], Repository, :platform => {:platform_type => 'personal'} + cannot [:remove_members, :remove_member, :add_member, :lock_sync, :unlock_sync, :start_sync, :stop_sync], 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 918673357..88c729e83 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -57,6 +57,14 @@ class Repository < ActiveRecord::Base sync_actions :unlock end + def start_sync + sync_actions :lock, '.repo.lock' + end + + def stop_sync + sync_actions :unlock, '.repo.lock' + end + def add_member(member, role = 'admin') Relation.add_member(member, self, role) end @@ -84,10 +92,10 @@ class Repository < ActiveRecord::Base protected - def sync_actions(action) + def sync_actions(action, lock_file = '.sync.lock') result = false (['SRPMS'] << Arch.pluck(:name)).each do |arch| - path = "#{platform.path}/repository/#{arch}/#{name}/.sync.lock" + path = "#{platform.path}/repository/#{arch}/#{name}/#{lock_file}" case action when :lock result ||= system 'touch', path diff --git a/app/views/platforms/repositories/_regenerate_metadata.html.haml b/app/views/platforms/repositories/_regenerate_metadata.html.haml deleted file mode 100644 index 89bee4eb5..000000000 --- a/app/views/platforms/repositories/_regenerate_metadata.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -.hr -= form_for @repository, :url => regenerate_metadata_platform_repository_path(@platform, @repository), :html => { :class => :form, :method => :put } do |f| - .leftside= t('layout.repositories.regenerate_metadata') - .rightside - = select_tag :build_for_platform_id, options_from_collection_for_select(Platform.main, :id, :name) if @platform.personal? - = f.submit t('layout.repositories.regenerate_metadata'), :confirm => t('layout.confirm') - .hr{:style => 'padding-bottom:20px;'} -.both \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index de3859f66..ac5f5131c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,13 +39,15 @@ Rosa::Application.routes.draw do end resources :repositories, :only => [:show, :update, :destroy] do member { - get :projects - get :key_pair - put :add_member - delete :remove_member - put :add_project - delete :remove_project - put :signatures + get :projects + get :key_pair + put :add_member + delete :remove_member + put :add_project + delete :remove_project + put :signatures + put :start_sync + put :stop_sync } end resources :projects, :only => [:index, :show, :update, :create, :destroy] do