From c87d05b59fb52d044d06d9e4d921e8e6a7c338d5 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 8 Aug 2012 23:57:47 -0300 Subject: [PATCH] Small changes on licenses --- app/controllers/admin/licenses_controller.rb | 18 +++++++++++------- app/views/cms/_general_fields.html.erb | 2 +- app/views/licenses/index.html.erb | 16 +++++++++------- db/schema.rb | 11 ++++++++++- public/stylesheets/application.css | 5 +++++ test/functional/licenses_controller_test.rb | 22 ++++++++++++++++++++++ 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/licenses_controller.rb b/app/controllers/admin/licenses_controller.rb index 49212c5..1cef9ca 100644 --- a/app/controllers/admin/licenses_controller.rb +++ b/app/controllers/admin/licenses_controller.rb @@ -20,7 +20,7 @@ class LicensesController < AdminController end def edit - @license = License.find(params[:license_id]) + @license = environment.licenses.find(params[:license_id]) if request.post? begin @license.update_attributes!(params[:license]) @@ -33,12 +33,16 @@ class LicensesController < AdminController end def remove - @license = License.find(params[:license_id]) - begin - @license.destroy - session[:notice] = _('Licese removed') - rescue - session[:notice] = _('Licese could not be removed') + @license = environment.licenses.find(params[:license_id]) + if request.post? + begin + @license.destroy + session[:notice] = _('License removed') + rescue + session[:notice] = _('License could not be removed') + end + else + session[:notice] = _('License could not be removed') end redirect_to :action => 'index' end diff --git a/app/views/cms/_general_fields.html.erb b/app/views/cms/_general_fields.html.erb index d1f7715..3644994 100644 --- a/app/views/cms/_general_fields.html.erb +++ b/app/views/cms/_general_fields.html.erb @@ -1 +1 @@ -<%= labelled_form_field(_('License'), select(:article, :license_id, [[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]})) %> +<%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %> diff --git a/app/views/licenses/index.html.erb b/app/views/licenses/index.html.erb index af50ba0..02106be 100644 --- a/app/views/licenses/index.html.erb +++ b/app/views/licenses/index.html.erb @@ -1,5 +1,5 @@

<%= _('Manage licenses') %>

- +
@@ -7,14 +7,16 @@ <% @licenses.each do |license| %> - - + + + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :method => 'post', :confirm => _('Are you sure you want to remove this license?') %> <% end %> - - -
<%= _('Name') %> <%= _('Url reference') %>
<%= truncate(license.name, 19) %><%= license.url.present? ? link_to(truncate(license.url, 60), license.url, :target => '_blank') : '' %><%= truncate(license.name, :length => 19) %><%= license.url.present? ? link_to(truncate(license.url, :length => 60), license.url, :target => '_blank') : '' %> <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> - <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %>
<%= link_to(_('NEW LICENSE'), :action => 'create')%>
+ +<% button_bar do %> + <%= button(:add, _('Add a new license'), :action => 'create')%> + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %> +<% end %> diff --git a/db/schema.rb b/db/schema.rb index b3e4e77..0a18e01 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120718145131) do +ActiveRecord::Schema.define(:version => 20120718162001) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do t.integer "translation_of_id" t.string "language" t.string "source_name" + t.integer "license_id" end create_table "articles", :force => true do |t| @@ -125,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do t.integer "translation_of_id" t.string "language" t.string "source_name" + t.integer "license_id" end add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" @@ -314,6 +316,13 @@ ActiveRecord::Schema.define(:version => 20120718145131) do add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" + create_table "licenses", :force => true do |t| + t.string "name", :null => false + t.string "slug", :null => false + t.string "url" + t.integer "environment_id", :null => false + end + create_table "mailing_sents", :force => true do |t| t.integer "mailing_id" t.integer "person_id" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index c6429f4..49c2f52 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2960,6 +2960,11 @@ table.cms-articles .icon:hover { .controller-cms ul.categories li.cat_checked { background: #B8CFE7; } + +.controller-cms select#article_license_id { + max-width: 100%; +} + /************* external blog options *****************/ .controller-cms #fetch-external-feed { diff --git a/test/functional/licenses_controller_test.rb b/test/functional/licenses_controller_test.rb index 9e51048..2158c11 100644 --- a/test/functional/licenses_controller_test.rb +++ b/test/functional/licenses_controller_test.rb @@ -26,6 +26,18 @@ class LicensesControllerTest < ActionController::TestCase assert_includes assigns(:licenses), l2 end + should 'not list licenses from other environments' do + other_env = fast_create(Environment) + l1 = License.create!(:name => 'GPLv3', :environment => environment) + l2 = License.create!(:name => 'AGPL', :environment => other_env) + @controller.stubs(:environment).returns(environment) + + get :index + + assert_includes assigns(:licenses), l1 + assert_not_includes assigns(:licenses), l2 + end + should 'create a new license' do assert_difference License, :count, 1 do post :create, :license => {:name => 'GPLv3'} @@ -43,4 +55,14 @@ class LicensesControllerTest < ActionController::TestCase post :remove, :license_id => license.id assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)} end + + should 'remove a license only with post method' do + license = License.create!(:name => 'GPLv3', :environment => environment) + get :remove, :license_id => license.id + assert_nothing_raised ActiveRecord::RecordNotFound do + License.find(license.id) + end + assert_redirected_to :action => 'index' + end + end -- libgit2 0.21.2