Commit 68a4fe77f3bb6c7f35ada5ef0cd527dbf93ed177
1 parent
a7e994f9
Exists in
master
and in
29 other branches
[licenses] Adding controllers and views for licenses management
(ActionItem2379)
Showing
7 changed files
with
129 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,46 @@ |
1 | +class LicensesController < AdminController | |
2 | + protect 'manage_environment_licenses', :environment | |
3 | + | |
4 | + def index | |
5 | + @licenses = environment.licenses | |
6 | + end | |
7 | + | |
8 | + def create | |
9 | + @license = License.new(params[:license]) | |
10 | + if request.post? | |
11 | + begin | |
12 | + @license.environment = environment | |
13 | + @license.save! | |
14 | + session[:notice] = _('License created') | |
15 | + redirect_to :action => 'index' | |
16 | + rescue | |
17 | + session[:notice] = _('License could not be created') | |
18 | + end | |
19 | + end | |
20 | + end | |
21 | + | |
22 | + def edit | |
23 | + @license = License.find(params[:license_id]) | |
24 | + if request.post? | |
25 | + begin | |
26 | + @license.update_attributes!(params[:license]) | |
27 | + session[:notice] = _('License updated') | |
28 | + redirect_to :action => 'index' | |
29 | + rescue | |
30 | + session[:notice] = _('License could not be updated') | |
31 | + end | |
32 | + end | |
33 | + end | |
34 | + | |
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') | |
42 | + end | |
43 | + redirect_to :action => 'index' | |
44 | + end | |
45 | + | |
46 | +end | ... | ... |
app/views/admin_panel/index.rhtml
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | <tr><td><%= link_to _('Edit Templates'), :action => 'edit_templates' %></td></tr> |
16 | 16 | <tr><td><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
17 | 17 | <tr><td><%= link_to _('Set Portal'), :action => 'set_portal_community' %></td></tr> |
18 | + <tr><td><%= link_to _('Manage Licenses'), :controller =>'licenses' %></td></tr> | |
18 | 19 | <% @plugins.dispatch(:admin_panel_links).each do |link| %> |
19 | 20 | <tr><td><%= link_to link[:title], link[:url] %></td></tr> |
20 | 21 | <% end %> | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<%= error_messages_for :license %> | |
2 | + | |
3 | +<% form_for :license, @license do |f| %> | |
4 | + <%= hidden_field_tag(:license_id, params[:license_id]) %> | |
5 | + <%= required labelled_form_field(_('Name'), f.text_field(:name)) %> | |
6 | + <%= labelled_form_field(_('License url'), f.text_field(:url)) %> | |
7 | + | |
8 | + <% button_bar do %> | |
9 | + <%= submit_button('save', _('Save'))%> | |
10 | + <%= button('cancel', _('Cancel'), {:action => 'index'})%> | |
11 | + <% end %> | |
12 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +<h1><%= _('Manage licenses') %></h1> | |
2 | +<table style='width: 100%; overflow: hidden;'> | |
3 | + <tr> | |
4 | + <th style='width: 25%'><%= _('Name') %></th> | |
5 | + <th style='width: 60%'><%= _('Url reference') %></th> | |
6 | + <th style='width: 15%'><%= _('Actions') %></th> | |
7 | + </tr> | |
8 | + <% @licenses.each do |license| %> | |
9 | + <tr> | |
10 | + <td title="<%= license.name%>"><%= truncate(license.name, 19) %></td> | |
11 | + <td title="<%= license.url %>"><%= link_to(truncate(license.url, 60), license.url, :target => '_blank') %></td> | |
12 | + <td style='white-space: nowrap;'> | |
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> | |
15 | + </tr> | |
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> | ... | ... |
... | ... | @@ -0,0 +1,46 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'licenses_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class LIcensesController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class LicensesControllerTest < ActionController::TestCase | |
8 | + | |
9 | + def setup | |
10 | + @controller = LicensesController.new | |
11 | + @request = ActionController::TestRequest.new | |
12 | + @response = ActionController::TestResponse.new | |
13 | + @environment = Environment.default | |
14 | + login_as(create_admin_user(@environment)) | |
15 | + end | |
16 | + | |
17 | + attr_accessor :environment | |
18 | + | |
19 | + should 'list environment licenses' do | |
20 | + l1 = License.create!(:name => 'GPLv3', :environment => environment) | |
21 | + l2 = License.create!(:name => 'AGPL', :environment => environment) | |
22 | + | |
23 | + get :index | |
24 | + | |
25 | + assert_includes assigns(:licenses), l1 | |
26 | + assert_includes assigns(:licenses), l2 | |
27 | + end | |
28 | + | |
29 | + should 'create a new license' do | |
30 | + assert_difference License, :count, 1 do | |
31 | + post :create, :license => {:name => 'GPLv3'} | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + should 'edit a license' do | |
36 | + license = License.create!(:name => 'GPLv2', :environment => environment) | |
37 | + post :edit, :license_id => license.id, :license => {:name => 'GPLv3'} | |
38 | + assert_equal 'GPLv3', License.last.name | |
39 | + end | |
40 | + | |
41 | + should 'remove a license' do | |
42 | + license = License.create!(:name => 'GPLv3', :environment => environment) | |
43 | + post :remove, :license_id => license.id | |
44 | + assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)} | |
45 | + end | |
46 | +end | ... | ... |