From 874086e1cab54988f43e658d649759e48292acb8 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 26 Jun 2013 13:00:51 +0400 Subject: [PATCH] #192: added ability to change visibility of platform --- .../platforms/platforms_controller.rb | 11 +++++++ app/models/ability.rb | 4 +-- app/models/platform.rb | 4 +-- app/views/platforms/platforms/edit.html.haml | 10 ++++++ config/locales/models/platform.en.yml | 3 ++ config/locales/models/platform.ru.yml | 3 ++ config/locales/models/repository.en.yml | 2 -- config/locales/models/repository.ru.yml | 2 -- config/locales/models/token.ru.yml | 4 +-- config/routes.rb | 3 +- .../platforms/platforms_controller_spec.rb | 32 +++++++++++++++++++ 11 files changed, 66 insertions(+), 12 deletions(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 5c5992673..57ea23f7c 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -56,6 +56,17 @@ class Platforms::PlatformsController < Platforms::BaseController end end + def change_visibility + if @platform.change_visibility + flash[:notice] = I18n.t("flash.platform.saved") + redirect_to @platform + else + flash[:error] = I18n.t("flash.platform.save_error") + flash[:warning] = @platform.errors.full_messages.join('. ') + render :action => :edit + end + end + def clone @cloned = Platform.new @cloned.name = @platform.name + "_clone" diff --git a/app/models/ability.rb b/app/models/ability.rb index ddeb1c4c9..a86fc5e91 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -105,7 +105,7 @@ class Ability can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform} can :related, Platform, :id => user.repositories.pluck(:platform_id) - can([:update, :destroy], Platform) {|platform| owner?(platform) } + can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) } can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) } can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)} @@ -118,7 +118,7 @@ class Ability 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?} - can([:change_visibility, :settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} + can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} diff --git a/app/models/platform.rb b/app/models/platform.rb index 47c364410..4cca33b68 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,6 +1,6 @@ # -*- encoding : utf-8 -*- class Platform < ActiveRecord::Base - VISIBILITIES = ['open']#, 'hidden'] # Disable support hidden platforms. + VISIBILITIES = %w(open hidden) belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :owner, :polymorphic => true @@ -142,10 +142,8 @@ class Platform < ActiveRecord::Base def change_visibility if !hidden? update_attributes(:visibility => 'hidden') - remove_symlink_directory else update_attributes(:visibility => 'open') - symlink_directory end end diff --git a/app/views/platforms/platforms/edit.html.haml b/app/views/platforms/platforms/edit.html.haml index 18442734e..bb7f4cc91 100644 --- a/app/views/platforms/platforms/edit.html.haml +++ b/app/views/platforms/platforms/edit.html.haml @@ -5,6 +5,16 @@ = form_for @platform, :url => platform_path(@platform), :html => { :class => :form } do |f| = render "form", :f => f +- if can? :change_visibility, @platform + .hr + .leftside= t('activerecord.attributes.platform.visibility') + .rightside= link_to t("layout.platforms.change_visibility_from_#{@platform.visibility}"), + change_visibility_platform_path(@platform), + :method => :post, + :confirm => t("layout.platforms.confirm_change_visibility"), + :class => 'button' + .both + - if can? :destroy, @platform .hr .leftside= t("layout.platforms.delete_warning") diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index dfc0c9a4a..4ef57f072 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -46,6 +46,9 @@ en: mass_build: Mass build build_task: Build Task refresh_button: Refresh + change_visibility_from_hidden: Change status to "Public" + change_visibility_from_open: Change status to "Private" + confirm_change_visibility: Are you sure you want to change visibility of this platform? flash: platform: diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index 8221b07e4..8d918053c 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -46,6 +46,9 @@ ru: build_task: Сборочное задание refresh_button: Обновить project: Проект + change_visibility_from_hidden: Сменить статус на "Публичный" + change_visibility_from_open: Сменить статус на "Приватный" + confirm_change_visibility: Вы уверены, что хотите сменить статус этой платформы? flash: platform: diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 3330fd0e9..3b5720897 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -22,8 +22,6 @@ en: personal_repositories: settings_header: Settings - change_visibility_from_hidden: Change status to "Public" - change_visibility_from_open: Change status to "Private" settings: Settings show: My repository private_users: Private repository users diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 257926dbc..21bc8f5cd 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -22,8 +22,6 @@ ru: personal_repositories: settings_header: Настройки - change_visibility_from_hidden: Сменить статус на "Публичный" - change_visibility_from_open: Сменить статус на "Приватный" settings: Настройки show: Мой репозиторий private_users: Пользователи приватного репозитория diff --git a/config/locales/models/token.ru.yml b/config/locales/models/token.ru.yml index 60b3f53d7..26da79171 100644 --- a/config/locales/models/token.ru.yml +++ b/config/locales/models/token.ru.yml @@ -28,5 +28,5 @@ ru: authentication_token: Токен created_at: Создан updated_at: Обновлен - creator: Создатель - updater: Обновитель + creator: Создал + updater: Обновил diff --git a/config/routes.rb b/config/routes.rb index 7ee792bc5..3c873c481 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,8 +143,9 @@ Rosa::Application.routes.draw do get :clone get :members post :remove_members # fixme: change post to delete + post :change_visibility delete :remove_member - post :add_member + post :add_member post :make_clone get :advisories end diff --git a/spec/controllers/platforms/platforms_controller_spec.rb b/spec/controllers/platforms/platforms_controller_spec.rb index 96312890e..697a18cfb 100644 --- a/spec/controllers/platforms/platforms_controller_spec.rb +++ b/spec/controllers/platforms/platforms_controller_spec.rb @@ -29,6 +29,22 @@ shared_examples_for 'platform user with owner rights' do end end + context 'perform change_visibility action' do + before do + @visibility = @platform.visibility + post :change_visibility, :id => @platform.id + end + + it 'should be able to perform action' do + response.should redirect_to(platform_path(@platform)) + end + + it 'ensures that visibility of platform has been changed' do + @platform.reload + @platform.visibility.should_not == @visibility + end + end + context 'platform user with destroy rights for main platforms only' do it 'should be able to perform destroy action for main platform' do delete :destroy, :id => @platform.id @@ -62,6 +78,22 @@ shared_examples_for 'platform user without owner rights' do end end + context 'perform change_visibility action' do + before do + @visibility = @platform.visibility + post :change_visibility, :id => @platform.id + end + + it 'should not be able to perform action' do + response.should_not be_success + end + + it 'ensures that visibility of platform has not been changed' do + @platform.reload + @platform.visibility.should == @visibility + end + end + context 'platform user without destroy rights' do it 'should not be able to perform destroy action for main platform' do delete :destroy, :id => @platform.id