diff --git a/app/controllers/admin/licenses_controller.rb b/app/controllers/admin/licenses_controller.rb
new file mode 100644
index 0000000..49212c5
--- /dev/null
+++ b/app/controllers/admin/licenses_controller.rb
@@ -0,0 +1,46 @@
+class LicensesController < AdminController
+ protect 'manage_environment_licenses', :environment
+
+ def index
+ @licenses = environment.licenses
+ end
+
+ def create
+ @license = License.new(params[:license])
+ if request.post?
+ begin
+ @license.environment = environment
+ @license.save!
+ session[:notice] = _('License created')
+ redirect_to :action => 'index'
+ rescue
+ session[:notice] = _('License could not be created')
+ end
+ end
+ end
+
+ def edit
+ @license = License.find(params[:license_id])
+ if request.post?
+ begin
+ @license.update_attributes!(params[:license])
+ session[:notice] = _('License updated')
+ redirect_to :action => 'index'
+ rescue
+ session[:notice] = _('License could not be updated')
+ end
+ end
+ end
+
+ def remove
+ @license = License.find(params[:license_id])
+ begin
+ @license.destroy
+ session[:notice] = _('Licese removed')
+ rescue
+ session[:notice] = _('Licese could not be removed')
+ end
+ redirect_to :action => 'index'
+ end
+
+end
diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml
index f5641dc..2753627 100644
--- a/app/views/admin_panel/index.rhtml
+++ b/app/views/admin_panel/index.rhtml
@@ -15,6 +15,7 @@
<%= link_to _('Edit Templates'), :action => 'edit_templates' %> |
<%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %> |
<%= link_to _('Set Portal'), :action => 'set_portal_community' %> |
+ <%= link_to _('Manage Licenses'), :controller =>'licenses' %> |
<% @plugins.dispatch(:admin_panel_links).each do |link| %>
<%= link_to link[:title], link[:url] %> |
<% end %>
diff --git a/app/views/licenses/_form.html.erb b/app/views/licenses/_form.html.erb
new file mode 100644
index 0000000..ac4f53f
--- /dev/null
+++ b/app/views/licenses/_form.html.erb
@@ -0,0 +1,12 @@
+<%= error_messages_for :license %>
+
+<% form_for :license, @license do |f| %>
+ <%= hidden_field_tag(:license_id, params[:license_id]) %>
+ <%= required labelled_form_field(_('Name'), f.text_field(:name)) %>
+ <%= labelled_form_field(_('License url'), f.text_field(:url)) %>
+
+ <% button_bar do %>
+ <%= submit_button('save', _('Save'))%>
+ <%= button('cancel', _('Cancel'), {:action => 'index'})%>
+ <% end %>
+<% end %>
diff --git a/app/views/licenses/create.html.erb b/app/views/licenses/create.html.erb
new file mode 100644
index 0000000..a13ed33
--- /dev/null
+++ b/app/views/licenses/create.html.erb
@@ -0,0 +1,2 @@
+<%= _('New license') %>
+<%= render :partial => 'form' %>
diff --git a/app/views/licenses/edit.html.erb b/app/views/licenses/edit.html.erb
new file mode 100644
index 0000000..9cd0e69
--- /dev/null
+++ b/app/views/licenses/edit.html.erb
@@ -0,0 +1,2 @@
+<%= _('Edit license') %>
+<%= render :partial => 'form' %>
diff --git a/app/views/licenses/index.html.erb b/app/views/licenses/index.html.erb
new file mode 100644
index 0000000..e6d1878
--- /dev/null
+++ b/app/views/licenses/index.html.erb
@@ -0,0 +1,20 @@
+<%= _('Manage licenses') %>
+
+
+ <%= _('Name') %> |
+ <%= _('Url reference') %> |
+ <%= _('Actions') %> |
+
+ <% @licenses.each do |license| %>
+
+ <%= truncate(license.name, 19) %> |
+ <%= link_to(truncate(license.url, 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?') %> |
+
+ <% end %>
+
+ <%= link_to(_('NEW LICENSE'), :action => 'create')%> |
+
+
diff --git a/test/functional/licenses_controller_test.rb b/test/functional/licenses_controller_test.rb
new file mode 100644
index 0000000..9e51048
--- /dev/null
+++ b/test/functional/licenses_controller_test.rb
@@ -0,0 +1,46 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'licenses_controller'
+
+# Re-raise errors caught by the controller.
+class LIcensesController; def rescue_action(e) raise e end; end
+
+class LicensesControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = LicensesController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @environment = Environment.default
+ login_as(create_admin_user(@environment))
+ end
+
+ attr_accessor :environment
+
+ should 'list environment licenses' do
+ l1 = License.create!(:name => 'GPLv3', :environment => environment)
+ l2 = License.create!(:name => 'AGPL', :environment => environment)
+
+ get :index
+
+ assert_includes assigns(:licenses), l1
+ assert_includes assigns(:licenses), l2
+ end
+
+ should 'create a new license' do
+ assert_difference License, :count, 1 do
+ post :create, :license => {:name => 'GPLv3'}
+ end
+ end
+
+ should 'edit a license' do
+ license = License.create!(:name => 'GPLv2', :environment => environment)
+ post :edit, :license_id => license.id, :license => {:name => 'GPLv3'}
+ assert_equal 'GPLv3', License.last.name
+ end
+
+ should 'remove a license' do
+ license = License.create!(:name => 'GPLv3', :environment => environment)
+ post :remove, :license_id => license.id
+ assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)}
+ end
+end
--
libgit2 0.21.2