noosfero | 3 new commits pushed to repository

Leandro Nunes gitlab at gitlab.com
Wed Jan 28 09:21:12 BRST 2015


Leandro Nunes pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/91109fe37086fb29a1508b00cdb85b2c33f7cf55">91109fe3</a> by Leandro Nunes dos Santos
hide license selection in article edition when there is no license available

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/7018c3d23b4667fac37cc34ad706eac182c57f37">7018c3d2</a> by Leandro Nunes dos Santos
Merge branches 'master' and 'hide_license' into hide_license

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/dd8aaa4737740b49f8450ca2f3e9255a9b351ad7">dd8aaa47</a> by Leandro Nunes
Merge branch 'hide_license' into 'master'

Hide license

Hide license selection when there is no license available on environment

See merge request !438

- - - - -


Changes:

=====================================
app/models/environment.rb
=====================================
--- 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

=====================================
app/views/cms/_general_fields.html.erb
=====================================
--- 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 %>

=====================================
test/functional/cms_controller_test.rb
=====================================
--- 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)

=====================================
test/unit/environment_test.rb
=====================================
--- 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150128/2074784c/attachment.html>


More information about the Noosfero-dev mailing list