Commit c87d05b59fb52d044d06d9e4d921e8e6a7c338d5
1 parent
3e98d8f0
Exists in
master
and in
23 other branches
Small changes on licenses
* Licenses only can be removed with method 'post' * Fixing truncate calls to stop displaying deprecation warnings * Added buttons to add a new license and to go back to admin panel * Added new db/schema (ActionItem2379)
Showing
6 changed files
with
58 additions
and
16 deletions
Show diff stats
app/controllers/admin/licenses_controller.rb
| @@ -20,7 +20,7 @@ class LicensesController < AdminController | @@ -20,7 +20,7 @@ class LicensesController < AdminController | ||
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | def edit | 22 | def edit |
| 23 | - @license = License.find(params[:license_id]) | 23 | + @license = environment.licenses.find(params[:license_id]) |
| 24 | if request.post? | 24 | if request.post? |
| 25 | begin | 25 | begin |
| 26 | @license.update_attributes!(params[:license]) | 26 | @license.update_attributes!(params[:license]) |
| @@ -33,12 +33,16 @@ class LicensesController < AdminController | @@ -33,12 +33,16 @@ class LicensesController < AdminController | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | def remove | 35 | def remove |
| 36 | - @license = License.find(params[:license_id]) | ||
| 37 | - begin | ||
| 38 | - @license.destroy | ||
| 39 | - session[:notice] = _('Licese removed') | ||
| 40 | - rescue | ||
| 41 | - session[:notice] = _('Licese could not be removed') | 36 | + @license = environment.licenses.find(params[:license_id]) |
| 37 | + if request.post? | ||
| 38 | + begin | ||
| 39 | + @license.destroy | ||
| 40 | + session[:notice] = _('License removed') | ||
| 41 | + rescue | ||
| 42 | + session[:notice] = _('License could not be removed') | ||
| 43 | + end | ||
| 44 | + else | ||
| 45 | + session[:notice] = _('License could not be removed') | ||
| 42 | end | 46 | end |
| 43 | redirect_to :action => 'index' | 47 | redirect_to :action => 'index' |
| 44 | end | 48 | end |
app/views/cms/_general_fields.html.erb
| 1 | -<%= labelled_form_field(_('License'), select(:article, :license_id, [[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]})) %> | 1 | +<%= 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))) %> |
app/views/licenses/index.html.erb
| 1 | <h1><%= _('Manage licenses') %></h1> | 1 | <h1><%= _('Manage licenses') %></h1> |
| 2 | -<table style='width: 100%; overflow: hidden;'> | 2 | +<table style='overflow: hidden;'> |
| 3 | <tr> | 3 | <tr> |
| 4 | <th style='width: 25%'><%= _('Name') %></th> | 4 | <th style='width: 25%'><%= _('Name') %></th> |
| 5 | <th style='width: 60%'><%= _('Url reference') %></th> | 5 | <th style='width: 60%'><%= _('Url reference') %></th> |
| @@ -7,14 +7,16 @@ | @@ -7,14 +7,16 @@ | ||
| 7 | </tr> | 7 | </tr> |
| 8 | <% @licenses.each do |license| %> | 8 | <% @licenses.each do |license| %> |
| 9 | <tr> | 9 | <tr> |
| 10 | - <td title="<%= license.name%>"><%= truncate(license.name, 19) %></td> | ||
| 11 | - <td title="<%= license.url %>"><%= license.url.present? ? link_to(truncate(license.url, 60), license.url, :target => '_blank') : '' %></td> | 10 | + <td title="<%= license.name%>"><%= truncate(license.name, :length => 19) %></td> |
| 11 | + <td title="<%= license.url %>"><%= license.url.present? ? link_to(truncate(license.url, :length => 60), license.url, :target => '_blank') : '' %></td> | ||
| 12 | <td style='white-space: nowrap;'> | 12 | <td style='white-space: nowrap;'> |
| 13 | <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> | 13 | <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> |
| 14 | - <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %></td> | 14 | + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :method => 'post', :confirm => _('Are you sure you want to remove this license?') %></td> |
| 15 | </tr> | 15 | </tr> |
| 16 | <% end %> | 16 | <% end %> |
| 17 | - <tr> | ||
| 18 | - <td colspan='3' style='text-align: center'><strong><%= link_to(_('NEW LICENSE'), :action => 'create')%></strong></td> | ||
| 19 | - </tr> | ||
| 20 | </table> | 17 | </table> |
| 18 | + | ||
| 19 | +<% button_bar do %> | ||
| 20 | + <%= button(:add, _('Add a new license'), :action => 'create')%> | ||
| 21 | + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %> | ||
| 22 | +<% end %> |
db/schema.rb
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | # | 9 | # |
| 10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
| 11 | 11 | ||
| 12 | -ActiveRecord::Schema.define(:version => 20120718145131) do | 12 | +ActiveRecord::Schema.define(:version => 20120718162001) do |
| 13 | 13 | ||
| 14 | create_table "abuse_reports", :force => true do |t| | 14 | create_table "abuse_reports", :force => true do |t| |
| 15 | t.integer "reporter_id" | 15 | t.integer "reporter_id" |
| @@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | @@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | ||
| 85 | t.integer "translation_of_id" | 85 | t.integer "translation_of_id" |
| 86 | t.string "language" | 86 | t.string "language" |
| 87 | t.string "source_name" | 87 | t.string "source_name" |
| 88 | + t.integer "license_id" | ||
| 88 | end | 89 | end |
| 89 | 90 | ||
| 90 | create_table "articles", :force => true do |t| | 91 | create_table "articles", :force => true do |t| |
| @@ -125,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | @@ -125,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | ||
| 125 | t.integer "translation_of_id" | 126 | t.integer "translation_of_id" |
| 126 | t.string "language" | 127 | t.string "language" |
| 127 | t.string "source_name" | 128 | t.string "source_name" |
| 129 | + t.integer "license_id" | ||
| 128 | end | 130 | end |
| 129 | 131 | ||
| 130 | add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" | 132 | add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" |
| @@ -314,6 +316,13 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | @@ -314,6 +316,13 @@ ActiveRecord::Schema.define(:version => 20120718145131) do | ||
| 314 | add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" | 316 | add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" |
| 315 | add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" | 317 | add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" |
| 316 | 318 | ||
| 319 | + create_table "licenses", :force => true do |t| | ||
| 320 | + t.string "name", :null => false | ||
| 321 | + t.string "slug", :null => false | ||
| 322 | + t.string "url" | ||
| 323 | + t.integer "environment_id", :null => false | ||
| 324 | + end | ||
| 325 | + | ||
| 317 | create_table "mailing_sents", :force => true do |t| | 326 | create_table "mailing_sents", :force => true do |t| |
| 318 | t.integer "mailing_id" | 327 | t.integer "mailing_id" |
| 319 | t.integer "person_id" | 328 | t.integer "person_id" |
public/stylesheets/application.css
| @@ -2960,6 +2960,11 @@ table.cms-articles .icon:hover { | @@ -2960,6 +2960,11 @@ table.cms-articles .icon:hover { | ||
| 2960 | .controller-cms ul.categories li.cat_checked { | 2960 | .controller-cms ul.categories li.cat_checked { |
| 2961 | background: #B8CFE7; | 2961 | background: #B8CFE7; |
| 2962 | } | 2962 | } |
| 2963 | + | ||
| 2964 | +.controller-cms select#article_license_id { | ||
| 2965 | + max-width: 100%; | ||
| 2966 | +} | ||
| 2967 | + | ||
| 2963 | /************* external blog options *****************/ | 2968 | /************* external blog options *****************/ |
| 2964 | 2969 | ||
| 2965 | .controller-cms #fetch-external-feed { | 2970 | .controller-cms #fetch-external-feed { |
test/functional/licenses_controller_test.rb
| @@ -26,6 +26,18 @@ class LicensesControllerTest < ActionController::TestCase | @@ -26,6 +26,18 @@ class LicensesControllerTest < ActionController::TestCase | ||
| 26 | assert_includes assigns(:licenses), l2 | 26 | assert_includes assigns(:licenses), l2 |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | + should 'not list licenses from other environments' do | ||
| 30 | + other_env = fast_create(Environment) | ||
| 31 | + l1 = License.create!(:name => 'GPLv3', :environment => environment) | ||
| 32 | + l2 = License.create!(:name => 'AGPL', :environment => other_env) | ||
| 33 | + @controller.stubs(:environment).returns(environment) | ||
| 34 | + | ||
| 35 | + get :index | ||
| 36 | + | ||
| 37 | + assert_includes assigns(:licenses), l1 | ||
| 38 | + assert_not_includes assigns(:licenses), l2 | ||
| 39 | + end | ||
| 40 | + | ||
| 29 | should 'create a new license' do | 41 | should 'create a new license' do |
| 30 | assert_difference License, :count, 1 do | 42 | assert_difference License, :count, 1 do |
| 31 | post :create, :license => {:name => 'GPLv3'} | 43 | post :create, :license => {:name => 'GPLv3'} |
| @@ -43,4 +55,14 @@ class LicensesControllerTest < ActionController::TestCase | @@ -43,4 +55,14 @@ class LicensesControllerTest < ActionController::TestCase | ||
| 43 | post :remove, :license_id => license.id | 55 | post :remove, :license_id => license.id |
| 44 | assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)} | 56 | assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)} |
| 45 | end | 57 | end |
| 58 | + | ||
| 59 | + should 'remove a license only with post method' do | ||
| 60 | + license = License.create!(:name => 'GPLv3', :environment => environment) | ||
| 61 | + get :remove, :license_id => license.id | ||
| 62 | + assert_nothing_raised ActiveRecord::RecordNotFound do | ||
| 63 | + License.find(license.id) | ||
| 64 | + end | ||
| 65 | + assert_redirected_to :action => 'index' | ||
| 66 | + end | ||
| 67 | + | ||
| 46 | end | 68 | end |