[Git][noosfero/noosfero][master] 2 commits: Fix bug with hiding main block forever

Victor Costa gitlab at mg.gitlab.com
Fri Jun 2 11:43:22 BRT 2017


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
e3702c10 by Leonardo Soares at 2017-06-02T11:19:34-03:00
Fix bug with hiding main block forever

- - - - -
0094e86d by Victor Costa at 2017-06-02T14:42:50+00:00
Merge branch 'gov/fix-hide-main-block' into 'master'

fixing bug with hiding main block forever

See merge request !1226
- - - - -


4 changed files:

- app/models/main_block.rb
- config/locales/en-US.yml
- config/locales/pt-BR.yml
- test/unit/main_block_test.rb


Changes:

=====================================
app/models/main_block.rb
=====================================
--- a/app/models/main_block.rb
+++ b/app/models/main_block.rb
@@ -1,5 +1,7 @@
 class MainBlock < Block
 
+  validate :cannnot_be_unacessible
+
   def self.description
     _('Main content')
   end
@@ -26,4 +28,11 @@ class MainBlock < Block
     }
   end
 
+  private
+  def cannnot_be_unacessible
+    if display == 'never'
+      self.errors.add(:display, :cannot_hide_block)
+    end
+  end
+
 end


=====================================
config/locales/en-US.yml
=====================================
--- a/config/locales/en-US.yml
+++ b/config/locales/en-US.yml
@@ -208,6 +208,7 @@
       taken: "has already been taken"
       record_invalid: "Validation failed: %{errors}"
       not_available: "is not available."
+      cannot_hide_block: "You cannot hide this block"
     template: &errors_template
       header:
         one: "1 error prohibited this %{model} from being saved"


=====================================
config/locales/pt-BR.yml
=====================================
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -218,6 +218,7 @@
       taken: "já está em uso"
       record_invalid: "A validação falhou: %{errors}"
       not_available: "não está disponível."
+      cannot_hide_block: "Você não pode esconder este bloco"
     template: &errors_template
       header:
         one: "Não foi possível gravar %{model}: 1 erro"


=====================================
test/unit/main_block_test.rb
=====================================
--- a/test/unit/main_block_test.rb
+++ b/test/unit/main_block_test.rb
@@ -33,4 +33,10 @@ class MainBlockTest < ActiveSupport::TestCase
     assert_equal MainBlock.new.display_user_options, {"all"=>_('All users')}
   end
 
+  should 'not save main block with never visibility' do
+    block = MainBlock.new
+    block.display = 'never'
+    block.save
+    assert_equal ["You cannot hide this block"], block.errors[:display]
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/91d5bd596f5f5395f41a0fca993c66fd1a25238c...0094e86d3f3eddaea9bcae9f5b141bc173260ed7

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/91d5bd596f5f5395f41a0fca993c66fd1a25238c...0094e86d3f3eddaea9bcae9f5b141bc173260ed7
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170602/93375909/attachment-0001.html>


More information about the Noosfero-dev mailing list