diff --git a/app/models/environment.rb b/app/models/environment.rb index 1910fd7..ee00db4 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -937,6 +937,10 @@ class Environment < ActiveRecord::Base locales_list end + def has_license? + self.licenses.any? + end + private def default_language_available diff --git a/app/views/cms/_general_fields.html.erb b/app/views/cms/_general_fields.html.erb index 95212d4..527c030 100644 --- a/app/views/cms/_general_fields.html.erb +++ b/app/views/cms/_general_fields.html.erb @@ -1,2 +1,4 @@ <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_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))) %> +<% if profile.environment.has_license? %> + <%= 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))) %> +<% end %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 5c09b4b..acc605c 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1678,6 +1678,15 @@ class CmsControllerTest < ActionController::TestCase assert_equal license, article.license end + should 'not display license field if there is no license availabe in environment' do + article = fast_create(Article, :profile_id => profile.id) + License.delete_all + login_as(profile.identifier) + + get :new, :profile => profile.identifier, :type => 'TinyMceArticle' + assert_no_tag :tag => 'select', :attributes => {:id => 'article_license_id'} + end + should 'list folders options to move content' do article = fast_create(Article, :profile_id => profile.id) f1 = fast_create(Folder, :profile_id => profile.id) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 731e0d9..d8df1c6 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -1627,4 +1627,26 @@ class EnvironmentTest < ActiveSupport::TestCase assert_equal 'Welcome to the environment', environment.signup_welcome_screen_body end + + should 'has_license be true if there is one license in enviroment' do + e = fast_create(Environment) + fast_create(License, :name => 'Some', :environment_id => e.id) + + assert e.has_license? + end + + should 'has_license be true if there is many licenses in enviroment' do + e = fast_create(Environment) + fast_create(License, :name => 'Some', :environment_id => e.id) + fast_create(License, :name => 'Another', :environment_id => e.id) + + assert e.has_license? + end + + should 'has_license be false if there is no license in enviroment' do + e = fast_create(Environment) + + assert !e.has_license? + end + end -- libgit2 0.21.2