diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index fc96434a6..a0b7a6a7f 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -149,6 +149,18 @@ class Platforms::RepositoriesController < Platforms::BaseController redirect_to platform_repository_path(@platform, @repository) end + def lock_sync + @repository.lock_sync + flash[:notice] = t('flash.repository.sync_locked') + redirect_to edit_platform_repository_path(@platform, @repository) + end + + def unlock_sync + @repository.unlock_sync + flash[:notice] = t('flash.repository.sync_unlocked') + redirect_to edit_platform_repository_path(@platform, @repository) + end + protected def set_members diff --git a/app/models/ability.rb b/app/models/ability.rb index 3cbbd06f2..27707e5b4 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], Repository) {|repository| local_admin? 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([: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,8 @@ 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], Repository, :platform => {:platform_type => 'personal'} + cannot [:remove_members, :remove_member, :add_member, :lock_sync, :unlock_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 6802c4c0e..918673357 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -45,6 +45,18 @@ class Repository < ActiveRecord::Base end end + def sync_locked? + sync_actions :check + end + + def lock_sync + sync_actions :lock + end + + def unlock_sync + sync_actions :unlock + end + def add_member(member, role = 'admin') Relation.add_member(member, self, role) end @@ -72,6 +84,22 @@ class Repository < ActiveRecord::Base protected + def sync_actions(action) + result = false + (['SRPMS'] << Arch.pluck(:name)).each do |arch| + path = "#{platform.path}/repository/#{arch}/#{name}/.sync.lock" + case action + when :lock + result ||= system 'touch', path + when :unlock + result ||= system 'rm', '-rf', path + when :check + return true if File.exist?(path) + end + end + return result + end + def detele_directory return unless platform repository_path = platform.path << '/repository' diff --git a/app/views/platforms/repositories/edit.html.haml b/app/views/platforms/repositories/edit.html.haml index 088c0fae4..f839cf9d1 100644 --- a/app/views/platforms/repositories/edit.html.haml +++ b/app/views/platforms/repositories/edit.html.haml @@ -8,7 +8,30 @@ = render "form", :f => f %br -= render 'regenerate_metadata' if can?(:regenerate_metadata, @repository) +=# render 'regenerate_metadata' if can?(:regenerate_metadata, @repository) + + +- if can?(:update, @repository) + .hr + %h3= t('layout.repositories.extra_actions') + + = link_to t('layout.repositories.regenerate_metadata'), + regenerate_metadata_platform_repository_path(@platform, @repository), + :method => :put, :confirm => t('layout.confirm'), :class => 'button' + + - if @platform.main? + - if @repository.sync_locked? + - label = t('layout.repositories.unlock_sync') + - path = unlock_sync_platform_repository_path(@platform, @repository) + - else + - label = t('layout.repositories.lock_sync') + - path = lock_sync_platform_repository_path(@platform, @repository) + + = link_to label, path, :method => :put, :confirm => t('layout.confirm'), :class => 'button' + .both + .hr + + - if @platform.main? = render "shared/members_table", diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 3b5720897..4541d2ede 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -1,6 +1,9 @@ en: layout: repositories: + extra_actions: Extra actions + lock_sync: Lock sync with mirrors + unlock_sync: Unlock sync with mirrors add_project_to: Add project to repository edit: Settings list: List @@ -28,6 +31,10 @@ en: flash: repository: + sync_locked: Sync of repository with mirrors has been locked + sync_unlocked: Sync of repository with mirrors has been unlocked + + saved: Repository added updated: Repository updated save_error: Unable to add repository diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 21bc8f5cd..44d6f3e12 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -1,6 +1,9 @@ ru: layout: repositories: + extra_actions: Дополнительные действия + lock_sync: Заблокировать синхронизацию с зеркалами + unlock_sync: Разблокировать синхронизацию с зеркалами add_project_to: Добавить проект к репозиторию edit: Настройки list: Список @@ -28,6 +31,9 @@ ru: flash: repository: + sync_locked: Синхронизация репозитория c зеркалами заблокирована + sync_unlocked: Синхронизация репозитория c зеркалами разблокирована + saved: Репозиторий успешно добавлен updated: Репозиторий успешно обновлен save_error: Не удалось добавить репозиторий diff --git a/config/routes.rb b/config/routes.rb index f296ebe97..de3859f66 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -174,13 +174,15 @@ Rosa::Application.routes.draw do resources :repositories do member do - get :add_project - delete :remove_project - get :projects_list - post :remove_members # fixme: change post to delete - delete :remove_member - post :add_member - put :regenerate_metadata + get :add_project + delete :remove_project + get :projects_list + post :remove_members # fixme: change post to delete + delete :remove_member + post :add_member + put :regenerate_metadata + put :lock_sync + put :unlock_sync end end resources :key_pairs, :only => [:create, :index, :destroy]