diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb
index 4bb9a81..20de316 100644
--- a/app/controllers/public/profile_controller.rb
+++ b/app/controllers/public/profile_controller.rb
@@ -113,6 +113,11 @@ class ProfileController < PublicController
render :text => '', :layout => false
end
+ def unblock
+ profile.unblock
+ redirect_to :controller => 'profile', :action => 'index'
+ end
+
protected
def check_access_to_profile
@@ -157,4 +162,5 @@ class ProfileController < PublicController
def members_per_page
20
end
+
end
diff --git a/app/models/disabled_enterprise_message_block.rb b/app/models/disabled_enterprise_message_block.rb
index 4dcd7c8..ad0dfde 100644
--- a/app/models/disabled_enterprise_message_block.rb
+++ b/app/models/disabled_enterprise_message_block.rb
@@ -14,7 +14,9 @@ class DisabledEnterpriseMessageBlock < Block
def content
message = self.owner.environment.message_for_disabled_enterprise || ''
- content_tag('div', message, :class => 'enterprise-disabled')
+ lambda do
+ render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message}
+ end
end
def editable?
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index f1edd9e..cd27b20 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -82,6 +82,11 @@ class Enterprise < Organization
save
end
+ def unblock
+ data[:blocked] = false
+ save
+ end
+
def enable(owner)
return if enabled
affiliate(owner, Profile::Roles.all_roles(environment.id))
diff --git a/app/views/blocks/disabled_enterprise_message.rhtml b/app/views/blocks/disabled_enterprise_message.rhtml
new file mode 100644
index 0000000..6d92659
--- /dev/null
+++ b/app/views/blocks/disabled_enterprise_message.rhtml
@@ -0,0 +1,8 @@
+
+ <%= message %>
+ <% if profile.blocked? && user.is_admin?(profile.environment) %>
+
+ <%= button :lock, _('Unblock'), {:controller => 'profile', :action => 'unblock'} %>
+
+ <% end %>
+
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 9277931..9ef648f 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -150,3 +150,14 @@ end
Given /^"(.+)" is friend of "(.+)"$/ do |person, friend|
Person[person].add_friend(Person[friend])
end
+
+Given /^(.+) is blocked$/ do |enterprise_name|
+ enterprise = Enterprise.find_by_name(enterprise_name)
+ enterprise.block
+end
+
+Given /^(.+) is disabled$/ do |enterprise_name|
+ enterprise = Enterprise.find_by_name(enterprise_name)
+ enterprise.enabled = false
+ enterprise.save
+end
diff --git a/features/unblock_button.feature b/features/unblock_button.feature
new file mode 100644
index 0000000..33c6f08
--- /dev/null
+++ b/features/unblock_button.feature
@@ -0,0 +1,34 @@
+Feature: unblock button
+ As an environment administrator
+ I want to unblock an enterprise
+ In order to try to activate it again
+
+ Background:
+ Given the following enterprise
+ | identifier | name |
+ | sample-enterprise | Sample Enterprise |
+ And the following blocks
+ | owner | type |
+ | sample-enterprise | DisabledEnterpriseMessageBlock |
+ And Sample Enterprise is disabled
+
+ Scenario: the environment administrator unblocks a blocked enterprise
+ Given I am logged in as admin
+ And Sample Enterprise is blocked
+ And I am on Sample Enterprise's homepage
+ When I follow "Unblock"
+ Then I should not see "Unblock"
+
+ Scenario: a not administrator user can't see "Unblock" button
+ Given the following user
+ | login | name |
+ | joaosilva | Joao Silva |
+ And I am logged in as "joaosilva"
+ And Sample Enterprise is blocked
+ When I am on Sample Enterprise's homepage
+ Then I should not see "Unblock"
+
+ Scenario: a not blocked enterprise should not show "Unblock" button
+ Given I am logged in as admin
+ When I am on Sample Enterprise's homepage
+ Then I should not see "Unblock"
diff --git a/public/designs/icons/tango/style.css b/public/designs/icons/tango/style.css
index 9b38c34..89963e0 100644
--- a/public/designs/icons/tango/style.css
+++ b/public/designs/icons/tango/style.css
@@ -68,4 +68,5 @@
.icon-media-play { background-image: url(Tango/16x16/actions/media-playback-start.png) }
.icon-media-prev { background-image: url(Tango/16x16/actions/media-skip-backward.png) }
.icon-media-next { background-image: url(Tango/16x16/actions/media-skip-forward.png) }
+.icon-lock { background-image: url(Tango/16x16/actions/lock.png) }
diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css
index 1cfb3c6..c03cbe8 100644
--- a/public/stylesheets/common.css
+++ b/public/stylesheets/common.css
@@ -102,6 +102,10 @@ div#profile-disabled {
background: url("../images/icons-app/alert.png") no-repeat 5px #ffffa9;
}
+div#profile-disabled .unlock-button{
+ margin: 5px;
+}
+
.explanation {
font-style: italic;
font-size: 10px;
diff --git a/test/unit/disabled_enterprise_message_block_test.rb b/test/unit/disabled_enterprise_message_block_test.rb
index 14a2bc5..a19ebc6 100644
--- a/test/unit/disabled_enterprise_message_block_test.rb
+++ b/test/unit/disabled_enterprise_message_block_test.rb
@@ -14,7 +14,8 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase
block.expects(:owner).returns(p)
p.expects(:environment).returns(e)
- assert_tag_in_string block.content, :tag => 'div', :content => /This message is for disabled enterprises/
+ expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => 'This message is for disabled enterprises'})
+ instance_eval(&block.content)
end
should 'display nothing if environment has no message' do
@@ -24,7 +25,8 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase
block.expects(:owner).returns(p)
p.expects(:environment).returns(e)
- assert_no_tag_in_string block.content, :tag => 'div', :content => /This message is for disabled enterprises/
+ expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => ''})
+ instance_eval(&block.content)
end
should 'not be editable' do
diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb
index 9c8eb53..6decc46 100644
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -145,6 +145,14 @@ class EnterpriseTest < Test::Unit::TestCase
assert Enterprise.find(ent.id).blocked?
end
+ should 'unblock' do
+ ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
+ ent.data[:blocked] = true
+ ent.save
+ ent.unblock
+ assert !Enterprise.find(ent.id).blocked?
+ end
+
should 'enable and make user admin' do
ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
p = create_user('test_user').person
--
libgit2 0.21.2