From 3ebd36f6fe49501a7c74a9d3e692e6d9743b198a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 22:02:42 +0400 Subject: [PATCH] [refs #525] Erase corrections and refactor --- app/controllers/platforms/platforms_controller.rb | 7 +++++++ app/controllers/platforms/repositories_controller.rb | 6 ------ app/models/ability.rb | 6 ++++-- app/models/platform.rb | 4 ++++ app/models/repository.rb | 4 ---- app/views/platforms/platforms/edit.html.haml | 5 +++++ app/views/platforms/repositories/show.html.haml | 2 -- config/locales/models/repository.en.yml | 1 + config/locales/models/repository.ru.yml | 1 + config/routes.rb | 2 +- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 347704c40..3566060d9 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -143,4 +143,11 @@ class Platforms::PlatformsController < Platforms::BaseController def advisories @advisories = @platform.advisories.paginate(:page => params[:page]) end + + def erase + @platform.erase + flash[:success] = t('flash.repository.erase') + redirect_to edit_platform_path(@platform) + end + end diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index f2d5fb6fd..d37caf8c6 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -54,12 +54,6 @@ class Platforms::RepositoriesController < Platforms::BaseController end end - def erase - @repository.erase - flash[:success] = t('flash.repository.erase') - redirect_to platform_repository_path(@platform, @repository) - end - def projects_list owner_subquery = " diff --git a/app/models/ability.rb b/app/models/ability.rb index 498b83caa..2607a3b46 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -90,7 +90,8 @@ class Ability can [:read, :projects_list], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} - can([:create, :update, :projects_list, :add_project, :remove_project, :erase], Repository) {|repository| local_admin? repository.platform} + can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can(:erase, Platform) {|platform| local_admin?(platform) && platform.platform_type == 'personal'} can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:visibility => 'open'} @@ -119,7 +120,8 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' - cannot [:create, :destroy, :add_project, :remove_project, :erase], Repository, :platform => {:platform_type => 'personal'} + cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} + cannot :erase, Platform, :platform_type => 'main' cannot :destroy, Issue cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' diff --git a/app/models/platform.rb b/app/models/platform.rb index c617c724a..74cb81ded 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -48,6 +48,10 @@ class Platform < ActiveRecord::Base include Modules::Models::Owner + def erase + system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") + end + def urpmi_list(host, pair = nil) blank_pair = {:login => 'login', :pass => 'password'} pair = blank_pair if pair.blank? diff --git a/app/models/repository.rb b/app/models/repository.rb index 99b483042..57c741790 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -16,10 +16,6 @@ class Repository < ActiveRecord::Base attr_accessible :name, :description attr_readonly :name, :platform_id - def erase - system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.platform.name }/repository/*") - end - def base_clone(attrs = {}) dup.tap do |c| c.platform_id = nil diff --git a/app/views/platforms/platforms/edit.html.haml b/app/views/platforms/platforms/edit.html.haml index a397e71d1..56f6cb162 100644 --- a/app/views/platforms/platforms/edit.html.haml +++ b/app/views/platforms/platforms/edit.html.haml @@ -9,3 +9,8 @@ .hr .leftside= t("layout.platforms.delete_warning") .rightside= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button' +- if can? :erase, @platform + .hr + .leftside= t("layout.repositories.erase_warning") + .rightside= link_to t("layout.repositories.erase"), erase_platform_path(@platform), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post + .both diff --git a/app/views/platforms/repositories/show.html.haml b/app/views/platforms/repositories/show.html.haml index ffc4f9bc4..5540913de 100644 --- a/app/views/platforms/repositories/show.html.haml +++ b/app/views/platforms/repositories/show.html.haml @@ -11,7 +11,5 @@ %h3.fix= t("layout.projects.list_header") - if can? :add_project, @repository = link_to t("layout.projects.add"), add_project_platform_repository_path(@platform, @repository), :class => 'button' -- if can? :erase, @repository - = link_to t("layout.repositories.erase"), erase_platform_repository_path(@platform, @repository), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post = render 'proj_list' diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 82dcc3135..81cf14472 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -16,6 +16,7 @@ en: current_repository_header: Current repository erase: Erase erase_confirm: Are you sure you want to erase this repository? + erase_warning: Warning! Erased repository can not be restored! personal_repositories: settings_header: Settings diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 5557a74ce..fb9e7fe31 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -16,6 +16,7 @@ ru: current_repository_header: Текущий репозиторий erase: Очистить erase_confirm: Уверены, что хотите очистить репозиторий? + erase_warning: Внимание! Очищеный репозиторий не может быть восстановлен! personal_repositories: settings_header: Настройки diff --git a/config/routes.rb b/config/routes.rb index 0beeb7144..af396fa70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,7 @@ Rosa::Application.routes.draw do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] member do + post :erase get :clone get :members post :remove_members @@ -58,7 +59,6 @@ Rosa::Application.routes.draw do resources :repositories do member do get :add_project - post :erase delete :remove_project get :projects_list end