#83: added ability to lock repository

This commit is contained in:
Vokhmin Alexey V 2013-07-26 18:41:39 +04:00
parent 9f7c2fcbd9
commit 8e879ef0c7
7 changed files with 89 additions and 10 deletions

View File

@ -149,6 +149,18 @@ class Platforms::RepositoriesController < Platforms::BaseController
redirect_to platform_repository_path(@platform, @repository) redirect_to platform_repository_path(@platform, @repository)
end 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 protected
def set_members def set_members

View File

@ -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, :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')) {|repository| can? :show, repository.platform}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? 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([: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([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)}
can(:clear, Platform) {|platform| owner?(platform) && platform.personal?} can(:clear, Platform) {|platform| owner?(platform) && platform.personal?}
@ -164,7 +164,8 @@ class Ability
# Shared cannot rights for all users (registered, admin) # Shared cannot rights for all users (registered, admin)
cannot :destroy, Platform, :platform_type => 'personal' cannot :destroy, Platform, :platform_type => 'personal'
cannot [:create, :destroy], Repository, :platform => {:platform_type => 'personal'}, :name => 'main' 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 :clear, Platform, :platform_type => 'main'
cannot :destroy, Issue cannot :destroy, Issue

View File

@ -45,6 +45,18 @@ class Repository < ActiveRecord::Base
end end
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') def add_member(member, role = 'admin')
Relation.add_member(member, self, role) Relation.add_member(member, self, role)
end end
@ -72,6 +84,22 @@ class Repository < ActiveRecord::Base
protected 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 def detele_directory
return unless platform return unless platform
repository_path = platform.path << '/repository' repository_path = platform.path << '/repository'

View File

@ -8,7 +8,30 @@
= render "form", :f => f = render "form", :f => f
%br %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? - if @platform.main?
= render "shared/members_table", = render "shared/members_table",

View File

@ -1,6 +1,9 @@
en: en:
layout: layout:
repositories: repositories:
extra_actions: Extra actions
lock_sync: Lock sync with mirrors
unlock_sync: Unlock sync with mirrors
add_project_to: Add project to repository add_project_to: Add project to repository
edit: Settings edit: Settings
list: List list: List
@ -28,6 +31,10 @@ en:
flash: flash:
repository: repository:
sync_locked: Sync of repository with mirrors has been locked
sync_unlocked: Sync of repository with mirrors has been unlocked
saved: Repository added saved: Repository added
updated: Repository updated updated: Repository updated
save_error: Unable to add repository save_error: Unable to add repository

View File

@ -1,6 +1,9 @@
ru: ru:
layout: layout:
repositories: repositories:
extra_actions: Дополнительные действия
lock_sync: Заблокировать синхронизацию с зеркалами
unlock_sync: Разблокировать синхронизацию с зеркалами
add_project_to: Добавить проект к репозиторию add_project_to: Добавить проект к репозиторию
edit: Настройки edit: Настройки
list: Список list: Список
@ -28,6 +31,9 @@ ru:
flash: flash:
repository: repository:
sync_locked: Синхронизация репозитория c зеркалами заблокирована
sync_unlocked: Синхронизация репозитория c зеркалами разблокирована
saved: Репозиторий успешно добавлен saved: Репозиторий успешно добавлен
updated: Репозиторий успешно обновлен updated: Репозиторий успешно обновлен
save_error: Не удалось добавить репозиторий save_error: Не удалось добавить репозиторий

View File

@ -174,13 +174,15 @@ Rosa::Application.routes.draw do
resources :repositories do resources :repositories do
member do member do
get :add_project get :add_project
delete :remove_project delete :remove_project
get :projects_list get :projects_list
post :remove_members # fixme: change post to delete post :remove_members # fixme: change post to delete
delete :remove_member delete :remove_member
post :add_member post :add_member
put :regenerate_metadata put :regenerate_metadata
put :lock_sync
put :unlock_sync
end end
end end
resources :key_pairs, :only => [:create, :index, :destroy] resources :key_pairs, :only => [:create, :index, :destroy]